summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Pipping <sebastian@pipping.org>2010-01-13 22:42:47 +0100
committerSebastian Pipping <sebastian@pipping.org>2010-01-13 22:59:31 +0100
commit2a8c6eb92c06b79392b553df0b189f1bae927f35 (patch)
tree971c9923832cfe59de8dc7c7790253438083f4cc /write-overlays-ini.py
parentRevert element "category" from repositories.xml (diff)
downloadrepositories-xml-format-2a8c6eb92c06b79392b553df0b189f1bae927f35.tar.gz
repositories-xml-format-2a8c6eb92c06b79392b553df0b189f1bae927f35.tar.bz2
repositories-xml-format-2a8c6eb92c06b79392b553df0b189f1bae927f35.zip
Planet config writer: Handle feed URI collisions better
Diffstat (limited to 'write-overlays-ini.py')
-rwxr-xr-xwrite-overlays-ini.py33
1 files changed, 30 insertions, 3 deletions
diff --git a/write-overlays-ini.py b/write-overlays-ini.py
index d47e88a..737c539 100755
--- a/write-overlays-ini.py
+++ b/write-overlays-ini.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+# -*- coding: utf-8 -*-
# Copyright (C) 2009 Sebastian Pipping <sebastian@pipping.org>
# Licensed under GPL 2 or later
@@ -23,18 +24,44 @@ 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
+ # 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
- repo_name = repo.find('name').text.strip()
overlays_ini.set(_feed_uri, 'name', repo_name)
# _official = (repo.attrib.get('type', 'unofficial') == 'official') and 'yes' or 'no'
@@ -48,7 +75,7 @@ for repo in repositories:
try:
overlays_ini.set(_feed_uri, 'link', repo.find('homepage').text.strip())
except AttributeError:
- print 'Warning: %s is missing a homepage' % repo_name
+ 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')