summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlav Vitters <ovitters@mageia.org>2012-02-11 17:54:41 +0000
committerOlav Vitters <ovitters@mageia.org>2012-02-11 17:54:41 +0000
commit2ebcfe05585c8cac0aee4e13feeef0108e5e460b (patch)
tree85a79f27a964681042bb962efe743010ce881303
downloadmgagnome-2ebcfe05585c8cac0aee4e13feeef0108e5e460b.tar
mgagnome-2ebcfe05585c8cac0aee4e13feeef0108e5e460b.tar.gz
mgagnome-2ebcfe05585c8cac0aee4e13feeef0108e5e460b.tar.bz2
mgagnome-2ebcfe05585c8cac0aee4e13feeef0108e5e460b.tar.xz
mgagnome-2ebcfe05585c8cac0aee4e13feeef0108e5e460b.zip
Import mga-gnome script
-rwxr-xr-xmgagnome158
1 files changed, 158 insertions, 0 deletions
diff --git a/mgagnome b/mgagnome
new file mode 100755
index 0000000..481b2cf
--- /dev/null
+++ b/mgagnome
@@ -0,0 +1,158 @@
+#!/usr/bin/python
+
+import os
+import os.path
+import sys
+import re
+import subprocess
+import urllib2
+import urlparse
+import argparse
+from sgmllib import SGMLParser
+
+MEDIA="Core Release Source"
+URL="http://download.gnome.org/sources/"
+PKGROOT='~/pkgs'
+
+class urllister(SGMLParser):
+ def reset(self):
+ SGMLParser.reset(self)
+ self.urls = []
+
+ def start_a(self, attrs):
+ href = [v for k, v in attrs if k=='href']
+ if href:
+ self.urls.extend(href)
+
+def get_upstream_names():
+ urlopen = urllib2.build_opener()
+
+ good_dir = re.compile('^[-A-Za-z0-9_+.]+/$')
+
+ # Get the files
+ usock = urlopen.open(URL)
+ parser = urllister()
+ parser.feed(usock.read())
+ usock.close()
+ parser.close()
+ files = parser.urls
+
+ tarballs = set([filename.replace('/', '') for filename in files if good_dir.search(filename)])
+
+ return tarballs
+
+def get_downstream_names():
+ re_file = re.compile(r'^(?P<module>.*?)[_-](?:(?P<oldversion>([0-9]+[\.])*[0-9]+)-)?(?P<version>([0-9]+[\.\-])*[0-9]+)\.(?P<format>(?:tar\.|diff\.)?[a-z][a-z0-9]*)$')
+
+ p = subprocess.Popen(['urpmf', '--files', '.', "--media", MEDIA], stdout=subprocess.PIPE, close_fds=True)
+ contents = p.stdout.read().strip("\n").splitlines()
+ ecode = p.wait()
+ if ecode != 0:
+ sys.exit(1)
+
+ FILES = {}
+ TARBALLS = {}
+
+ for line in contents:
+ try:
+ srpm, filename = line.split(":")
+ except ValueError:
+ print >>sys.stderr, line
+ continue
+
+ if '.tar' in filename:
+ r = re_file.match(filename)
+ if r:
+ fileinfo = r.groupdict()
+ module = fileinfo['module']
+
+ if module not in TARBALLS:
+ TARBALLS[module] = set()
+ TARBALLS[module].add(srpm)
+
+ if srpm not in FILES:
+ FILES[srpm] = set()
+ FILES[srpm].add(filename)
+
+ return TARBALLS, FILES
+
+def cmd_co(options, parser):
+ upstream = get_upstream_names()
+ downstream, downstream_files = get_downstream_names()
+
+ cwd = os.path.expanduser(PKGROOT)
+
+ matches = upstream & set(downstream.keys())
+ for module in matches:
+ print module, "\t".join(downstream[module])
+ for package in downstream[module]:
+ subprocess.call(['mgarepo', 'co', package], cwd=cwd)
+
+def cmd_ls(options, parser):
+ upstream = get_upstream_names()
+ downstream, downstream_files = get_downstream_names()
+
+ matches = upstream & set(downstream.keys())
+ for module in matches:
+ print "\n".join(downstream[module])
+
+def cmd_patches(options, parser):
+ upstream = get_upstream_names()
+ downstream, downstream_files = get_downstream_names()
+
+ path = os.path.expanduser(PKGROOT)
+
+ matches = upstream & set(downstream.keys())
+ for module in sorted(matches):
+ for srpm in downstream[module]:
+ for filename in downstream_files[srpm]:
+ if '.patch' in filename or '.diff' in filename:
+ print "\t".join((module,srpm, os.path.join(path, srpm, "SOURCES", filename) if options.path else filename))
+
+def main():
+ description = """Mageia GNOME commands."""
+ epilog="""Report bugs to Olav Vitters"""
+ parser = argparse.ArgumentParser(description=description,epilog=epilog)
+
+ # SUBPARSERS
+ subparsers = parser.add_subparsers(title='subcommands')
+ # install
+ subparser = subparsers.add_parser('co', help='checkout all GNOME modules')
+ subparser.set_defaults(
+ func=cmd_co
+ )
+
+ subparser = subparsers.add_parser('packages', help='list all GNOME packages')
+ subparser.set_defaults(
+ func=cmd_ls
+ )
+
+ subparser = subparsers.add_parser('patches', help='list all GNOME patches')
+ subparser.add_argument("-p", "--path", action="store_true", dest="path",
+ help="Full path to patch")
+ subparser.set_defaults(
+ func=cmd_patches, path=False
+ )
+
+
+ if len(sys.argv) == 1:
+ parser.print_help()
+ sys.exit(2)
+
+ options = parser.parse_args()
+
+ try:
+ options.func(options, parser)
+ except KeyboardInterrupt:
+ print('Interrupted')
+ sys.exit(1)
+ except EOFError:
+ print('EOF')
+ sys.exit(1)
+ except IOError, e:
+ if e.errno != errno.EPIPE:
+ raise
+ sys.exit(0)
+
+if __name__ == "__main__":
+ main()