Below is the file 'Store.py' from this revision. You can also download the file.
#!/usr/bin/env python # # Abstraction around shelves / data stores used by Fourstar # # provides an abstraction to arbitary store backend # # Store as a shelf #import sqlite3 from sqlite3 import dbapi2 as sqlite from SQLTemplates import * from Error import * class Store: def __init__(self): self.file = None self.db = None self.cursor = None def create(self,file): print file self.file = file self.db = sqlite.connect(file) self.cursor = self.db.cursor() for statement in create_fourstar_db.keys(): self.cursor.execute(create_fourstar_db[statement]) if not self.check_schema(): raise CreateError return True def connect(self,file): print file self.file = file self.db = sqlite.connect(file) self.cursor = self.db.cursor() if not self.check_schema(): raise ConnectError, "Schema not matching" return True def check_schema(self): for statement in create_fourstar_db.keys(): self.cursor.execute("select sql from sqlite_master where tbl_name=?;",(statement,)) sql = self.cursor.fetchone() if not sql: return 0 #print sql[0] #print create_fourstar_db[statement] if sql[0] != create_fourstar_db[statement]: return 0 return 1 def status(self): if not self.check_schema(): raise StatusSchemaError print "status foo!" # # is there any reason why this needs to abstract anything other than # SQL? # # command, arg list # select blah from foo where thing=%s