From f2b6ec93422282139695c37b5d157bb52eab72f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Fri, 16 Jun 2006 15:05:22 +0000 Subject: [PATCH] * fix: use subprocess.PIPE, tested, works for faik's test script * add an --xml option to info command, to do this add a writexml command to xmlfilepiks (a bit incomplete at the moment) --- pisi/cli/commands.py | 37 ++++++++++++++++++++++++++++--------- pisi/pxml/xmlfilepiks.py | 12 ++++++++++++ pisi/util.py | 2 +- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/pisi/cli/commands.py b/pisi/cli/commands.py index 30664fa3..64f082dd 100644 --- a/pisi/cli/commands.py +++ b/pisi/cli/commands.py @@ -667,6 +667,8 @@ Usage: info ... help=_("show only paths.")) self.parser.add_option("-s", "--short", action="store_true", default=False, help=_("do not show details")) + self.parser.add_option("", "--xml", action="store_true", + default=False, help=_("output in xml format")) def run(self): @@ -675,14 +677,31 @@ Usage: info ... if len(self.args) == 0: self.help() return + + index = pisi.index.Index() + index.distribution = None for arg in self.args: if ctx.componentdb.has_component(arg): component = ctx.componentdb.get_union_comp(arg) - #if self.options.long: - ctx.ui.info(unicode(component)) - else: # then assume it was a package - self.info_package(arg) + if self.options.xml: + index.add_component(component) + else: + if not self.options.short: + ctx.ui.info(unicode(component)) + else: + ctx.ui.info("%s - %s" % (component.name, component.summary)) + else: # then assume it was a package + if self.options.xml: + index.packages.append(pisi.api.info(arg)[0].package) + else: + self.info_package(arg) + if self.options.xml: + errs = [] + index.newDocument() + index.encode(index.rootNode(), errs) + index.writexmlfile(sys.stdout) + sys.stdout.write('\n') self.finalize() @@ -694,21 +713,19 @@ Usage: info ... else: if ctx.installdb.is_installed(arg): metadata, files = pisi.api.info_name(arg, True) - if ctx.get_option('short'): + if self.options.short: ctx.ui.info(_('[inst] '), noln=True) else: ctx.ui.info(_('Installed package:')) self.print_pkginfo(metadata, files,pisi.itembyrepodb.installed) - print if ctx.packagedb.has_package(arg): metadata, files = pisi.api.info_name(arg, False) - if ctx.get_option('short'): + if self.options.short: ctx.ui.info(_('[repo] '), noln=True) else: ctx.ui.info(_('Package found in repository:')) self.print_pkginfo(metadata, files, pisi.itembyrepodb.repos) - print def print_pkginfo(self, metadata, files, repo = None): import os.path @@ -733,7 +750,7 @@ Usage: info ... print fileinfo.path else: ctx.ui.warning(_('File information not available')) - if ctx.get_option('long'): + if not self.options.short: print @@ -867,6 +884,7 @@ Usage: list-installed ctx.ui.info('%15s - %s' % (package.name, unicode(package.summary))) self.finalize() + class RebuildDb(Command): """Rebuild Databases @@ -1086,6 +1104,7 @@ all repositories. p = p + ' ' * max(0, 15 - lenp) ctx.ui.info('%s - %s ' % (p, unicode(package.summary))) + class ListComponents(Command): """List available components diff --git a/pisi/pxml/xmlfilepiks.py b/pisi/pxml/xmlfilepiks.py index e7b143e6..15355940 100644 --- a/pisi/pxml/xmlfilepiks.py +++ b/pisi/pxml/xmlfilepiks.py @@ -54,6 +54,15 @@ class XmlFile(object): def rootNode(self): """returns root document element""" return self.doc + + def readxmlfile(self, file): + raise Exception("not implemented") + try: + self.doc = iks.parse(file) + return self.doc + except Exception, e: + raise Error(_("File '%s' has invalid XML") % (localpath) ) + def readxml(self, uri, tmpDir='/tmp', sha1sum=False, compress=None, sign=None, copylocal = False): @@ -73,3 +82,6 @@ class XmlFile(object): f = File(uri, File.write, sha1sum=sha1sum, compress=compress, sign=sign) f.write(self.doc.toPrettyString()) f.close() + + def writexmlfile(self, f): + f.write(self.doc.toPrettyString()) diff --git a/pisi/util.py b/pisi/util.py index faa8cfc7..797d01b1 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -155,7 +155,7 @@ def run_batch(cmd, realtime = False): if ctx.stderr: stderr = ctx.stderr else: - stderr = subprocess.STDOUT + stderr = subprocess.PIPE out = err = "" p = subprocess.Popen(cmd, shell=True, stdout=stdout, stderr=stderr)