Update of /cvsroot/freevo/freevo/lib/pyepg
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30604/lib/pyepg
Modified Files:
db_sqlite.py
Log Message:
-Add version tracking and automatic upgrading.
-Move the database implimentation specific check_table into db_sqlite.py.
Index: db_sqlite.py
===================================================================
RCS file: /cvsroot/freevo/freevo/lib/pyepg/db_sqlite.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** db_sqlite.py 10 Dec 2004 19:55:28 -0000 1.1
--- db_sqlite.py 24 Mar 2005 17:52:26 -0000 1.2
***************
*** 46,49 ****
--- 46,50 ----
log = logging.getLogger('pyepg')
+ latest_version = "0.1.1"
class Database:
***************
*** 53,57 ****
def __init__(self, dbpath):
if not os.path.isfile(dbpath):
! log.warning('epg database missing, creating it')
scheme = os.path.join(os.path.dirname(__file__), 'epg_schema.sql')
os.system('sqlite %s < %s 2>/dev/null >/dev/null' % \
--- 54,58 ----
def __init__(self, dbpath):
if not os.path.isfile(dbpath):
! log.warning('EPG database missing, creating it')
scheme = os.path.join(os.path.dirname(__file__), 'epg_schema.sql')
os.system('sqlite %s < %s 2>/dev/null >/dev/null' % \
***************
*** 65,68 ****
--- 66,90 ----
notifier.step(False, False)
self.cursor = self.db.cursor()
+ ver = self.get_version()
+ log.info('EPG database version %s' % ver)
+ if ver != latest_version:
+ log.warning('EPG database out of date, latest version is %s' % \
+ latest_version)
+ self.upgrade_db(ver)
+
+
+ def upgrade_db(self, ver):
+ # TODO: finish this or change it
+ # Here's a quick hack for the current upgrade:
+
+ if ver == "0.0.0" and latest_version == "0.1.1":
+ log.info('Upgrading EPG database from %s to %s.' % \
+ (ver, latest_version))
+ self.execute('drop table admin')
+ self.execute('create table versioning (thing text primary key,
version text)')
+ self.execute('insert into versioning (thing, version) values
("sql", "0.1.1")')
+ self.execute('create index programs_title on programs (title)')
+ self.commit()
+ return
***************
*** 80,81 ****
--- 102,122 ----
except OperationalError, e:
notifier.step(False, False)
+
+
+ def get_version(self):
+ if self.check_table('versioning'):
+ return self.execute('select version from versioning where
thing="sql"')[0][0]
+ else:
+ return "0.0.0"
+
+
+ def check_table(self, table=None):
+ if not table:
+ return False
+ # verify the table exists
+ if not self.execute('select name from sqlite_master where ' + \
+ 'name="%s" and type="table"' % table):
+ return None
+ return table
+
+
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog