1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2009 Sebastian Pipping <sebastian@pipping.org>
# Licensed under GPL 2 or later
import sys
import os
if len(sys.argv) != 1 + 3:
print "USAGE:\n python %s foo/repositories.xml bar/overlays.base baz/overlays.ini" % \
os.path.basename(sys.argv[0])
sys.exit(1)
repositories_xml_location = sys.argv[1]
overlays_base_location = sys.argv[2]
overlays_ini_location = sys.argv[3]
import xml.etree.ElementTree as ET
from ConfigParser import ConfigParser, DuplicateSectionError
from sharedutils import * # local
a = ET.parse(open(repositories_xml_location))
repositories = a.getroot()
overlays_ini = ConfigParser()
overlays_ini.read(overlays_base_location)
feed_uri_to_name = {}
for repo in repositories:
try:
_feed_uri = repo.find('feed').text.strip()
except AttributeError:
continue
repo_name = repo.find('name').text.strip()
if _feed_uri in feed_uri_to_name:
feed_uri_to_name[_feed_uri].add(repo_name)
else:
feed_uri_to_name[_feed_uri] = set([repo_name])
def shorten_down(l):
pos = l[0].find('-')
if pos != -1:
# e.g. on ['vdr-devel', 'vdr-experimental']
prefix = l[0][0:pos]
else:
# e.g. on ['wschlich', 'wschlich-testing']
prefix = l[0]
if all(map(lambda x: x.startswith(prefix), l)):
return '%s*' % prefix
else:
if all(map(lambda x: x.endswith('emacs'), l)):
return 'emacs'
return '/'.join(l)
try:
overlays_ini.add_section(_feed_uri)
except DuplicateSectionError:
# print 'Warning: Feed URI collision on <%s>' % _feed_uri
_names = sorted(feed_uri_to_name[_feed_uri])
repo_name = shorten_down(_names)
print ' Info: Making name "%s" from "%s"' % (repo_name, '/'.join(_names))
del _names
overlays_ini.set(_feed_uri, 'name', repo_name)
# _official = (repo.attrib.get('type', 'unofficial') == 'official') and 'yes' or 'no'
_owner_type = repo.find('owner').attrib.get('type', 'project')
if _owner_type == 'person':
overlays_ini.set(_feed_uri, 'developer', 'yes')
else: # TODO elif _owner_type == 'project':
overlays_ini.set(_feed_uri, 'project', 'yes')
try:
overlays_ini.set(_feed_uri, 'link', repo.find('homepage').text.strip())
except AttributeError:
print ' Warning: %s is missing a homepage' % repo_name
f = open(overlays_ini_location, 'w')
f.write('# NOTE: This file is generated, do not edit directly.\n\n')
overlays_ini.write(f)
f.close()
|