* 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
This commit is contained in:
Eray Özkural
2006-03-22 20:19:49 +00:00
parent ca94151d64
commit a6817216cc
5 changed files with 33 additions and 20 deletions
+3 -1
View File
@@ -33,5 +33,7 @@ class Error(Exception):
"""Class of exceptions that lead to program termination""" """Class of exceptions that lead to program termination"""
pass pass
import pisi.api
# FIXME: can't do this due to name clashes in config and other singletons booo # FIXME: can't do this due to name clashes in config and other singletons booo
#from pisi.api import * #pisi.api import *
+15 -7
View File
@@ -48,7 +48,7 @@ import pisi.lockeddbshelve as shelve
class Error(pisi.Error): class Error(pisi.Error):
pass 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""" """Initialize PiSi subsystem"""
# UI comes first # UI comes first
@@ -71,7 +71,7 @@ def init(database = True, options = None, ui = None, comar = True):
# initialize repository databases # initialize repository databases
ctx.database = database ctx.database = database
if database: if database:
shelve.init_dbenv() shelve.init_dbenv(write=write)
ctx.repodb = pisi.repodb.init() ctx.repodb = pisi.repodb.init()
ctx.installdb = pisi.installdb.init() ctx.installdb = pisi.installdb.init()
ctx.filesdb = pisi.files.FilesDB() ctx.filesdb = pisi.files.FilesDB()
@@ -93,14 +93,18 @@ def finalize():
if ctx.initialized: if ctx.initialized:
pisi.repodb.finalize() pisi.repodb.finalize()
pisi.installdb.finalize() pisi.installdb.finalize()
if ctx.filesdb: if ctx.filesdb != None:
ctx.filesdb.close() ctx.filesdb.close()
if ctx.componentdb: ctx.filesdb = None
if ctx.componentdb != None:
ctx.componentdb.close() ctx.componentdb.close()
ctx.componentdb = None
if ctx.packagedb: if ctx.packagedb:
packagedb.finalize_db() packagedb.finalize_db()
ctx.packagedb = None ctx.packagedb = None
if ctx.sourcedb:
pisi.sourcedb.finalize() pisi.sourcedb.finalize()
ctx.sourcedb = None
pisi.search.finalize() pisi.search.finalize()
if ctx.dbenv: if ctx.dbenv:
ctx.dbenv.close() ctx.dbenv.close()
@@ -328,8 +332,10 @@ def delete_cache():
def rebuild_db(files=False): def rebuild_db(files=False):
assert ctx.database == False
def destroy(files): def destroy(files):
from pisi.lockeddbshelve import LockedDBShelf #from pisi.lockeddbshelve import LockedDBShelf
for db in os.listdir(ctx.config.db_dir()): for db in os.listdir(ctx.config.db_dir()):
if db.endswith('.bdb'): # delete only db files if db.endswith('.bdb'): # delete only db files
if db.startswith('files') or db.startswith('filesdbversion'): if db.startswith('files') or db.startswith('filesdbversion'):
@@ -348,13 +354,15 @@ def rebuild_db(files=False):
ctx.ui.debug('Resurrecting %s' % package_fn) ctx.ui.debug('Resurrecting %s' % package_fn)
pisi.api.resurrect_package(package_fn, files, txn) pisi.api.resurrect_package(package_fn, files, txn)
# check db schema versions
try: try:
pisi.lockeddbshelve.check_dbversion('filesdbversion', pisi.__filesdbversion__, write=False) pisi.lockeddbshelve.check_dbversion('filesdbversion', pisi.__filesdbversion__, write=False)
except: except:
files = True # exception means the files db version was wrong files = True # exception means the files db version was wrong
pisi.lockeddbshelve.init_dbenv()
destroy(files) # bye bye 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 # save parameters and shutdown pisi
options = ctx.config.options options = ctx.config.options
ui = ctx.ui ui = ctx.ui
+1 -1
View File
@@ -70,7 +70,7 @@ class CLI(UI):
msgend = '' msgend = ''
else: else:
msgend = '\n' msgend = '\n'
self.output('%s %s' % (msg, msgend), verbose=verbose) self.output( unicode(msg) + msgend, verbose=verbose)
def warning(self, msg, verbose = False): def warning(self, msg, verbose = False):
if ctx.get_option('no_color'): if ctx.get_option('no_color'):
+9 -9
View File
@@ -39,33 +39,33 @@ from pisi.version import Version
class Error(pisi.Error): class Error(pisi.Error):
pass 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) verfn = join_path(pisi.context.config.db_dir(), versionfile)
if os.path.exists(verfn): if os.path.exists(verfn):
verfile = file(verfn, 'r') verfile = file(verfn, 'r')
ls = verfile.readlines() ls = verfile.readlines()
currver = Version(ls[0]) currver = Version(ls[0])
dbver = Version(ver) 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) raise Error(_('Database version for %s insufficient. Please run rebuild-db command.') % versionfile)
elif currver > dbver: elif currver > dbver:
raise Error(_('Database version for %s greater than PiSi version. You need a newer PiSi.') % versionfile) raise Error(_('Database version for %s greater than PiSi version. You need a newer PiSi.') % versionfile)
else: elif not force:
return True return True # return if force not set and db version ok
elif write: if write:
if os.access(pisi.context.config.db_dir(), os.W_OK): if os.access(pisi.context.config.db_dir(), os.W_OK):
ctx.ui.warning(_('Writing current database version')) ctx.ui.warning(_('Writing current database version'))
verfile = file(verfn, 'w') verfile = file(verfn, 'w')
verfile.write(pisi.__dbversion__) verfile.write(ver)
verfile.close() verfile.close()
else: else:
raise Error(_('Cannot attain write access to database environment')) 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): if os.access(pisi.context.config.db_dir(), os.R_OK):
# try to read version # try to read version
check_dbversion('dbversion', pisi.__dbversion__) check_dbversion('dbversion', pisi.__dbversion__, write=write)
check_dbversion('filesdbversion', pisi.__filesdbversion__) check_dbversion('filesdbversion', pisi.__filesdbversion__, write=write)
else: else:
raise Error(_('Cannot attain read access to database environment')) raise Error(_('Cannot attain read access to database environment'))
if os.access(pisi.context.config.db_dir(), os.W_OK): if os.access(pisi.context.config.db_dir(), os.W_OK):
+3
View File
@@ -192,3 +192,6 @@ class Version:
def __eq__(self,rhs): def __eq__(self,rhs):
return self.compare(rhs) == 0 return self.compare(rhs) == 0
def __str__(self):
return self.verstring