diff --git a/pisi/__init__.py b/pisi/__init__.py index 41ca5a9a..9fd9f8e8 100644 --- a/pisi/__init__.py +++ b/pisi/__init__.py @@ -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' ] diff --git a/pisi/cli/commands.py b/pisi/cli/commands.py index 1134d33e..ceab3752 100644 --- a/pisi/cli/commands.py +++ b/pisi/cli/commands.py @@ -637,9 +637,10 @@ Usage: info ... 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() diff --git a/pisi/component.py b/pisi/component.py index 7b37b289..f0edb7b9 100644 --- a/pisi/component.py +++ b/pisi/component.py @@ -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) diff --git a/pisi/context.py b/pisi/context.py index 4a9e2c0d..71ec41de 100644 --- a/pisi/context.py +++ b/pisi/context.py @@ -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: diff --git a/pisi/index.py b/pisi/index.py index 8d700d6f..8f46c8b2 100644 --- a/pisi/index.py +++ b/pisi/index.py @@ -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) diff --git a/pisi/itembyrepodb.py b/pisi/itembyrepodb.py index 803b8ffe..5cdd5f0f 100644 --- a/pisi/itembyrepodb.py +++ b/pisi/itembyrepodb.py @@ -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() diff --git a/pisi/packagedb.py b/pisi/packagedb.py index f09416b7..0d4bf3a1 100644 --- a/pisi/packagedb.py +++ b/pisi/packagedb.py @@ -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):