]> git.ozlabs.org Git - patchwork/commitdiff
Make parser.py invokation a little more flexible
authorJeremy Kerr <jk@ozlabs.org>
Wed, 10 Sep 2008 02:03:50 +0000 (12:03 +1000)
committerJeremy Kerr <jk@ozlabs.org>
Wed, 10 Sep 2008 02:03:50 +0000 (12:03 +1000)
Add options to control output, allowing us to use the parser to
generate patch hashes.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
apps/patchwork/parser.py

index 8ed36ccb59bcf3d392dc98602e8d525838ae0b98..abec782f4f7c75cf74d7a83ef73b07f680addbdd 100644 (file)
@@ -205,11 +205,31 @@ def hash_patch(str):
 
     return hash
 
-if __name__ == '__main__':
-    import sys
+
+def main(args):
+    from optparse import OptionParser
+
+    parser = OptionParser()
+    parser.add_option('-p', '--patch', action = 'store_true',
+            dest = 'print_patch', help = 'print parsed patch')
+    parser.add_option('-c', '--comment', action = 'store_true',
+            dest = 'print_comment', help = 'print parsed comment')
+    parser.add_option('-#', '--hash', action = 'store_true',
+            dest = 'print_hash', help = 'print patch hash')
+
+    (options, args) = parser.parse_args()
+
     (patch, comment) = parse_patch(sys.stdin.read())
-    if patch:
+
+    if options.print_hash and patch:
+        print hash_patch(patch).hexdigest()
+
+    if options.print_patch and patch:
         print "Patch: ------\n" + patch
-        print "hash: %s" % hash_patch(patch).hexdigest()
-    if comment:
+
+    if options.print_comment and comment:
         print "Comment: ----\n" + comment
+
+if __name__ == '__main__':
+    import sys
+    sys.exit(main(sys.argv))