summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Pipping <sebastian@pipping.org>2009-09-26 01:55:41 +0200
committerSebastian Pipping <sebastian@pipping.org>2009-09-26 01:55:41 +0200
commitd033e73b28f2b789800c48314a23dc49cdaeb053 (patch)
treea725408fbffd65654ceab0de0d4de46c5f03d5b5
parentAdd simple layman parser and tidy.config (diff)
downloadrepositories-xml-format-d033e73b28f2b789800c48314a23dc49cdaeb053.tar.gz
repositories-xml-format-d033e73b28f2b789800c48314a23dc49cdaeb053.tar.bz2
repositories-xml-format-d033e73b28f2b789800c48314a23dc49cdaeb053.zip
Implement layman-global.txt to repositories.xml translator
-rwxr-xr-xlayman-parser.py107
-rw-r--r--overlay-rockage.txt6
-rwxr-xr-xvalidate.sh15
3 files changed, 96 insertions, 32 deletions
diff --git a/layman-parser.py b/layman-parser.py
index d20b20a..5a9d295 100755
--- a/layman-parser.py
+++ b/layman-parser.py
@@ -1,42 +1,91 @@
#!/usr/bin/env python
import xml.etree.ElementTree as ET
+import codecs
-def indent(elem, level=0):
- i = "\n" + level*" "
- if len(elem):
- if not elem.text or not elem.text.strip():
- elem.text = i + " "
- if not elem.tail or not elem.tail.strip():
- elem.tail = i
- for elem in elem:
- indent(elem, level+1)
- if not elem.tail or not elem.tail.strip():
- elem.tail = i
+def to_ascii(o, current_encoding='utf-8'):
+ if not isinstance(o, basestring):
+ return o
+
+ if isinstance(o, unicode):
+ s = o
else:
- if level and (not elem.tail or not elem.tail.strip()):
- elem.tail = i
+ s = unicode(o, current_encoding)
+ return codecs.encode(s, 'ascii', 'ignore')
-def comp_elems (a, b):
- return cmp(a.get('name'), b.get('name'))
+def recurse_print(e, level=0):
+ t = e.text
+ if t:
+ if t == '' or t.isspace():
+ t = None
+ else:
+ t = t.strip('\n\r')
+ print '%s<%s>%s' % (' '*level, e.tag, t and (' .. %s' % to_ascii(t)) or '')
+ for k, v in sorted(e.attrib.items()):
+ print '%s| %s = %s' % (' '*(level+2), k, v)
+ for c in e.getchildren():
+ recurse_print(c, level=level + 1)
a = ET.parse(open('layman-global.txt'))
+overlays = a.getroot()
-x = a.getroot()
-
-x.getchildren().sort(cmp=comp_elems)
-
-#for c in x.getchildren():
-# f = ET.SubElement(c, 'feed')
-# f.text = c.get('src')
-
-indent(x)
-a.write('file')
+for overlay in overlays:
+ # Transform 'overlay' tag
+ overlay.tag = 'repo'
+
+ # Transform 'link' tag
+ link = overlay.find('link')
+ if link != None:
+ link.tag = 'homepage'
+
+ # Move 'description' tag
+ description = overlay.find('description')
+ overlay.remove(description)
+ overlay.insert(0, description)
-C = [t.get('name') for t in x.getchildren()]
-for n in set(C):
- C.remove(n)
+ # Transform 'contact' attribute
+ maintainer = ET.Element('maintainer')
+ overlay.append(maintainer)
+ email = ET.Element('email')
+ email.text = overlay.attrib['contact']
+ del overlay.attrib['contact']
+ maintainer.append(email)
+
+ # Transform 'src' and 'type' attribute
+ source = ET.Element('source')
+ source.text = overlay.attrib['src']
+ del overlay.attrib['src']
+ source.attrib['type'] = overlay.attrib['type']
+ del overlay.attrib['type']
+ overlay.append(source)
+
+ # Extend by quality label
+ overlay.attrib['quality'] = 'experimental' # TODO
+
+ # Extend by maintainer project flag
+ maintainer.attrib['project'] = 'no' # TODO
+
+ # Extend by maintainer name
+ name = ET.Element('name')
+ name.text = 'TODO' # TODO
+ maintainer.append(name)
+
+ # Extend by feed URI
+ feed = ET.Element('feed')
+ overlay.append(feed)
+ feed.text = 'http://www.example.org/TODO/' # TODO
+
+ # Fix issues on the fly
+ if email.text.find('@') == -1 or \
+ email.text.find(' ') != -1:
+ email.text = 'todo@example.org' # TODO
+
+# Transform 'overlays' tag
+overlays.tag = 'repositories'
-print 'dupes:' + str(C)
+# Extend by format version
+overlays.attrib['version'] = '1.0'
+recurse_print(overlays)
+a.write('repositories.xml')
diff --git a/overlay-rockage.txt b/overlay-rockage.txt
index eb0dbe7..a6e6b7c 100644
--- a/overlay-rockage.txt
+++ b/overlay-rockage.txt
@@ -19,15 +19,15 @@ Dead = Dumping ground for dead packages
status="official"
quality="experimental">
<description>Opal and other junk</description>
+ <homepage>asdsads</homepage>
<maintainer project="no">
(<name>Robert Buchholz</name>)
<email>rbu@gentoo.org</email>
</owner>
- <feed>sdsds</feed>
- <feed>sdsds</feed>
- <homepage>asdsads</homepage>
<source type="rsync">git://sadasdsdsd</source>
<source type="git">git://sadasdsdsd</source>
+ <feed>sdsds</feed>
+ <feed>sdsds</feed>
<repo>
</repositories>
diff --git a/validate.sh b/validate.sh
index c0eae3a..2b259f5 100755
--- a/validate.sh
+++ b/validate.sh
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
+echo '==================== layman-global.txt ===================='
echo '== DTD =='
xmllint --noout --dtdvalid layman-global.dtd layman-global.xml \
&& echo VALID \
@@ -10,3 +11,17 @@ xmllint --noout --relaxng layman-global.rng layman-global.xml \
&& echo VALID \
|| echo BROKEN
echo
+
+echo
+echo '==================== repositories.xml ===================='
+echo '== DTD =='
+xmllint --noout --dtdvalid repositories.dtd repositories.xml \
+ && echo VALID \
+ || echo BROKEN
+echo
+
+echo '== Relax NG =='
+xmllint --noout --relaxng repositories.rng repositories.xml \
+ && echo VALID \
+ || echo BROKEN
+echo