initial checkin 001
[platform/upstream/pattern-tools.git] / scripts / convert-to-yaml.py
1 #!/usr/bin/python
2
3 import xml.etree.ElementTree as ET
4 import sys
5 import yaml
6 import os
7
8
9
10 for f in os.listdir("patterns"):
11     if '.xml' not in f:
12         continue
13     tree = ET.parse("patterns/%s" %f)
14
15     p = {}
16     namespace="http://linux.duke.edu/metadata/rpm"
17     pns = 'http://novell.com/package/metadata/suse/pattern'
18     n  = tree.find('{%s}name' %pns).text
19     if n.startswith("meego-"):
20         n = n[6:]
21     p['Name']  = n
22     s  = tree.find('{%s}summary' %pns).text
23     if s.startswith("MeeGo"):
24         s = s[5:].lstrip()
25     p['Summary']  = s
26     p['Description']  = tree.find('{%s}description' %pns).text
27     req = tree.findall('.//{%s}entry' % namespace)
28     pkgs = []
29     for r in req:
30         pkgs.append(r.attrib.get("name"))
31
32     p['Packages'] = pkgs
33     yf = yaml.dump(p, default_flow_style=False)
34
35     yfn = os.path.basename(f).rpartition(".")[0] + ".yaml"
36     if yfn.startswith("meego-"):
37         yfn = yfn[6:]
38     fp = open("new/%s" %yfn, 'w')
39     fp.write(yf)
40     fp.close()
41