| 1 |
#!/usr/bin/python -OO
|
| 2 |
|
| 3 |
__revision__ = "$Revision: $"
|
| 4 |
# $Source: $
|
| 5 |
|
| 6 |
from p_objects import *
|
| 7 |
|
| 8 |
def to_xml(p_object):
|
| 9 |
"""Converts portage objects to XML"""
|
| 10 |
|
| 11 |
if isinstance(p_object, Ebuild):
|
| 12 |
begin = ('<ebuild category="%s" name="%s" version="%s" found="%s">' %
|
| 13 |
(p_object.category, p_object.name, p_object.version,
|
| 14 |
p_object.when_found.gmtime().strftime("%a, %d %b %Y %H:%M:%S +0000")))
|
| 15 |
end = '</ebuild>'
|
| 16 |
|
| 17 |
return '\n '.join([begin] + ['<arch>%s</arch>' % x
|
| 18 |
for x in p_object.archs] + [end])
|
| 19 |
|
| 20 |
elif isinstance(p_object, Package):
|
| 21 |
begin = '<package category="%s" name="%s">' % (p_object.category,
|
| 22 |
p_object.name)
|
| 23 |
end = '</package>'
|
| 24 |
description = ('<description><![CDATA[%s]]></description>'
|
| 25 |
% p_object.description)
|
| 26 |
homepage = ''.join(['<homepage><![CDATA[%s]]></homepage>'
|
| 27 |
% x for x in p_object.homepages])
|
| 28 |
license = ''.join(['<license>%s</license>' % x for x in
|
| 29 |
p_object.licenses])
|
| 30 |
|
| 31 |
return '\n '.join([begin, description, homepage, license] +
|
| 32 |
[to_xml(ebuild) for ebuild in p_object.ebuilds] + [end])
|
| 33 |
|
| 34 |
elif isinstance(p_object, Category):
|
| 35 |
begin = '<category name="%s">' % p_object.name
|
| 36 |
end = '</category>'
|
| 37 |
|
| 38 |
return '\n '.join([begin] + [to_xml(package) for package in
|
| 39 |
p_object.packages] + [end])
|
| 40 |
|
| 41 |
elif isinstance(p_object, SubArch):
|
| 42 |
begin = ('<portage arch="%s" branch="%s">'
|
| 43 |
% (p_object.arch, p_object.sub))
|
| 44 |
end = '</portage>'
|
| 45 |
string = ''
|
| 46 |
string = '\n '.join([begin] + [to_xml(category) for category in
|
| 47 |
p_object.categories] + [end])
|
| 48 |
return string
|
| 49 |
|
| 50 |
else:
|
| 51 |
return '\n\t<!-- Do not know how to xmlize %s -->' % p_object
|
| 52 |
|
| 53 |
if __name__ == '__main__':
|
| 54 |
from ebuilddb import db_connect
|
| 55 |
import os
|
| 56 |
|
| 57 |
db = db_connect()
|
| 58 |
collection = ArchCollection()
|
| 59 |
factory = CategoryFactory(db)
|
| 60 |
for arch in config.ARCHLIST:
|
| 61 |
for sub in SUBARCHS:
|
| 62 |
print arch, sub
|
| 63 |
categories = [factory.create(arch, sub, category.name)
|
| 64 |
for category in factory.get(arch, sub)]
|
| 65 |
collection.collection[arch][sub].set_categories(categories)
|
| 66 |
filename = collection.collection[arch][sub].xml_filename
|
| 67 |
#print filename
|
| 68 |
new_filename = filename + '.new'
|
| 69 |
f_object = open(new_filename,'w')
|
| 70 |
f_object.write('<?xml version="1.0" encoding="iso-8859-1"?>\n')
|
| 71 |
f_object.write(to_xml(collection.collection[arch][sub]))
|
| 72 |
f_object.close()
|
| 73 |
os.rename(new_filename, filename)
|