diff --git a/pisi/cli/commands.py b/pisi/cli/commands.py index 45e2cf10..1c69cc0d 100644 --- a/pisi/cli/commands.py +++ b/pisi/cli/commands.py @@ -137,12 +137,12 @@ class Command(object): else: self.authInfo = None - def init(self, database = True): + def init(self, database = True, write = True): """initialize PiSi components""" # NB: command imports here or in the command class run fxns import pisi.api - pisi.api.init(database = database, options = self.options, + pisi.api.init(database = database, write = write, options = self.options, comar = self.comar) def finalize(self): diff --git a/pisi/lockeddbshelve.py b/pisi/lockeddbshelve.py index 6025fc77..fe149568 100644 --- a/pisi/lockeddbshelve.py +++ b/pisi/lockeddbshelve.py @@ -76,7 +76,7 @@ def init_dbenv(write=False, writeversion=False): check_dbversion('filesdbversion', pisi.__filesdbversion__, write=write, update=writeversion) else: raise Error(_('Cannot attain read access to database environment')) - if os.access(pisi.context.config.db_dir(), os.W_OK): + if write and os.access(pisi.context.config.db_dir(), os.W_OK): ctx.dbenv = dbobj.DBEnv() flags = (db.DB_INIT_MPOOL | # cache db.DB_INIT_TXN | # transaction subsystem @@ -87,7 +87,9 @@ def init_dbenv(write=False, writeversion=False): ctx.dbenv.open(pisi.context.config.db_dir(), flags) ctx.dbenv.set_flags(db.DB_LOG_AUTOREMOVE, 1) # clear inactive logs automatically else: - ctx.ui.warning(_("Opening PISI database in read-only mode. Operations that require write access will fail.")) + # Warn if not on purpose + if write: + ctx.ui.warning(_("Opening PISI database in read-only mode. Operations that require write access will fail.")) ctx.dbenv = None #def open(filename, flags='r', mode = 0644, filetype = db.DB_BTREE): @@ -113,10 +115,8 @@ class LockedDBShelf(shelve.DBShelf): dbenv = ctx.dbenv shelve.DBShelf.__init__(self, dbenv) filename = join_path(pisi.context.config.db_dir(), dbname + '.bdb') - if os.access(os.path.dirname(filename), os.W_OK): + if dbenv and os.access(os.path.dirname(filename), os.W_OK): flags = 'w' - if not self.dbenv: - raise Error(_('Database writes not allowed without transactions')) elif os.access(filename, os.R_OK): flags = 'r' else: