diff options
author | Sebastian Pipping <sebastian@pipping.org> | 2009-09-28 18:34:57 +0200 |
---|---|---|
committer | Sebastian Pipping <sebastian@pipping.org> | 2009-09-28 18:34:57 +0200 |
commit | c2e06d1d9c50704910eb0c586a5508d4c8fcbd19 (patch) | |
tree | 1410220c19c3b6d09ca975f9013e8645a9474ec5 | |
parent | Extract functionality for re-use (diff) | |
download | repositories-xml-format-c2e06d1d9c50704910eb0c586a5508d4c8fcbd19.tar.gz repositories-xml-format-c2e06d1d9c50704910eb0c586a5508d4c8fcbd19.tar.bz2 repositories-xml-format-c2e06d1d9c50704910eb0c586a5508d4c8fcbd19.zip |
Implement repositories.xml to layman-global.txt translator
-rwxr-xr-x | write-layman-global-txt.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/write-layman-global-txt.py b/write-layman-global-txt.py new file mode 100755 index 0000000..8f69f1e --- /dev/null +++ b/write-layman-global-txt.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python + +import xml.etree.ElementTree as ET +from sharedutils import * # local + +a = ET.parse(open('repositories.xml')) +repositories = a.getroot() + +for repo in repositories: + repo_name = repo.attrib['name'] + + # Transform 'repo' tag + repo.tag = 'overlay' + + # Transform 'homepage' tag + homepage = repo.find('homepage') + if homepage != None: + homepage.tag = 'link' + # Move 'link' tag first + repo.remove(homepage) + repo.insert(0, homepage) + + # Transform 'owner' tag + owner = repo.find('owner') + repo.attrib['contact'] = owner.find('email').text + repo.remove(owner) + + # Kill 'feed' tags + for o in repo.findall('feed'): + repo.remove(o) + + first_source = repo.find('source') + repo.attrib['src'] = first_source.text + repo.attrib['type'] = first_source.attrib['type'] + repo.remove(first_source) + + # Kill unsupported attributes + for att_name in ('quality', ): + if att_name in repo.attrib: + del repo.attrib[att_name] + + # Kill unsupported tags + for tag_name in ('feed', 'source'): + for o in repo.findall(tag_name): + repo.remove(o) + +# Kill unsupported attributes +for att_name in ('version', ): + if att_name in repositories.attrib: + del repositories.attrib[att_name] + +# Transform 'repositories' tag +repositories.tag = 'overlays' + +# Add note on file being a generated one +repositories.insert(0, ET.Comment('NOTE: This file is generated, do not edit directly.')) + +recurse_print(repositories) +indent(repositories) +a.write('layman-global.txt') |