summaryrefslogtreecommitdiff
authorHelio Chissini de Castro <helio@kde.org>2012-07-11 03:46:28 (GMT)
committer Helio Chissini de Castro <helio@kde.org>2012-07-11 03:46:28 (GMT)
commit3153d95e34b88874b7ce88e02adf7d254e8cb6a6 (patch) (side-by-side diff)
tree7e62c904e4c0a9b785a5eb4c1ec339d079808402
downloadanagrman-3153d95e34b88874b7ce88e02adf7d254e8cb6a6.tar.gz
anagrman-3153d95e34b88874b7ce88e02adf7d254e8cb6a6.tar.bz2
- Add anagrman tool to their own repo
Diffstat (more/less context) (ignore whitespace changes)
-rwxr-xr-xanagrman166
1 files changed, 166 insertions, 0 deletions
diff --git a/anagrman b/anagrman
new file mode 100755
index 0000000..a69af45
--- a/dev/null
+++ b/anagrman
@@ -0,0 +1,166 @@
+#!/usr/bin/python
+
+import argparse
+import urllib2
+import codecs
+from HTMLParser import HTMLParser
+from xml.dom.minidom import parseString
+from xml.dom.minidom import Document
+from xml.sax.saxutils import unescape
+from collections import defaultdict
+
+ccuManifestCgitURL = 'http://cgit.collabora.com/git/android/manifests.git'
+availableManifests = []
+listUpdated = False
+verbose = False
+remotes = defaultdict(list)
+projects = defaultdict(dict)
+removals = []
+
+class CgitPlainHTMLParser(HTMLParser):
+ isTag = False
+ global availableManifests;
+ def __init__(self):
+ HTMLParser.__init__(self)
+ self.seen = {}
+ def handle_starttag(self, tag, attrs):
+ if tag == 'a':
+ self.isTag = True
+ def handle_data(self, data):
+ if self.isTag:
+ availableManifests.append(data);
+ self.isTag = False
+
+class CGitPlainXMLParser:
+ global remotes
+ global ccuManifestiCgitURL
+ def __init__(self, manifest ):
+ name = ''
+ fetch = ''
+ revision = ''
+ fremote = ''
+ req = urllib2.Request( ccuManifestCgitURL + '/plain/' + manifest + '/local_manifest.xml')
+ data = urllib2.urlopen(req)
+ dom = parseString( data.read() )
+ xmlrem = dom.getElementsByTagName('remove-project')
+ for r in xmlrem:
+ for i in r.attributes.items():
+ if 'name' in i:
+ removals.append( i[1] )
+ xmlrem = dom.getElementsByTagName('remote')
+ for r in xmlrem:
+ for i in r.attributes.items():
+ if 'name' in i:
+ name = i[1]
+ if 'fetch' in i:
+ fetch = i[1]
+ if name and fetch:
+ remotes[fetch].append(name)
+ name = ''
+ fetch = ''
+ xmlrem = dom.getElementsByTagName('project')
+ for p in xmlrem:
+ for i in p.attributes.items():
+ if 'name' in i:
+ name = i[1]
+ if 'revision' in i:
+ revision = i[1]
+ if 'remote' in i:
+ fremote = i[1]
+ if name and revision and fremote:
+ if projects.has_key( name ):
+ if projects[name]['revision'] != revision:
+ print "Arghhhhhhhhh, there are two revisions for " + name
+ exit
+ if verbose:
+ print "Project " + name + " is present in one or more entries. Can go global."
+ projects[name] = {'revision':revision,'remote':fremote}
+ name = ''
+ revision = ''
+ fremote = ''
+
+class XmlWriter:
+ def __init__(self):
+ self.doc = Document()
+ def createNode(self, nodeName, parentNode = '', withAttribs = {}):
+ node = self.doc.createElement(nodeName)
+ if parentNode == '': # create a parent node
+ createdNode = self.doc.appendChild(node)
+ else: # create a child node
+ createdNode = parentNode.appendChild(node)
+ if withAttribs != {}:
+ for key, value in withAttribs.items():
+ self.setAttribute(createdNode, key, value)
+ return createdNode
+ def setAttribute(self, node, key, value):
+ node.setAttribute(key, value)
+ def printXML(self):
+ print self.doc.toprettyxml(indent=" ")
+ def writeXML(self):
+ f = codecs.open('local_manifest.xml', 'w', 'utf-8')
+ f.write( self.doc.toprettyxml(indent=" ") )
+ f.close()
+
+def generateFinal():
+ doc = XmlWriter()
+ node = doc.createNode('manifest')
+ for r in removals:
+ doc.createNode('remove-project', node, withAttribs = {'name': r } )
+ for r in remotes.keys():
+ doc.createNode('remote', node, withAttribs = {'name': remotes[r][0], 'fetch': r} )
+ for p in projects.keys():
+ newremote = ''
+ for r in remotes.keys():
+ if projects[p]['remote'] in remotes[r]:
+ newremote = remotes[r][0]
+ doc.createNode('project', node, withAttribs = {'path': 'external/collabora/' + p, 'name': p, 'revision':projects[p]['revision'], 'remote':newremote } )
+ if verbose:
+ doc.printXML()
+ doc.writeXML()
+
+def mergeManifests(manifests):
+ runMerge = True
+ updateListFromCgit()
+ for m in manifests:
+ if not m in availableManifests:
+ print "Project " + m + " not exists in the manifest project list."
+ else:
+ CGitPlainXMLParser( m )
+ if verbose:
+ print "Manifest from project " + m + " merged."
+ # Generate numbered repositories to avoid naming dupplication
+ nrepo = 1
+ for key in remotes.keys():
+ remotes[key].insert( 0, 'merged_repository_' + str(nrepo) )
+ nrepo = nrepo + 1
+ generateFinal()
+
+def listManifests():
+ updateListFromCgit()
+ print "Available Manifests:"
+ for project in availableManifests:
+ print project
+
+def updateListFromCgit():
+ global listUpdated
+ if listUpdated:
+ return
+ parser = CgitPlainHTMLParser()
+ req = urllib2.Request( ccuManifestCgitURL + '/plain/')
+ data = urllib2.urlopen(req)
+ parser.feed( data.read() )
+ listUpdated = True
+
+if __name__ == "__main__":
+ # Command line parser
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-l", "--list", help="List available manifest projects.",action="store_true")
+ parser.add_argument("-m", '--manifests', help="Modules separated by space", nargs="*", default=[])
+ parser.add_argument("-v", '--verbose', help="Verbose output", action="store_true")
+ args = parser.parse_args()
+ if args.verbose:
+ verbose = True
+ if args.list:
+ listManifests()
+ if args.manifests:
+ mergeManifests( args.manifests )