* 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)
This commit is contained in:
+25
-6
@@ -667,6 +667,8 @@ Usage: info <package1> <package2> ... <packagen>
|
|||||||
help=_("show only paths."))
|
help=_("show only paths."))
|
||||||
self.parser.add_option("-s", "--short", action="store_true",
|
self.parser.add_option("-s", "--short", action="store_true",
|
||||||
default=False, help=_("do not show details"))
|
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):
|
def run(self):
|
||||||
|
|
||||||
@@ -676,13 +678,30 @@ Usage: info <package1> <package2> ... <packagen>
|
|||||||
self.help()
|
self.help()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
index = pisi.index.Index()
|
||||||
|
index.distribution = None
|
||||||
|
|
||||||
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_union_comp(arg)
|
component = ctx.componentdb.get_union_comp(arg)
|
||||||
#if self.options.long:
|
if self.options.xml:
|
||||||
|
index.add_component(component)
|
||||||
|
else:
|
||||||
|
if not self.options.short:
|
||||||
ctx.ui.info(unicode(component))
|
ctx.ui.info(unicode(component))
|
||||||
|
else:
|
||||||
|
ctx.ui.info("%s - %s" % (component.name, component.summary))
|
||||||
else: # then assume it was a package
|
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)
|
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()
|
self.finalize()
|
||||||
|
|
||||||
|
|
||||||
@@ -694,21 +713,19 @@ Usage: info <package1> <package2> ... <packagen>
|
|||||||
else:
|
else:
|
||||||
if ctx.installdb.is_installed(arg):
|
if ctx.installdb.is_installed(arg):
|
||||||
metadata, files = pisi.api.info_name(arg, True)
|
metadata, files = pisi.api.info_name(arg, True)
|
||||||
if ctx.get_option('short'):
|
if self.options.short:
|
||||||
ctx.ui.info(_('[inst] '), noln=True)
|
ctx.ui.info(_('[inst] '), noln=True)
|
||||||
else:
|
else:
|
||||||
ctx.ui.info(_('Installed package:'))
|
ctx.ui.info(_('Installed package:'))
|
||||||
self.print_pkginfo(metadata, files,pisi.itembyrepodb.installed)
|
self.print_pkginfo(metadata, files,pisi.itembyrepodb.installed)
|
||||||
print
|
|
||||||
|
|
||||||
if ctx.packagedb.has_package(arg):
|
if ctx.packagedb.has_package(arg):
|
||||||
metadata, files = pisi.api.info_name(arg, False)
|
metadata, files = pisi.api.info_name(arg, False)
|
||||||
if ctx.get_option('short'):
|
if self.options.short:
|
||||||
ctx.ui.info(_('[repo] '), noln=True)
|
ctx.ui.info(_('[repo] '), noln=True)
|
||||||
else:
|
else:
|
||||||
ctx.ui.info(_('Package found in repository:'))
|
ctx.ui.info(_('Package found in repository:'))
|
||||||
self.print_pkginfo(metadata, files, pisi.itembyrepodb.repos)
|
self.print_pkginfo(metadata, files, pisi.itembyrepodb.repos)
|
||||||
print
|
|
||||||
|
|
||||||
def print_pkginfo(self, metadata, files, repo = None):
|
def print_pkginfo(self, metadata, files, repo = None):
|
||||||
import os.path
|
import os.path
|
||||||
@@ -733,7 +750,7 @@ Usage: info <package1> <package2> ... <packagen>
|
|||||||
print fileinfo.path
|
print fileinfo.path
|
||||||
else:
|
else:
|
||||||
ctx.ui.warning(_('File information not available'))
|
ctx.ui.warning(_('File information not available'))
|
||||||
if ctx.get_option('long'):
|
if not self.options.short:
|
||||||
print
|
print
|
||||||
|
|
||||||
|
|
||||||
@@ -867,6 +884,7 @@ Usage: list-installed
|
|||||||
ctx.ui.info('%15s - %s' % (package.name, unicode(package.summary)))
|
ctx.ui.info('%15s - %s' % (package.name, unicode(package.summary)))
|
||||||
self.finalize()
|
self.finalize()
|
||||||
|
|
||||||
|
|
||||||
class RebuildDb(Command):
|
class RebuildDb(Command):
|
||||||
"""Rebuild Databases
|
"""Rebuild Databases
|
||||||
|
|
||||||
@@ -1086,6 +1104,7 @@ all repositories.
|
|||||||
p = p + ' ' * max(0, 15 - lenp)
|
p = p + ' ' * max(0, 15 - lenp)
|
||||||
ctx.ui.info('%s - %s ' % (p, unicode(package.summary)))
|
ctx.ui.info('%s - %s ' % (p, unicode(package.summary)))
|
||||||
|
|
||||||
|
|
||||||
class ListComponents(Command):
|
class ListComponents(Command):
|
||||||
"""List available components
|
"""List available components
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,15 @@ class XmlFile(object):
|
|||||||
"""returns root document element"""
|
"""returns root document element"""
|
||||||
return self.doc
|
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,
|
def readxml(self, uri, tmpDir='/tmp', sha1sum=False,
|
||||||
compress=None, sign=None, copylocal = False):
|
compress=None, sign=None, copylocal = False):
|
||||||
uri = File.make_uri(uri)
|
uri = File.make_uri(uri)
|
||||||
@@ -73,3 +82,6 @@ class XmlFile(object):
|
|||||||
f = File(uri, File.write, sha1sum=sha1sum, compress=compress, sign=sign)
|
f = File(uri, File.write, sha1sum=sha1sum, compress=compress, sign=sign)
|
||||||
f.write(self.doc.toPrettyString())
|
f.write(self.doc.toPrettyString())
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
def writexmlfile(self, f):
|
||||||
|
f.write(self.doc.toPrettyString())
|
||||||
|
|||||||
+1
-1
@@ -155,7 +155,7 @@ def run_batch(cmd, realtime = False):
|
|||||||
if ctx.stderr:
|
if ctx.stderr:
|
||||||
stderr = ctx.stderr
|
stderr = ctx.stderr
|
||||||
else:
|
else:
|
||||||
stderr = subprocess.STDOUT
|
stderr = subprocess.PIPE
|
||||||
|
|
||||||
out = err = ""
|
out = err = ""
|
||||||
p = subprocess.Popen(cmd, shell=True, stdout=stdout, stderr=stderr)
|
p = subprocess.Popen(cmd, shell=True, stdout=stdout, stderr=stderr)
|
||||||
|
|||||||
Reference in New Issue
Block a user