From 1a6655d0b422d8df9371404148377feba7d9368a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Thu, 8 Jun 2006 15:03:58 +0000 Subject: [PATCH] * fix: determine source component when indexing * fix: add sources to componentdb correctly, enabling emerge :) --- pisi/component.py | 28 +++++++++++++++++++++++++++- pisi/index.py | 30 +++++++++++++++++------------- pisi/sourcedb.py | 2 ++ 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/pisi/component.py b/pisi/component.py index 2c7635ac..07f62ee5 100644 --- a/pisi/component.py +++ b/pisi/component.py @@ -9,7 +9,7 @@ # # Please read the COPYING file. # -# Author: Eray Ozkural +# Author: Eray Ozkural import gettext __trans = gettext.translation('pisi', fallback=True) @@ -149,6 +149,7 @@ class ComponentDB(object): def add_package(self, component_name, package, repo, txn = None): def proc(txn): + assert component_name if self.has_component(component_name, repo, txn): component = self.get_component(component_name, repo, txn) else: @@ -171,6 +172,31 @@ class ComponentDB(object): ctx.txn_proc(lambda x: proc(txn, repo), txn) + def add_spec(self, component_name, spec, repo, txn = None): + def proc(txn): + assert component_name + if self.has_component(component_name, repo, txn): + component = self.get_component(component_name, repo, txn) + else: + component = Component( name = component_name ) + if not spec in component.sources: + component.sources.append(spec) + self.d.add_item(component_name, component, repo, txn) # update + self.d.txn_proc(proc, txn) + + def remove_spec(self, component_name, spec, repo = None, txn = None): + def proc(txn, repo): + if not self.has_component(component_name, repo, txn): + raise Error(_('Information for component %s not available') % component_name) + 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 spec in component.sources: + component.packages.remove(spec) + self.d.add_item(component_name, component, repo, txn) # update + + ctx.txn_proc(lambda x: proc(txn, repo), txn) + def clear(self, txn = None): self.d.clear(txn) diff --git a/pisi/index.py b/pisi/index.py index 814684ee..4d3786ff 100644 --- a/pisi/index.py +++ b/pisi/index.py @@ -38,7 +38,7 @@ import pisi.specfile as specfile class Error(pisi.Error): pass - + class Index(XmlFile): __metaclass__ = autoxml.autoxml @@ -156,16 +156,20 @@ class Index(XmlFile): #ctx.ui.error(str(Error(*errs))) def add_spec(self, path, repo_uri): + import pisi.build ctx.ui.info(_('Adding %s to source index') % path) - sf = specfile.SpecFile() - sf.read(path) - errs = sf.errors() - if sf.errors(): - ctx.ui.error(_('SpecFile in %s is corrupt, skipping...') % path) - ctx.ui.error(str(Error(*errs))) - else: - if ctx.config.options and ctx.config.options.absolute_uris: - sf.source.sourceURI = os.path.realpath(path) - else: # create relative path by default - sf.source.sourceURI = util.removepathprefix(repo_uri, path) - self.specs.append(sf) + builder = pisi.build.Builder(path) + #sf = specfile.SpecFile() + #sf.read(path) + #errs = sf.errors() + #if sf.errors(): + #ctx.ui.error(_('SpecFile in %s is corrupt, skipping...') % path) + #ctx.ui.error(str(Error(*errs))) + builder.fetch_component() + sf = builder.spec + if ctx.config.options and ctx.config.options.absolute_uris: + sf.source.sourceURI = os.path.realpath(path) + else: # create relative path by default + sf.source.sourceURI = util.removepathprefix(repo_uri, path) + # check component + self.specs.append(sf) diff --git a/pisi/sourcedb.py b/pisi/sourcedb.py index 248024a9..4abb44dc 100644 --- a/pisi/sourcedb.py +++ b/pisi/sourcedb.py @@ -75,6 +75,7 @@ class SourceDB(object): self.d.add_item(name, spec, repo, txn) for pkg in spec.packages: self.dpkgtosrc.add_item(pkg.name, name, repo, txn) + ctx.componentdb.add_spec(spec.source.partOf, spec.source.name, repo, txn) self.d.txn_proc(proc, txn) def remove_spec(self, name, repo, txn = None): @@ -85,6 +86,7 @@ class SourceDB(object): self.d.remove_item(name, txn=txn) for pkg in spec.packages: self.dpkgtosrc.remove_item_repo(pkg.name, repo, txn) + ctx.componentdb.remove_spec(spec.source.partOf, spec.source.name, repo, txn) self.d.txn_proc(proc, txn)