58 lines
1.1 KiB
Python
58 lines
1.1 KiB
Python
# Basic plugin class
|
|
|
|
__author__="bjschuma"
|
|
__date__ ="$Jan 23, 2010 2:46:07 PM$"
|
|
|
|
|
|
from bt import plugin
|
|
from bt import alias
|
|
from bt.message import write
|
|
from bt.file import *
|
|
import settings
|
|
|
|
|
|
class Plugin(plugin.Plugin):
|
|
def __init__(self):
|
|
plugin.Plugin.__init__(self)
|
|
self.help = "Used to create aliases to shorten commands"
|
|
self.usage = "alias [list, new old]"
|
|
|
|
|
|
def getfile(self,flags='r'):
|
|
#path = join( settings.get("user"), "."+settings.get("appname") )
|
|
path = join(settings.get("appdir"), "aliases")
|
|
return fopen(path,flags)
|
|
|
|
|
|
def open(self):
|
|
file = self.getfile()
|
|
if file == None:
|
|
return
|
|
for line in file:
|
|
self.run(line.split())
|
|
|
|
|
|
def close(self):
|
|
file = self.getfile('w')
|
|
join = " "
|
|
for key in alias.aliases:
|
|
line = key + " " + join.join(alias.aliases[key] )
|
|
file.write(line + "\n")
|
|
file.close()
|
|
|
|
|
|
def run(self, args=None):
|
|
if args==None or len(args)<1:
|
|
write("Usage: "+self.usage)
|
|
return
|
|
|
|
if len(args)==1 and args[0]=="list":
|
|
for key in alias.aliases.keys():
|
|
write(key + " = " + str(alias.aliases[key]))
|
|
return
|
|
|
|
alias.register(args[0],args[1:])
|
|
|
|
|
|
|