# HG changeset patch # User Atul Varma # Date 1271212078 25200 # Node ID 0bf01b41e4cb3a7c9fd8b6ec535a21a70de6d460 # Parent 82d1d8b0bedfac58750cd812547b5457194142a9 added get and post commands to bzpatch.py; post isn't done yet. diff -r 82d1d8b0bedf -r 0bf01b41e4cb bzpatch.py --- a/bzpatch.py Tue Apr 13 19:19:10 2010 -0700 +++ b/bzpatch.py Tue Apr 13 19:27:58 2010 -0700 @@ -29,11 +29,7 @@ patch] return '\n'.join(lines) -if __name__ == '__main__': - bug_id = int(sys.argv[1]) - bzapi = bugzilla.BugzillaApi() - bug = bugzilla.Bug.fetch(bzapi, bug_id) - +def get_patch(bug): def cmp_lastcreated(a, b): return cmp(a.creation_time, b.creation_time) @@ -43,4 +39,29 @@ most_recent_patch = patches[-1] - print get_patch_with_header(most_recent_patch) + return get_patch_with_header(most_recent_patch) + +if __name__ == '__main__': + if len(sys.argv) < 3: + print "usage: %s " % sys.argv[0] + sys.exit(1) + + cmd = sys.argv[1] + + if cmd not in ['get', 'post']: + print "unrecognized command: %s" % cmd + sys.exit(1) + + try: + bug_id = int(sys.argv[2]) + except ValueError: + print "not a valid bug id: %s" % sys.argv[2] + sys.exit(1) + + bzapi = bugzilla.BugzillaApi() + bug = bzapi.bugs.get(bug_id) + + if cmd == 'get': + print get_patch(bug) + else: + raise NotImplementedError('TODO: finish this!')