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 == "": if artist == "":
artist = "Unknown Artist" artist = "Unknown Artist"
# If artist does not exist yet, insert into database
if (artist in artists.keys())==False: if (artist in artists.keys())==False:
arid = database.count("artist") arid = database.count("artist")
database.insert("artist", (arid, artist) ) database.insert("artist", (arid, artist) )
@ -92,4 +93,4 @@ def run(file=None):
album = "Unknown Album" album = "Unknown Album"
alid = database.count("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 CREATE TABLE artist
( (
arid INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
name TEXT UNIQUE name TEXT UNIQUE
); );
CREATE TABLE album CREATE TABLE album
( (
alid INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
artid INTEGER,
name TEXT UNIQUE name TEXT UNIQUE
); );
CREATE TABLE library
(
libid INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE,
path TEXT UNIQUE
);
""") """)
global vals global vals
vals["files"] = "?" vals["files"] = "?"
vals["artist"]= "?,?" vals["artist"]= "?,?"
vals["album"] = "?,?,?" vals["album"] = "?,?"
vals["library"] = "?,?,?"
@ -88,35 +95,30 @@ def init():
close() close()
def insert(table, values): def execute(statement, values=None):
global conn global conn
if conn == None: if conn == None:
open() open()
if values == None:
return conn.execute(statement)
else:
return conn.execute(statement,values)
def insert(table, values):
global vals global vals
#c = conn.cursor() execute('INSERT OR IGNORE INTO ' + table + ' VALUES(' + vals[table] + ')',values)
#t = (file,)
conn.execute('INSERT OR IGNORE INTO ' + table + ' VALUES(' + vals[table] + ')',values)
#c.close()
def count(table): def count(table):
global conn return execute('select count(*) from ' + table).fetchone()[0]
if conn == None:
open()
result = conn.execute('select count(*) from '+ table)
return result.fetchone()[0]
def select(select,table,where=None): def select(select,table,where=None):
global conn
if conn == None:
open()
statement = 'select '+select+' from '+table statement = 'select '+select+' from '+table
if not (where==None): if not (where==None):
statement += ' where '+where statement += ' where '+where
print statement print statement
#return statement result = execute(statement)
result = conn.execute(statement) return result
#print result.fetchone()
#return result.fetchone()
return (0,)