Re: Better way to this ?? Query database to xml

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 2009-04-05 at 03:40 -0700, Michael A. Peters wrote:
> The ugly string
> 
> rpm -qa --qf '<package name="%{name}">\n  \
> <epoch>%{epoch}</epoch>\n  \
> <version>%{version}</version>\n  \
> <release>%{release}</release>\n  \
> <arch>%{arch}</arch>  \
> <summary>%{summary}</summary>\n  <vendor>%{vendor}</vendor>\n</package>\n'
> 
> The issue - it can produce malformed xml because vendor string can and 
> does sometimes contain < and >
> 
> I'm thinking there probably is a better to do it with python straight 
> from the database? Maybe even something already exists for this?

 For yum I'd just do something like:

% cat /tmp/pkgs-xml.py
#! /usr/bin/python -tt

import sys
import yum

yb = yum.YumBase()
yb.conf.cache = 1

for pkg in yb.rpmdb.returnPackages(patterns=sys.argv[1:]):
    print """\
<package name="%s">
  <epoch>%s</epoch>
  <version>%s</version>
  <release>%s</release>
  <arch>%s</arch>
  <summary>%s</summary>
  <vendor>%s</vendor>
</package>
""" % (pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch,
       yum.misc.to_xml(pkg.summary), yum.misc.to_xml(pkg.vendor))

...but if you can't rely on yum you could copy and paste (or rewrite)
all the yum specific bits and just use rpm-python.

-- 
James Antill <james@xxxxxxxxxxxxxxxxx>
Fedora
_______________________________________________
Rpm-list mailing list
Rpm-list@xxxxxxxxxxxxx
http://lists.rpm.org/mailman/listinfo/rpm-list

[Index of Archives]     [RPM Ecosystem]     [Linux Kernel]     [Red Hat Install]     [PAM]     [Red Hat Watch]     [Red Hat Development]     [Red Hat]     [Gimp]     [Yosemite News]     [IETF Discussion]

  Powered by Linux