3
# review - adds review comment to charm bug
5
# Copyright (C) 2011 Canonical Ltd.
6
# Author: Mark Mims <mark.mims@canonical.com>
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
26
from launchpadlib.launchpad import Launchpad
30
parser = argparse.ArgumentParser(
31
description="Review a charm by adding a comment to the corresponding"
32
" charm bug. The review comment can be passed as a --message"
35
parser.add_argument('bug_id',
36
help='The launchpad bug for the charm being reviewed.')
40
help='The review text to add as a comment to the bug.')
43
'--yes', '-y', dest="skip_prompt", default=False, action='store_true',
44
help='do not prompt me... just do it.')
47
'--verbose', '-v', default=False, action='store_true',
48
help='show debug logging?')
51
'--lp-instance', '-t', dest='lp_instance', default='production',
52
help="The Launchpad instance to use. Defaults to production, but "
53
"staging' or 'qastaging' might be used for testing.")
55
return parser.parse_args()
58
def log_level(verbose):
62
return logging.WARNING
65
def get_message_from_stdin():
68
sys.stdin = open('/dev/tty') # 'reset' stdin to prompt if necessary
72
def get_message(message):
76
return get_message_from_stdin()
79
def prompt_to_continue(bug_id):
80
logging.debug("prompting")
81
ans = raw_input("Really add this comment to launchpad bug #%s? y/[n] "
83
return ans.strip().lower().startswith('y')
87
args = parse_options()
88
logging.basicConfig(level=log_level(args.verbose),
89
format='%(levelname)s:%(message)s')
91
review_message = get_message(args.message) # before connecting to lp
93
logging.debug('login with %s launchpad:', args.lp_instance)
94
lp = Launchpad.login_with('charm-pilot', args.lp_instance)
97
logging.debug('find bug %s:', bug_id)
101
logging.debug('found bug')
103
if args.skip_prompt or prompt_to_continue(bug_id):
104
logging.debug('adding comment')
105
# TODO check return or catch exception
106
bug.newMessage(content=review_message)
108
logging.debug('not adding comment')
111
logging.error("no bug: %s", bug_id)
117
if __name__ == '__main__':
118
sys.exit(main(sys.argv))