Can create multiple libraries

This commit is contained in:
bjschuma 2010-01-01 21:00:12 -05:00
parent 54dd1463ff
commit cbdf7d9dba
3 changed files with 93 additions and 23 deletions

67
src/core/create.py Normal file
View File

@ -0,0 +1,67 @@
# This is a simple test plugin, to make sure everything is working
__author__="bjschuma"
__date__ ="$Jan 1, 2010 6:33:06 PM$"
global name, app, type, path, opt
name = "create"
app = "ocarina"
type = "core"
path = ""
opt = []
from bt.message import write
from bt.file import *
from tools import database
from manager import manager
import settings
# Called every time the plugin is enabled
def open():
pass
# Called every time the plugin is stopped
def close():
pass
def library(args):
name = "Default"
root = ""
if len(args) >= 1:
name = args[0]
if len(args) >= 2:
space = ' '
root = expandPath( space.join(args[1:]) )
#next = settings.get("nextlib")
database.open()
next = database.count('library')
database.insert('library',(next,name,root) )
database.close()
if not root == "":
manager.run("scan",[root])
# Called when the plugin needs to perform some action
def run(args=None):
l = len(args)
if args[0] == "library":
library(args[1:])
#name = "Default"
#root = ""
#if l >= 2:
# name = args[1]
#if l >= 3:
# space = ' '
# root = expandPath( space.join(args[2:]) )
#database.open()
#database.insert('library',(name,root) )
#database.close()
#if not root=="":
# manager.run("scan",[root])

View File

@ -80,6 +80,7 @@ def run(file=None):
if artist == "":
artist = "Unknown Artist"
# If artist does not exist yet, insert into database
if (artist in artists.keys())==False:
arid = database.count("artist")
database.insert("artist", (arid, artist) )
@ -92,4 +93,4 @@ def run(file=None):
album = "Unknown Album"
alid = database.count("album")
database.insert("album", (alid, arid, album) )
database.insert("album", (alid, album) )

View File

@ -44,24 +44,31 @@ def create():
CREATE TABLE artist
(
arid INTEGER PRIMARY KEY,
id INTEGER PRIMARY KEY,
name TEXT UNIQUE
);
CREATE TABLE album
(
alid INTEGER PRIMARY KEY,
artid INTEGER,
id INTEGER PRIMARY KEY,
name TEXT UNIQUE
);
CREATE TABLE library
(
libid INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE,
path TEXT UNIQUE
);
""")
global vals
vals["files"] = "?"
vals["artist"]= "?,?"
vals["album"] = "?,?,?"
vals["album"] = "?,?"
vals["library"] = "?,?,?"
@ -88,35 +95,30 @@ def init():
close()
def insert(table, values):
def execute(statement, values=None):
global conn
if conn == None:
open()
if values == None:
return conn.execute(statement)
else:
return conn.execute(statement,values)
def insert(table, values):
global vals
#c = conn.cursor()
#t = (file,)
conn.execute('INSERT OR IGNORE INTO ' + table + ' VALUES(' + vals[table] + ')',values)
#c.close()
execute('INSERT OR IGNORE INTO ' + table + ' VALUES(' + vals[table] + ')',values)
def count(table):
global conn
if conn == None:
open()
result = conn.execute('select count(*) from '+ table)
return result.fetchone()[0]
return execute('select count(*) from ' + table).fetchone()[0]
def select(select,table,where=None):
global conn
if conn == None:
open()
statement = 'select '+select+' from '+table
if not (where==None):
statement += ' where '+where
print statement
#return statement
result = conn.execute(statement)
#print result.fetchone()
#return result.fetchone()
return (0,)
result = execute(statement)
return result