* 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:
+2
-2
@@ -12,9 +12,9 @@
|
|||||||
|
|
||||||
# PiSi version
|
# 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
|
__filesdbversion__ = "1.0.5" # yes, this is the real bottleneck
|
||||||
|
|
||||||
__all__ = [ 'api', 'config', 'packagedb', 'installdb', 'search' ]
|
__all__ = [ 'api', 'config', 'packagedb', 'installdb', 'search' ]
|
||||||
|
|||||||
@@ -637,9 +637,10 @@ Usage: info <package1> <package2> ... <packagen>
|
|||||||
|
|
||||||
for arg in self.args:
|
for arg in self.args:
|
||||||
if ctx.componentdb.has_component(arg):
|
if ctx.componentdb.has_component(arg):
|
||||||
component = ctx.componentdb.get_component(arg)
|
component, repo = ctx.componentdb.get_component_repo(arg)
|
||||||
#if self.options.long:
|
#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
|
else: # then assume it was a package
|
||||||
self.info_package(arg)
|
self.info_package(arg)
|
||||||
self.finalize()
|
self.finalize()
|
||||||
|
|||||||
+47
-31
@@ -19,6 +19,8 @@ import pisi
|
|||||||
import pisi.pxml.xmlfile as xmlfile
|
import pisi.pxml.xmlfile as xmlfile
|
||||||
import pisi.pxml.autoxml as autoxml
|
import pisi.pxml.autoxml as autoxml
|
||||||
import pisi.lockeddbshelve as shelve
|
import pisi.lockeddbshelve as shelve
|
||||||
|
from pisi.itembyrepodb import ItemByRepoDB
|
||||||
|
import pisi.itembyrepodb as itembyrepodb
|
||||||
|
|
||||||
class Error(pisi.Error):
|
class Error(pisi.Error):
|
||||||
pass
|
pass
|
||||||
@@ -91,58 +93,72 @@ class ComponentDB(object):
|
|||||||
|
|
||||||
#FIXME: we might need a database per repo in the future
|
#FIXME: we might need a database per repo in the future
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.d = shelve.LockedDBShelf('components')
|
self.d = ItemByRepoDB('component')
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.d.close()
|
self.d.close()
|
||||||
|
|
||||||
def has_component(self, name, txn = None):
|
def destroy(self):
|
||||||
name = shelve.LockedDBShelf.encodekey(name)
|
self.d.destroy()
|
||||||
return self.d.has_key(str(name), txn)
|
|
||||||
|
|
||||||
def get_component(self, name, txn = None):
|
def has_component(self, name, repo = None, txn = None):
|
||||||
name = shelve.LockedDBShelf.encodekey(name)
|
#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):
|
def proc(txn):
|
||||||
if not self.has_component(name, txn):
|
if self.has_component(component.name, repo, 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):
|
|
||||||
# preserve the list of packages
|
# preserve the list of packages
|
||||||
component.packages = self.d[component.name].packages
|
component.packages = self.d.get_item(component.name, repo, txn).packages
|
||||||
self.d[component.name] = component
|
self.d.add_item(component.name, component, repo, txn)
|
||||||
self.d.txn_proc(proc, 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):
|
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:
|
if not package in component.packages:
|
||||||
component.packages.append(package)
|
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)
|
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):
|
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)
|
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:
|
if package in component.packages:
|
||||||
component.packages.remove(package)
|
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)
|
self.d.txn_proc(proc, txn)
|
||||||
|
|
||||||
def clear(self, txn = None):
|
def clear(self, txn = None):
|
||||||
self.d.clear(txn)
|
self.d.clear(txn)
|
||||||
|
|
||||||
def remove_component(self, name, txn = None):
|
def remove_component(self, name, repo = None, txn = None):
|
||||||
name = str(name)
|
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)
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ initialized = False
|
|||||||
|
|
||||||
import bsddb3.db as db
|
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):
|
def txn_proc(proc, txn = None):
|
||||||
# can be used to txn protect a method automatically
|
# can be used to txn protect a method automatically
|
||||||
if not txn:
|
if not txn:
|
||||||
|
|||||||
+1
-1
@@ -106,7 +106,7 @@ class Index(XmlFile):
|
|||||||
|
|
||||||
def update_db(self, repo, txn = None):
|
def update_db(self, repo, txn = None):
|
||||||
for comp in self.components:
|
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)
|
ctx.packagedb.remove_repo(repo, txn=txn)
|
||||||
for pkg in self.packages:
|
for pkg in self.packages:
|
||||||
ctx.packagedb.add_package(pkg, repo, txn=txn)
|
ctx.packagedb.add_package(pkg, repo, txn=txn)
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class ItemByRepoDB(object):
|
|||||||
self.d.clear(txn=txn)
|
self.d.clear(txn=txn)
|
||||||
|
|
||||||
def txn_proc(self, proc, txn):
|
def txn_proc(self, proc, txn):
|
||||||
self.d.txn_proc(proc, txn)
|
return self.d.txn_proc(proc, txn)
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
return self.d.items()
|
return self.d.items()
|
||||||
|
|||||||
+2
-3
@@ -97,7 +97,7 @@ class PackageDB(object):
|
|||||||
else:
|
else:
|
||||||
self.dr.add_item(dep_name, [ (name, dep) ], repo, txn)
|
self.dr.add_item(dep_name, [ (name, dep) ], repo, txn)
|
||||||
# add component
|
# 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
|
# index summary and description
|
||||||
for (lang, doc) in package_info.summary.iteritems():
|
for (lang, doc) in package_info.summary.iteritems():
|
||||||
if lang in ['en', 'tr']:
|
if lang in ['en', 'tr']:
|
||||||
@@ -120,8 +120,7 @@ class PackageDB(object):
|
|||||||
if self.dr.has_key(name, repo, txn=txn):
|
if self.dr.has_key(name, repo, txn=txn):
|
||||||
self.dr.remove_item(name, repo, txn=txn)
|
self.dr.remove_item(name, repo, txn=txn)
|
||||||
#WORKAROUND: do not remove component if it is not in repo
|
#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, repo, txn)
|
||||||
ctx.componentdb.remove_package(package_info.partOf, package_info.name, txn)
|
|
||||||
self.d.txn_proc(proc, txn)
|
self.d.txn_proc(proc, txn)
|
||||||
|
|
||||||
def remove_repo(self, repo, txn = None):
|
def remove_repo(self, repo, txn = None):
|
||||||
|
|||||||
Reference in New Issue
Block a user