* implement component db using itemby repodb as required

* fix: by this new mechanism, remove packages from components in 
  a consistent way. removed defunct workaround, culprit was:
  #WORKAROUND: do not remove component if it is not in repo
  fixes bug 2683
* fix: forgotten return in itembyrepodb's txn_proc
* fix: do not show installed component, show only repo component
This commit is contained in:
Eray Özkural
2006-05-07 13:32:08 +00:00
parent 0d588e0cbb
commit ec0f4ca325
7 changed files with 58 additions and 40 deletions
+2 -2
View File
@@ -12,9 +12,9 @@
# PiSi version
__version__ = "1.1_beta2"
__version__ = "1.1_beta3"
__dbversion__ = "1.0.9"
__dbversion__ = "1.1_beta3"
__filesdbversion__ = "1.0.5" # yes, this is the real bottleneck
__all__ = [ 'api', 'config', 'packagedb', 'installdb', 'search' ]
+3 -2
View File
@@ -637,9 +637,10 @@ Usage: info <package1> <package2> ... <packagen>
for arg in self.args:
if ctx.componentdb.has_component(arg):
component = ctx.componentdb.get_component(arg)
component, repo = ctx.componentdb.get_component_repo(arg)
#if self.options.long:
ctx.ui.info(unicode(component))
if repo != pisi.itembyrepodb.installed:
ctx.ui.info(unicode(component))
else: # then assume it was a package
self.info_package(arg)
self.finalize()
+47 -31
View File
@@ -19,6 +19,8 @@ import pisi
import pisi.pxml.xmlfile as xmlfile
import pisi.pxml.autoxml as autoxml
import pisi.lockeddbshelve as shelve
from pisi.itembyrepodb import ItemByRepoDB
import pisi.itembyrepodb as itembyrepodb
class Error(pisi.Error):
pass
@@ -91,58 +93,72 @@ class ComponentDB(object):
#FIXME: we might need a database per repo in the future
def __init__(self):
self.d = shelve.LockedDBShelf('components')
self.d = ItemByRepoDB('component')
def close(self):
self.d.close()
def has_component(self, name, txn = None):
name = shelve.LockedDBShelf.encodekey(name)
return self.d.has_key(str(name), txn)
def destroy(self):
self.d.destroy()
def get_component(self, name, txn = None):
name = shelve.LockedDBShelf.encodekey(name)
def has_component(self, name, repo = None, txn = None):
#name = shelve.LockedDBShelf.encodekey(name)
name = str(name)
return self.d.has_key(name, repo, txn)
def get_component(self, name, repo=None, txn = None):
try:
return self.d.get_item(name, repo, txn=txn)
except pisi.itembyrepodb.NotfoundError, e:
raise Error(_('Component %s not found') % name)
def get_component_repo(self, name, repo=None, txn = None):
#name = shelve.LockedDBShelf.encodekey(name)
try:
return self.d.get_item_repo(name, repo, txn=txn)
except pisi.itembyrepodb.NotfoundError, e:
raise Error(_('Component %s not found') % name)
def list_components(self, repo=None, show_tracking=False):
return self.d.list(repo, show_tracking=show_tracking)
def update_component(self, component, repo, txn = None):
def proc(txn):
if not self.has_component(name, txn):
self.d.put(name, Component(name = name), txn)
return self.d.get(name, txn)
return self.d.txn_proc(proc, txn)
def list_components(self):
list = []
for (pkg, x) in self.d.items():
list.append(pkg)
return list
def update_component(self, component, txn = None):
def proc(txn):
if self.d.has_key(component.name):
if self.has_component(component.name, repo, txn):
# preserve the list of packages
component.packages = self.d[component.name].packages
self.d[component.name] = component
component.packages = self.d.get_item(component.name, repo, txn).packages
self.d.add_item(component.name, component, repo, txn)
self.d.txn_proc(proc, txn)
def add_package(self, component_name, package, txn = None):
def add_package(self, component_name, package, repo, txn = None):
def proc(txn):
component = self.get_component(component_name, txn)
if self.has_component(component_name, repo, txn):
component = self.get_component(component_name, repo, txn)
else:
component = Component( name = component_name )
if not package in component.packages:
component.packages.append(package)
self.d.put(component_name, component, txn) # update
self.d.add_item(component_name, component, repo, txn) # update
self.d.txn_proc(proc, txn)
def remove_package(self, component_name, package, txn = None):
def remove_package(self, component_name, package, repo = None, txn = None):
def proc(txn):
if not self.has_component(component_name, txn):
if not self.has_component(component_name, repo, txn):
raise Error(_('Information for component %s not available') % component_name)
component = self.get_component(component_name, txn)
if not repo:
repo = self.d.which_repo(component_name, txn=txn) # get default repo then
component = self.get_component(component_name, repo, txn)
if package in component.packages:
component.packages.remove(package)
self.d.put(component_name, component, txn) # update
self.d.add_item(component_name, component, repo, txn) # update
self.d.txn_proc(proc, txn)
def clear(self, txn = None):
self.d.clear(txn)
def remove_component(self, name, txn = None):
def remove_component(self, name, repo = None, txn = None):
name = str(name)
self.d.delete(name, txn)
self.d.remove_item(name, repo, txn)
def remove_repo(self, repo, txn = None):
self.d.remove_repo(repo, txn=txn)
+2
View File
@@ -53,6 +53,8 @@ initialized = False
import bsddb3.db as db
# copy of DBShelve.txn_proc, the only difference is it doesn't need a shelf object
#FIXME: remove this redundancy, and move all this stuff to database.py
def txn_proc(proc, txn = None):
# can be used to txn protect a method automatically
if not txn:
+1 -1
View File
@@ -106,7 +106,7 @@ class Index(XmlFile):
def update_db(self, repo, txn = None):
for comp in self.components:
ctx.componentdb.update_component(comp, txn=txn)
ctx.componentdb.update_component(comp, repo, txn)
ctx.packagedb.remove_repo(repo, txn=txn)
for pkg in self.packages:
ctx.packagedb.add_package(pkg, repo, txn=txn)
+1 -1
View File
@@ -48,7 +48,7 @@ class ItemByRepoDB(object):
self.d.clear(txn=txn)
def txn_proc(self, proc, txn):
self.d.txn_proc(proc, txn)
return self.d.txn_proc(proc, txn)
def items(self):
return self.d.items()
+2 -3
View File
@@ -97,7 +97,7 @@ class PackageDB(object):
else:
self.dr.add_item(dep_name, [ (name, dep) ], repo, txn)
# add component
ctx.componentdb.add_package(package_info.partOf, package_info.name, txn)
ctx.componentdb.add_package(package_info.partOf, package_info.name, repo, txn)
# index summary and description
for (lang, doc) in package_info.summary.iteritems():
if lang in ['en', 'tr']:
@@ -120,8 +120,7 @@ class PackageDB(object):
if self.dr.has_key(name, repo, txn=txn):
self.dr.remove_item(name, repo, txn=txn)
#WORKAROUND: do not remove component if it is not in repo
if type(repo)==types.StringType:
ctx.componentdb.remove_package(package_info.partOf, package_info.name, txn)
ctx.componentdb.remove_package(package_info.partOf, package_info.name, repo, txn)
self.d.txn_proc(proc, txn)
def remove_repo(self, repo, txn = None):