From a6817216ccddf9d10166a7d336e2ef4afcce7fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Wed, 22 Mar 2006 20:19:49 +0000 Subject: [PATCH] * fix: let CLI methods convert given objects to unicode first, as expected * fix: get rebuild-db to work again * fix: note that LockedDBShelf doesn't return True if not equal to None (why the hell???) * __str__ function for Version --- pisi/__init__.py | 4 +++- pisi/api.py | 24 ++++++++++++++++-------- pisi/cli/__init__.py | 2 +- pisi/lockeddbshelve.py | 20 ++++++++++---------- pisi/version.py | 3 +++ 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/pisi/__init__.py b/pisi/__init__.py index e044b4ae..f3b65e92 100644 --- a/pisi/__init__.py +++ b/pisi/__init__.py @@ -33,5 +33,7 @@ class Error(Exception): """Class of exceptions that lead to program termination""" pass +import pisi.api + # FIXME: can't do this due to name clashes in config and other singletons booo -#from pisi.api import * +#pisi.api import * diff --git a/pisi/api.py b/pisi/api.py index 1d7ee9fa..51ea0388 100644 --- a/pisi/api.py +++ b/pisi/api.py @@ -48,7 +48,7 @@ import pisi.lockeddbshelve as shelve class Error(pisi.Error): pass -def init(database = True, options = None, ui = None, comar = True): +def init(database = True, write = False, options = None, ui = None, comar = True): """Initialize PiSi subsystem""" # UI comes first @@ -71,7 +71,7 @@ def init(database = True, options = None, ui = None, comar = True): # initialize repository databases ctx.database = database if database: - shelve.init_dbenv() + shelve.init_dbenv(write=write) ctx.repodb = pisi.repodb.init() ctx.installdb = pisi.installdb.init() ctx.filesdb = pisi.files.FilesDB() @@ -93,14 +93,18 @@ def finalize(): if ctx.initialized: pisi.repodb.finalize() pisi.installdb.finalize() - if ctx.filesdb: + if ctx.filesdb != None: ctx.filesdb.close() - if ctx.componentdb: + ctx.filesdb = None + if ctx.componentdb != None: ctx.componentdb.close() + ctx.componentdb = None if ctx.packagedb: packagedb.finalize_db() ctx.packagedb = None - pisi.sourcedb.finalize() + if ctx.sourcedb: + pisi.sourcedb.finalize() + ctx.sourcedb = None pisi.search.finalize() if ctx.dbenv: ctx.dbenv.close() @@ -328,8 +332,10 @@ def delete_cache(): def rebuild_db(files=False): + assert ctx.database == False + def destroy(files): - from pisi.lockeddbshelve import LockedDBShelf + #from pisi.lockeddbshelve import LockedDBShelf for db in os.listdir(ctx.config.db_dir()): if db.endswith('.bdb'): # delete only db files if db.startswith('files') or db.startswith('filesdbversion'): @@ -348,13 +354,15 @@ def rebuild_db(files=False): ctx.ui.debug('Resurrecting %s' % package_fn) pisi.api.resurrect_package(package_fn, files, txn) + # check db schema versions try: pisi.lockeddbshelve.check_dbversion('filesdbversion', pisi.__filesdbversion__, write=False) except: files = True # exception means the files db version was wrong - pisi.lockeddbshelve.init_dbenv() destroy(files) # bye bye - ctx.dbenv.close() + pisi.lockeddbshelve.check_dbversion('dbversion', pisi.__dbversion__, write=True, force=True) + pisi.lockeddbshelve.check_dbversion('filesdbversion', pisi.__filesdbversion__, write=True, force=True) + # save parameters and shutdown pisi options = ctx.config.options ui = ctx.ui diff --git a/pisi/cli/__init__.py b/pisi/cli/__init__.py index b1e683da..dabf83cc 100644 --- a/pisi/cli/__init__.py +++ b/pisi/cli/__init__.py @@ -70,7 +70,7 @@ class CLI(UI): msgend = '' else: msgend = '\n' - self.output('%s %s' % (msg, msgend), verbose=verbose) + self.output( unicode(msg) + msgend, verbose=verbose) def warning(self, msg, verbose = False): if ctx.get_option('no_color'): diff --git a/pisi/lockeddbshelve.py b/pisi/lockeddbshelve.py index 0be44ea4..2b2268fa 100644 --- a/pisi/lockeddbshelve.py +++ b/pisi/lockeddbshelve.py @@ -39,33 +39,33 @@ from pisi.version import Version class Error(pisi.Error): pass -def check_dbversion(versionfile, ver, write=True): +def check_dbversion(versionfile, ver, write=False, force=False): verfn = join_path(pisi.context.config.db_dir(), versionfile) if os.path.exists(verfn): verfile = file(verfn, 'r') ls = verfile.readlines() currver = Version(ls[0]) dbver = Version(ver) - if currver < dbver: + if currver < dbver and not force: raise Error(_('Database version for %s insufficient. Please run rebuild-db command.') % versionfile) elif currver > dbver: raise Error(_('Database version for %s greater than PiSi version. You need a newer PiSi.') % versionfile) - else: - return True - elif write: + elif not force: + return True # return if force not set and db version ok + if write: if os.access(pisi.context.config.db_dir(), os.W_OK): ctx.ui.warning(_('Writing current database version')) verfile = file(verfn, 'w') - verfile.write(pisi.__dbversion__) + verfile.write(ver) verfile.close() else: raise Error(_('Cannot attain write access to database environment')) - -def init_dbenv(): + +def init_dbenv(write=False): if os.access(pisi.context.config.db_dir(), os.R_OK): # try to read version - check_dbversion('dbversion', pisi.__dbversion__) - check_dbversion('filesdbversion', pisi.__filesdbversion__) + check_dbversion('dbversion', pisi.__dbversion__, write=write) + check_dbversion('filesdbversion', pisi.__filesdbversion__, write=write) else: raise Error(_('Cannot attain read access to database environment')) if os.access(pisi.context.config.db_dir(), os.W_OK): diff --git a/pisi/version.py b/pisi/version.py index 71330c1a..45fb4fa6 100644 --- a/pisi/version.py +++ b/pisi/version.py @@ -192,3 +192,6 @@ class Version: def __eq__(self,rhs): return self.compare(rhs) == 0 + + def __str__(self): + return self.verstring