From e5edd7a9dd0b3d750eda352ba337a8f65a6f0d64 Mon Sep 17 00:00:00 2001 From: bjschuma Date: Fri, 29 Jan 2010 00:40:48 -0500 Subject: [PATCH] Created new library plugin, can create a library in sqlite --- src/core/ct/__init__.py | 5 ++++ src/core/ct/db.py | 53 +++++++++++++++++++++++++++++++++++++++++ src/core/library.py | 38 +++++++++++++++++++++++++++++ src/core/ocarina.py | 15 ++++-------- 4 files changed, 100 insertions(+), 11 deletions(-) create mode 100644 src/core/ct/__init__.py create mode 100644 src/core/ct/db.py create mode 100644 src/core/library.py diff --git a/src/core/ct/__init__.py b/src/core/ct/__init__.py new file mode 100644 index 00000000..86024981 --- /dev/null +++ b/src/core/ct/__init__.py @@ -0,0 +1,5 @@ +__author__="bjschuma" +__date__ ="$Jan 27, 2010 6:20:54 PM$" + + +__all__ = ["db"] \ No newline at end of file diff --git a/src/core/ct/db.py b/src/core/ct/db.py new file mode 100644 index 00000000..0aef95f9 --- /dev/null +++ b/src/core/ct/db.py @@ -0,0 +1,53 @@ +#! /usr/bin/python + +# To change this template, choose Tools | Templates +# and open the template in the editor. + +__author__="bjschuma" +__date__ ="$Jan 27, 2010 6:21:27 PM$" + + +from bt.message import write +from bt import sql + +def init(): + if sql.dbexists() == True: + return + + table = sql.CTable("library") + table.addcol("id","INTEGER","PRIMARY KEY AUTOINCREMENT") + table.addcol("name","TEXT","UNIQUE") + table.addcol("path","TEXT","UNIQUE") + table.execute() + + table = sql.CTable("artist") + table.addcol("id","INTEGER","PRIMARY KEY AUTOINCREMENT") + table.addcol("name","TEXT","UNIQUE") + table.execute() + + table = sql.CTable("album") + table.addcol("id","INTEGER","PRIMARY KEY AUTOINCREMENT") + table.addcol("name","TEXT","UNIQUE") + table.execute() + + table = sql.CTable("track") + table.addcol("id","INTEGER","PRIMARY KEY AUTOINCREMENT") + table.addcol("artist","INTEGER") + table.addcol("album","INTEGER") + table.addcol("count","INTEGER") + table.addcol("length","INTEGER") + table.addcol("name","TEXT") + table.addcol("path","TEXT","UNIQUE") + table.execute() + + table = sql.CTable("libtrack") + table.addcol("library","INTEGER") + table.addcol("track","INTEGER") + table.execute() + + + +def newlib(name,path): + ins = sql.Insert('library',[None,name,path]) + ins.execute() + ins.commit() \ No newline at end of file diff --git a/src/core/library.py b/src/core/library.py new file mode 100644 index 00000000..5a88cd95 --- /dev/null +++ b/src/core/library.py @@ -0,0 +1,38 @@ +# 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 + + +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]" + + + 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) + + + def run(self, args=None): + if (args==None) or (len(args)==0): + write(self.usage) + + if args[0] == "create": + self.create(args[1:]) + diff --git a/src/core/ocarina.py b/src/core/ocarina.py index 405ec73a..2891a868 100644 --- a/src/core/ocarina.py +++ b/src/core/ocarina.py @@ -8,21 +8,14 @@ from bt import plugin import settings settings.set("appname","ocarina2") +from ct import db + class Plugin(plugin.Plugin): def __init__(self): plugin.Plugin.__init__(self) - self.help = "" + self.help = "A simple music player written in python" def open(self): - pass - - - def close(self): - pass - - - def run(self, args=None): - pass - + db.init()