* 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:
+3
-1
@@ -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 *
|
||||
|
||||
+16
-8
@@ -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
|
||||
|
||||
@@ -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'):
|
||||
|
||||
+10
-10
@@ -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):
|
||||
|
||||
@@ -192,3 +192,6 @@ class Version:
|
||||
|
||||
def __eq__(self,rhs):
|
||||
return self.compare(rhs) == 0
|
||||
|
||||
def __str__(self):
|
||||
return self.verstring
|
||||
|
||||
Reference in New Issue
Block a user