* autoxml r0xX0rz!
- convert Index to automxl - add error handling, too :) - update the code path for api.index - fix: type of packageURI
This commit is contained in:
+1
-1
@@ -244,7 +244,7 @@ def update_repo(repo):
|
|||||||
|
|
||||||
ctx.ui.info(_('* Updating repository: %s') % repo)
|
ctx.ui.info(_('* Updating repository: %s') % repo)
|
||||||
index = Index()
|
index = Index()
|
||||||
index.read(ctx.repodb.get_repo(repo).indexuri.get_uri(), repo)
|
index.read_uri(ctx.repodb.get_repo(repo).indexuri.get_uri(), repo)
|
||||||
index.update_db(repo)
|
index.update_db(repo)
|
||||||
ctx.ui.info(_('\n* Package database updated.'))
|
ctx.ui.info(_('\n* Package database updated.'))
|
||||||
|
|
||||||
|
|||||||
+20
-22
@@ -21,29 +21,36 @@ import gettext
|
|||||||
__trans = gettext.translation('pisi', fallback=True)
|
__trans = gettext.translation('pisi', fallback=True)
|
||||||
_ = __trans.ugettext
|
_ = __trans.ugettext
|
||||||
|
|
||||||
|
import pisi
|
||||||
import pisi.context as ctx
|
import pisi.context as ctx
|
||||||
|
import pisi.specfile as specfile
|
||||||
import pisi.metadata as metadata
|
import pisi.metadata as metadata
|
||||||
import pisi.packagedb as packagedb
|
import pisi.packagedb as packagedb
|
||||||
import pisi.util as util
|
import pisi.util as util
|
||||||
from pisi.package import Package
|
from pisi.package import Package
|
||||||
from pisi.xmlfile import XmlFile
|
from pisi.xmlfile import XmlFile
|
||||||
|
import pisi.xmlfile as xmlfile
|
||||||
from pisi.uri import URI
|
from pisi.uri import URI
|
||||||
|
|
||||||
|
class Error(pisi.Error):
|
||||||
|
pass
|
||||||
|
|
||||||
class Index(XmlFile):
|
class Index(XmlFile):
|
||||||
|
__metaclass__ = xmlfile.autoxml
|
||||||
|
|
||||||
def __init__(self):
|
tag = "PISI"
|
||||||
XmlFile.__init__(self,"PISI")
|
|
||||||
self.sources = []
|
|
||||||
self.packages = []
|
|
||||||
|
|
||||||
def read(self, filename, repo = None):
|
t_Sources = [ [specfile.Source], xmlfile.optional, "Source"]
|
||||||
|
t_Packages = [ [metadata.Package], xmlfile.optional, "Package"]
|
||||||
|
|
||||||
|
def read_uri(self, filename, repo = None):
|
||||||
"""Read PSPEC file"""
|
"""Read PSPEC file"""
|
||||||
|
|
||||||
self.filepath = filename
|
self.filepath = filename
|
||||||
url = URI(filename)
|
url = URI(filename)
|
||||||
if url.is_remote_file():
|
if url.is_remote_file():
|
||||||
from fetcher import fetch_url
|
from fetcher import fetch_url
|
||||||
|
assert repo
|
||||||
dest = os.path.join(ctx.config.index_dir(), repo)
|
dest = os.path.join(ctx.config.index_dir(), repo)
|
||||||
if not os.path.exists(dest):
|
if not os.path.exists(dest):
|
||||||
os.makedirs(dest)
|
os.makedirs(dest)
|
||||||
@@ -51,21 +58,7 @@ class Index(XmlFile):
|
|||||||
|
|
||||||
self.filepath = os.path.join(dest, url.filename())
|
self.filepath = os.path.join(dest, url.filename())
|
||||||
|
|
||||||
self.readxml(self.filepath)
|
self.read(self.filepath)
|
||||||
|
|
||||||
# find all binary packages
|
|
||||||
packageElts = self.getAllNodes("Package")
|
|
||||||
self.packages = [metadata.PackageInfo(p) for p in packageElts]
|
|
||||||
|
|
||||||
self.unlink()
|
|
||||||
|
|
||||||
def write(self, filename):
|
|
||||||
"""Write index file"""
|
|
||||||
self.newDOM()
|
|
||||||
for pkg in self.packages:
|
|
||||||
self.addChild(pkg.elt(self))
|
|
||||||
self.writexml(filename)
|
|
||||||
self.unlink()
|
|
||||||
|
|
||||||
def index(self, repo_uri):
|
def index(self, repo_uri):
|
||||||
self.repo_dir = repo_uri
|
self.repo_dir = repo_uri
|
||||||
@@ -97,7 +90,12 @@ class Index(XmlFile):
|
|||||||
# function.
|
# function.
|
||||||
md.package.packageURI = util.removepathprefix(repo_uri, path)
|
md.package.packageURI = util.removepathprefix(repo_uri, path)
|
||||||
# check package semantics
|
# check package semantics
|
||||||
if md.has_errors():
|
errs = md.errors()
|
||||||
|
if md.errors():
|
||||||
ctx.ui.error(_('Package %s: metadata corrupt') % md.package.name)
|
ctx.ui.error(_('Package %s: metadata corrupt') % md.package.name)
|
||||||
|
ctx.ui.error(str(Error(*errs)))
|
||||||
else:
|
else:
|
||||||
self.packages.append(md.package)
|
self.packages.append(md.package)
|
||||||
|
|
||||||
|
#TODO: add source
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -60,7 +60,7 @@ class Package:
|
|||||||
t_DistributionRelease = [ xmlfile.String, xmlfile.mandatory]
|
t_DistributionRelease = [ xmlfile.String, xmlfile.mandatory]
|
||||||
t_Architecture = [ xmlfile.String, xmlfile.mandatory]
|
t_Architecture = [ xmlfile.String, xmlfile.mandatory]
|
||||||
t_InstalledSize = [ xmlfile.Integer, xmlfile.mandatory]
|
t_InstalledSize = [ xmlfile.Integer, xmlfile.mandatory]
|
||||||
t_PackageURI = [ xmlfile.Integer, xmlfile.optional]
|
t_PackageURI = [ xmlfile.String, xmlfile.optional]
|
||||||
|
|
||||||
def decode_hook(self, node, errs, where):
|
def decode_hook(self, node, errs, where):
|
||||||
self.version = self.history[0].version
|
self.version = self.history[0].version
|
||||||
|
|||||||
Reference in New Issue
Block a user