← Back to team overview

keryx team mailing list archive

[Merge] lp:~mac9416/keryx/devel into lp:keryx/devel

 

mac9416 has proposed merging lp:~mac9416/keryx/devel into lp:keryx/devel.

Requested reviews:
    Chris Oliver (excid3)
-- 
https://code.launchpad.net/~mac9416/keryx/devel/+merge/9674
Your team Keryx Development Team is subscribed to branch lp:keryx/devel.
=== added directory 'tools'
=== added file 'tools/StatusMerge.py'
--- tools/StatusMerge.py	1970-01-01 00:00:00 +0000
+++ tools/StatusMerge.py	2009-08-05 01:37:32 +0000
@@ -0,0 +1,55 @@
+#!/usr/bin/python
+
+import os, sys
+from optparse import OptionParser
+
+PROGRAM = 'StatusMerge'
+VERSION = '0.9'
+USAGE = """%prog file1 file2 ...
+
+%prog takes two or more APT status files as arguments and produces one 
+file containing only packages listed in all provided status files."""
+HELP = """EXAMPLE: python StatusMerge.py status1 status2 status3"""
+
+def parse():
+    """ Parses options and arguments passed """
+    parser = OptionParser(description=HELP, usage=USAGE, version='%s %s' % (PROGRAM, VERSION))
+    parser.set_defaults(log_level="ERROR")
+
+    return parser.parse_args()
+
+def main():
+    """ Main code """
+
+    opts, args = parse()
+
+    if len(args) == 0:
+        print HELP
+        exit()
+    elif len(args) < 2:
+        print 'ERROR: not enough arguments. Exiting.'
+        exit()
+
+    status_list = []
+
+    for filename in args:
+        status_file = open(filename, 'rb')
+        text = status_file.read()
+        status_file.close()
+        status_list.append(text.split('\n\n'))
+
+    outfile = file(os.path.join(os.getcwd(), 'status_new'), 'wb')
+
+    for package in status_list[0]:
+        write = True
+        for status in status_list:
+            if not package in status:
+                write = False
+                break
+        if write:
+            outfile.write(package + '\n\n')
+
+    outfile.close()
+
+if __name__ == "__main__":
+    main()