OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Access the commit queue from the command line. | 6 """Access the commit queue from the command line. |
7 """ | 7 """ |
8 | 8 |
9 __version__ = '0.1' | 9 __version__ = '0.1' |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 help='Rietveld server, default: %default') | 70 help='Rietveld server, default: %default') |
71 auth.add_auth_options(parser) | 71 auth.add_auth_options(parser) |
72 | 72 |
73 # Call the original function with the modified parser. | 73 # Call the original function with the modified parser. |
74 return fn(parser, args, *extra_args, **kwargs) | 74 return fn(parser, args, *extra_args, **kwargs) |
75 | 75 |
76 hook.func_usage_more = '[options]' | 76 hook.func_usage_more = '[options]' |
77 return hook | 77 return hook |
78 | 78 |
79 | 79 |
80 def set_commit(obj, issue, flag): | 80 def _apply_on_issue(fun, obj, issue): |
tandrii(chromium)
2015/11/30 14:03:11
well, if you are into making re-usable thing, why
Michael Achenbach
2015/11/30 14:11:07
I'm not entirely sure about the semantics of the c
| |
81 """Sets the commit bit flag on an issue.""" | 81 """Applies function 'fun' on an issue.""" |
82 try: | 82 try: |
83 patchset = obj.get_issue_properties(issue, False)['patchsets'][-1] | 83 return fun(obj.get_issue_properties(issue, False)) |
84 print obj.set_flag(issue, patchset, 'commit', flag) | |
85 except urllib2.HTTPError, e: | 84 except urllib2.HTTPError, e: |
86 if e.code == 404: | 85 if e.code == 404: |
87 print >> sys.stderr, 'Issue %d doesn\'t exist.' % issue | 86 print >> sys.stderr, 'Issue %d doesn\'t exist.' % issue |
88 elif e.code == 403: | 87 elif e.code == 403: |
89 print >> sys.stderr, 'Access denied to issue %d.' % issue | 88 print >> sys.stderr, 'Access denied to issue %d.' % issue |
90 else: | 89 else: |
91 raise | 90 raise |
92 return 1 | 91 return 1 |
93 | 92 |
93 def get_commit(obj, issue): | |
94 """Gets the commit bit flag of an issue.""" | |
95 def _get_commit(properties): | |
96 print int(properties['commit']) | |
97 return 0 | |
98 _apply_on_issue(_get_commit, obj, issue) | |
99 | |
100 def set_commit(obj, issue, flag): | |
101 """Sets the commit bit flag on an issue.""" | |
102 def _set_commit(properties): | |
103 print obj.set_flag(issue, properties['patchsets'][-1], 'commit', flag) | |
104 return 0 | |
105 _apply_on_issue(_set_commit, obj, issue) | |
106 | |
94 @need_issue | 107 @need_issue |
95 def CMDset(parser, args): | 108 def CMDset(parser, args): |
96 """Sets the commit bit.""" | 109 """Sets the commit bit.""" |
97 options, args, obj = parser.parse_args(args) | 110 options, args, obj = parser.parse_args(args) |
98 if args: | 111 if args: |
99 parser.error('Unrecognized args: %s' % ' '.join(args)) | 112 parser.error('Unrecognized args: %s' % ' '.join(args)) |
100 return set_commit(obj, options.issue, '1') | 113 return set_commit(obj, options.issue, '1') |
101 | 114 |
115 @need_issue | |
116 def CMDget(parser, args): | |
117 """Gets the commit bit.""" | |
118 options, args, obj = parser.parse_args(args) | |
119 if args: | |
120 parser.error('Unrecognized args: %s' % ' '.join(args)) | |
121 return get_commit(obj, options.issue) | |
102 | 122 |
103 @need_issue | 123 @need_issue |
104 def CMDclear(parser, args): | 124 def CMDclear(parser, args): |
105 """Clears the commit bit.""" | 125 """Clears the commit bit.""" |
106 options, args, obj = parser.parse_args(args) | 126 options, args, obj = parser.parse_args(args) |
107 if args: | 127 if args: |
108 parser.error('Unrecognized args: %s' % ' '.join(args)) | 128 parser.error('Unrecognized args: %s' % ' '.join(args)) |
109 return set_commit(obj, options.issue, '0') | 129 return set_commit(obj, options.issue, '0') |
110 | 130 |
111 | 131 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 return CMDhelp(parser, args) | 263 return CMDhelp(parser, args) |
244 | 264 |
245 | 265 |
246 if __name__ == "__main__": | 266 if __name__ == "__main__": |
247 fix_encoding.fix_encoding() | 267 fix_encoding.fix_encoding() |
248 try: | 268 try: |
249 sys.exit(main()) | 269 sys.exit(main()) |
250 except KeyboardInterrupt: | 270 except KeyboardInterrupt: |
251 sys.stderr.write('interrupted\n') | 271 sys.stderr.write('interrupted\n') |
252 sys.exit(1) | 272 sys.exit(1) |
OLD | NEW |