summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Pipping <sebastian@pipping.org>2009-10-05 17:30:22 +0200
committerSebastian Pipping <sebastian@pipping.org>2009-10-05 17:30:22 +0200
commit5d1fa5c0a9331c73bfe7cfb42392a3d2df9ff12a (patch)
treeeae3053cb20e7e9f517a34794f911e8a71ac0ad7 /diff-gitosis-conf-against-repositories-xml.py
parentFix link/description interleave in layman-global.txt format (diff)
downloadrepositories-xml-format-5d1fa5c0a9331c73bfe7cfb42392a3d2df9ff12a.tar.gz
repositories-xml-format-5d1fa5c0a9331c73bfe7cfb42392a3d2df9ff12a.tar.bz2
repositories-xml-format-5d1fa5c0a9331c73bfe7cfb42392a3d2df9ff12a.zip
Move gitosis.conf handling script to printing "patches"
Diffstat (limited to 'diff-gitosis-conf-against-repositories-xml.py')
-rwxr-xr-xdiff-gitosis-conf-against-repositories-xml.py180
1 files changed, 180 insertions, 0 deletions
diff --git a/diff-gitosis-conf-against-repositories-xml.py b/diff-gitosis-conf-against-repositories-xml.py
new file mode 100755
index 0000000..580f2ad
--- /dev/null
+++ b/diff-gitosis-conf-against-repositories-xml.py
@@ -0,0 +1,180 @@
+#!/usr/bin/env python
+# Copyright (C) 2009 Sebastian Pipping <sebastian@pipping.org>
+# Licensed under GPL 2 or later
+
+import sys
+import os
+if len(sys.argv) not in (3, 4):
+ print "USAGE:\n python %s foo/gitosis.conf bar/repositories.xml [baz/extended.xml]" % \
+ os.path.basename(sys.argv[0])
+ sys.exit(1)
+gitosis_conf_location = sys.argv[1]
+repositories_xml_location = sys.argv[2]
+extended_xml_location = (len(sys.argv) == 4) and sys.argv[3] or None
+
+
+import xml.etree.ElementTree as ET
+from ConfigParser import ConfigParser
+import re
+
+from sharedutils import * # local
+
+
+def sort_as_in(elements, tag_order):
+ order_map = dict((v, i) for i, v in enumerate(tag_order))
+ deco = (t for t in enumerate(elements))
+ deco_sorted = sorted(deco, key=lambda (i, v): (order_map[v.tag], i))
+ return list(v for _, v in deco_sorted)
+
+class ChangeLog:
+ def __init__(self, repo_name, is_new):
+ self.empty = True
+ self.repo_name = repo_name
+ self.is_new = is_new
+
+ def log(self, kind, details):
+ if self.empty:
+ if self.is_new:
+ print 'Repo "%s" missing completely' % self.repo_name
+ else:
+ print 'Analyzing repo "%s":' % self.repo_name
+ self.empty = False
+ elif not self.is_new:
+ print '- Missing %s "%s"' % (kind, details)
+
+
+OWNER_REGEX = re.compile('^([^<]+) (?:\([^)]+\) )?<([^ ]+@[^ ]+)>$')
+NOT_AN_OVERLAY_MESSAGE = 'Skipping %s (not an overlay)'
+
+
+gitosis_conf = ConfigParser()
+gitosis_conf.read(gitosis_conf_location)
+
+a = ET.parse(open(repositories_xml_location))
+repositories = a.getroot()
+overlays_gentoo_org_dict = dict([[e.find('name').text, e] for e in repositories])
+
+for section_name in gitosis_conf.sections():
+ if section_name.startswith('repo '):
+ _repo_base = section_name[len('repo '):].strip()
+ if _repo_base.startswith('dev/'):
+ repo_name = _repo_base[len('dev/'):].strip()
+ owner_type = "person"
+ elif _repo_base.startswith('proj/'):
+ repo_name = _repo_base[len('proj/'):].strip()
+ owner_type = "project"
+ else:
+ # TODO print NOT_AN_OVERLAY_MESSAGE % repo_name
+ continue
+
+ _description = gitosis_conf.get(section_name, 'description')
+ if not gitosis_conf.has_option(section_name, 'gentoo-is-overlay') or \
+ not gitosis_conf.getboolean(section_name, 'gentoo-is-overlay'):
+ if not _description.lower().endswith('overlay'):
+ # TODO print NOT_AN_OVERLAY_MESSAGE % repo_name
+ continue
+
+ is_new = repo_name not in overlays_gentoo_org_dict
+ if is_new:
+ repo = ET.Element('repo')
+ repositories.append(repo)
+ name = ET.Element('name')
+ name.text = repo_name
+ repo.append(name)
+ else:
+ repo = overlays_gentoo_org_dict[repo_name]
+ log = ChangeLog(repo_name, is_new)
+
+ if 'status' not in repo.attrib:
+ repo.attrib['status'] = 'official'
+ log.log('attribute', 'status')
+
+ if 'quality' not in repo.attrib:
+ repo.attrib['quality'] = 'experiental'
+ log.log('attribute', 'quality')
+
+ homepage = repo.find('homepage')
+ if homepage == None:
+ homepage = ET.Element('homepage')
+ homepage.text = 'http://git.overlays.gentoo.org/gitweb/?p=%s.git;a=summary' % _repo_base
+ repo.append(homepage)
+ log.log('homepage', homepage.text)
+
+ description = repo.find('description')
+ if description == None:
+ description = ET.Element('description', lang='en')
+ description.text = _description
+ repo.append(description)
+ log.log('description', _description)
+
+
+ _owner = gitosis_conf.get(section_name, 'owner')
+ _owner_match = OWNER_REGEX.match(_owner)
+
+ owner = repo.find('owner')
+ if owner == None:
+ owner = ET.Element('owner', type=owner_type)
+ repo.append(owner)
+ log.log('owner', 'TODO')
+
+ owner_name = owner.find('name')
+ if owner_name == None:
+ owner_name = ET.Element('name')
+ owner_name.text = _owner_match.group(1)
+ log.log('owner name', owner_name.text)
+
+ owner_email = owner.find('email')
+ if owner_email == None:
+ owner_email = ET.Element('email')
+ owner_email.text = _owner_match.group(2)
+ log.log('owner email', owner_email.text)
+
+ owner[:] = [owner_email, owner_name]
+
+
+ _sources = set((source.attrib['type'], source.text) for source in repo.findall('source'))
+ source_uris = (
+ 'git://git.overlays.gentoo.org/%s.git' % _repo_base,
+ 'http://git.overlays.gentoo.org/gitroot/%s.git' % _repo_base,
+ 'git+ssh://git@git.overlays.gentoo.org/%s.git' % _repo_base,
+ )
+ for uri in source_uris:
+ if ('git', uri) not in _sources and \
+ ('git', uri[:-len('.git')]) not in _sources:
+ source = ET.Element('source', type='git')
+ source.text = uri
+ repo.append(source)
+ log.log('git source', uri)
+
+
+ _feeds = set(feed.text for feed in repo.findall('feed'))
+ feed_uris = (
+ 'http://git.overlays.gentoo.org/gitweb/?p=%s.git;a=atom' % _repo_base,
+ 'http://git.overlays.gentoo.org/gitweb/?p=%s.git;a=rss' % _repo_base,
+ )
+ for uri in feed_uris:
+ if uri not in _feeds:
+ feed = ET.Element('feed')
+ feed.text = uri
+ repo.append(feed)
+ log.log('feed', uri)
+
+ repo[:] = sort_as_in(repo[:], (
+ 'name', 'description', 'longdescription',
+ 'homepage', 'owner', 'source', 'feed'))
+
+ if is_new or not log.empty:
+ if extended_xml_location == None:
+ TERM_WIDTH = 67
+ print '-'*TERM_WIDTH
+ sys.stdout.write(' ')
+ indent(repo, 1)
+ repo.tail = '\n'
+ ET.ElementTree(repo).write(sys.stdout)
+ print '-'*TERM_WIDTH
+ print
+
+
+if extended_xml_location != None:
+ indent(repositories)
+ a.write(extended_xml_location)