ocarina/src/core/library.py

69 lines
1.4 KiB
Python

# Basic plugin class
__author__="bjschuma"
__date__ ="$Jan 27, 2010 6:16:01 PM$"
from bt import plugin
from bt.file import expandPath
from bt.message import write
from ct import db
from ct import update
import settings
class Plugin(plugin.Plugin):
def __init__(self):
plugin.Plugin.__init__(self)
self.help = "Used to access various parts of the library"
self.usage = "library [create, list, prcnt, remove, switch, update]"
def open(self):
if settings.has("curlib") == False:
settings.set("curlib",-1)
def create(self,args):
usage = "Usage: library create name path"
if len(args) < 2:
write(usage)
return
name = args[0]
join = ' '
path = expandPath(join.join(args[1:]))
db.newlib(name,path)
if settings.get("curlib")==-1:
settings.set("curlib",db.libid(name))
def remove(self,args):
usage = "Usage: library remove name"
if len(args) < 1:
write(usage)
return
name = args[0]
db.rmlib(name)
def run(self, args=None):
if (args==None) or (len(args)==0):
write(self.usage)
return
if args[0] == "create":
self.create(args[1:])
elif args[0] == "list":
db.listlib()
elif args[0] == "remove":
self.remove(args[1:])
elif args[0] == "update":
update.go(args[1])
elif args[0] == "prcnt":
update.prcnt()
elif args[0] == "switch":
newLib = db.libid(args[1])
if not newLib == None:
settings.set("curlib",newLib)