* an option to force building of files db
* optimize: do not store paths in files db * fix: destroy db: use db.remove
This commit is contained in:
@@ -747,15 +747,19 @@ If package specs are given, they should be the names of package dirs under /var/
|
||||
|
||||
name = ("rebuild-db", "rdb")
|
||||
|
||||
def options(self):
|
||||
self.parser.add_option("-f", "--files", action="store_true",
|
||||
default=False, help=_("rebuild files database"))
|
||||
|
||||
def run(self):
|
||||
if self.args:
|
||||
self.init(database=True)
|
||||
for package_fn in self.args:
|
||||
pisi.api.resurrect_package(package_fn)
|
||||
pisi.api.resurrect_package(package_fn, ctx.get_option('files`'))
|
||||
else:
|
||||
self.init(database=False)
|
||||
if ctx.ui.confirm(_('Rebuild PISI databases?')):
|
||||
pisi.api.rebuild_db()
|
||||
pisi.api.rebuild_db(ctx.get_option('files'))
|
||||
|
||||
self.finalize()
|
||||
|
||||
|
||||
+6
-5
@@ -57,7 +57,9 @@ class FilesDB(shelve.LockedDBShelf):
|
||||
def add_files(self, pkg_name, files, txn = None):
|
||||
def proc(txn):
|
||||
for x in files.list:
|
||||
self.put(str(x.path), (pkg_name, x), txn)
|
||||
path = x.path
|
||||
del x.path
|
||||
self.put(path, (pkg_name, x), txn)
|
||||
self.txn_proc(proc, txn)
|
||||
|
||||
def remove_files(self, files, txn = None):
|
||||
@@ -76,18 +78,17 @@ class FilesDB(shelve.LockedDBShelf):
|
||||
if not self.has_key(path, txn):
|
||||
return None
|
||||
else:
|
||||
return self.get(path, txn)
|
||||
(name, fileinfo) = self.get(path, txn)
|
||||
fileinfo.path = path
|
||||
return (name, fileinfo)
|
||||
return self.txn_proc(proc, txn)
|
||||
|
||||
def match_files(self, glob):
|
||||
# NB: avoid using, this reads the entire db
|
||||
|
||||
import fnmatch
|
||||
|
||||
glob = str(glob)
|
||||
infos = []
|
||||
for key in self.keys():
|
||||
if fnmatch.fnmatch(key, glob):
|
||||
infos.append(self[key])
|
||||
|
||||
return infos
|
||||
|
||||
@@ -100,7 +100,7 @@ class LockedDBShelf(shelve.DBShelf):
|
||||
self.open(filename, dbname, filetype, flags, mode)
|
||||
|
||||
def destroy(self):
|
||||
os.unlink(self.filename)
|
||||
self.remove(self.filename)
|
||||
|
||||
def __del__(self):
|
||||
# superclass does something funky, we don't need that
|
||||
|
||||
Reference in New Issue
Block a user