* there was some dailywtf code with db version checking, hopefully
fixed now. it's too silly to explain.
This commit is contained in:
+3
-3
@@ -48,7 +48,7 @@ import pisi.lockeddbshelve as shelve
|
|||||||
class Error(pisi.Error):
|
class Error(pisi.Error):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def init(database = True, write = False, options = None, ui = None, comar = True):
|
def init(database = True, write = True, options = None, ui = None, comar = True):
|
||||||
"""Initialize PiSi subsystem"""
|
"""Initialize PiSi subsystem"""
|
||||||
|
|
||||||
# UI comes first
|
# UI comes first
|
||||||
@@ -366,8 +366,8 @@ def rebuild_db(files=False):
|
|||||||
except:
|
except:
|
||||||
files = True # exception means the files db version was wrong
|
files = True # exception means the files db version was wrong
|
||||||
destroy(files) # bye bye
|
destroy(files) # bye bye
|
||||||
pisi.lockeddbshelve.check_dbversion('dbversion', pisi.__dbversion__, write=True, force=True)
|
pisi.lockeddbshelve.check_dbversion('dbversion', pisi.__dbversion__, write=True, update=True)
|
||||||
pisi.lockeddbshelve.check_dbversion('filesdbversion', pisi.__filesdbversion__, write=True, force=True)
|
pisi.lockeddbshelve.check_dbversion('filesdbversion', pisi.__filesdbversion__, write=True, update=True)
|
||||||
|
|
||||||
# save parameters and shutdown pisi
|
# save parameters and shutdown pisi
|
||||||
options = ctx.config.options
|
options = ctx.config.options
|
||||||
|
|||||||
+15
-7
@@ -38,20 +38,26 @@ from pisi.version import Version
|
|||||||
class Error(pisi.Error):
|
class Error(pisi.Error):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def check_dbversion(versionfile, ver, write=False, force=False):
|
# check database version
|
||||||
|
# if write is given it knows it has write access
|
||||||
|
# if force is given it updates the specified db version
|
||||||
|
def check_dbversion(versionfile, ver, write=False, update=False):
|
||||||
verfn = join_path(pisi.context.config.db_dir(), versionfile)
|
verfn = join_path(pisi.context.config.db_dir(), versionfile)
|
||||||
|
firsttime = False
|
||||||
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 and not force:
|
if currver < dbver and not update:
|
||||||
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)
|
||||||
elif not force:
|
else:
|
||||||
return True # return if force not set and db version ok
|
return True # db version is OK
|
||||||
if write:
|
else:
|
||||||
|
firsttime = True
|
||||||
|
if writen and (update or firsttime):
|
||||||
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 for %s') % versionfile)
|
ctx.ui.warning(_('Writing current database version for %s') % versionfile)
|
||||||
verfile = file(verfn, 'w')
|
verfile = file(verfn, 'w')
|
||||||
@@ -62,11 +68,13 @@ def check_dbversion(versionfile, ver, write=False, force=False):
|
|||||||
else:
|
else:
|
||||||
raise Error(_('Database version %s not present.') % versionfile)
|
raise Error(_('Database version %s not present.') % versionfile)
|
||||||
|
|
||||||
|
# write: write access to database environment
|
||||||
|
# writeversion: would you like to be able
|
||||||
def init_dbenv(write=False, writeversion=False):
|
def init_dbenv(write=False, writeversion=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__, write=writeversion)
|
check_dbversion('dbversion', pisi.__dbversion__, write=write, update=writeversion)
|
||||||
check_dbversion('filesdbversion', pisi.__filesdbversion__, write=writeversion)
|
check_dbversion('filesdbversion', pisi.__filesdbversion__, write=write, update=writeversion)
|
||||||
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):
|
||||||
|
|||||||
Reference in New Issue
Block a user