Added sqlite as a database for the library

This commit is contained in:
bjschuma 2009-12-28 15:26:09 -05:00
parent 3077a09a2d
commit db402f9659
6 changed files with 90 additions and 30 deletions

View File

@ -1,4 +0,0 @@
__author__="bjschuma"
__date__ ="$Dec 27, 2009 9:40:48 PM$"
__all__=["scan"]

View File

@ -1,20 +0,0 @@
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Dec 27, 2009 9:44:30 PM$"
from bt.file import *
def scan(dir):
write(dir)
#files = ls(dir)
#for file in files:
# path = join(dir,file)
# if checkDir(path)==True:
# self.scan(path)
# else:
# write(path,True)
# self.files += [path]

View File

@ -16,17 +16,23 @@ opt = []
import settings
from bt.message import write
from bt.file import *
import bt.proc
from manager import manager
from tools import database
from tools import library
settings.set("ocarina", join(settings.get("user"),".ocarina2") )
mkdir(settings.get("ocarina"))
bt.proc.setname("Ocarina 2")
#from tools import library
# Called every time the plugin is enabled
def open():
write("Ocarina has been started",True)
bt.proc.setname("Ocarina 2")
database.init()
# Called every time the plugin is stopped
def close():

View File

@ -5,8 +5,8 @@ __date__ ="$Dec 27, 2009 8:07:18 PM$"
global name, app, type, path, opt
name = "test"
app = "scion"
name = "scan"
app = "ocarina"
type = "core"
path = ""
opt = []
@ -14,7 +14,8 @@ opt = []
from bt.message import write
from bt.file import *
from library import *
#from library import *
from tools import database
#from library.scan import scan
@ -37,6 +38,7 @@ def scan(dir):
scan(path)
else:
write(path,True)
database.insert(path)
#self.files += [path]
@ -46,4 +48,6 @@ def run(args=None):
return
space = ' '
path = expandPath( space.join(args) )
#database.open()
scan(path)
database.close()

View File

@ -0,0 +1,4 @@
__author__="bjschuma"
__date__ ="$Dec 28, 2009 12:21:59 AM$"
__all__ = ['database']

View File

@ -0,0 +1,70 @@
# This is a simple test plugin, to make sure everything is working
__author__="bjschuma"
__date__ ="$Dec 27, 2009 9:58:50 PM$"
global name, app, type, path, opt
name = "database"
app = "ocarina"
type = "core"
path = ""
opt = []
import settings
from bt.file import *
import sqlite3
#global conn, c
#conn = None
#c = None
global db
global conn
db = None
conn = None
# Collect all information for what to insert
# Build into a large statement, then insert
# This will speed things up
# Reconnect to sqlite at every run, to avoid thread problems
def create():
global conn
conn.execute("create table files (path text)")
def open():
global db, conn
conn = sqlite3.connect(db)
conn.text_factory = str
def close():
global conn
conn.commit()
conn.close()
conn = None
def init():
global db
db = join(settings.get("ocarina"),"ocarina.db")
dbExists = checkPath(db)
open()
if dbExists == False:
create()
close()
def insert(file):
global conn
if conn == None:
open()
#c = conn.cursor()
t = (file,)
conn.execute('insert into files values(?)',t)
#c.close()