diff options
author | James Laska <jlaska@redhat.com> | 2011-03-24 17:08:35 -0400 |
---|---|---|
committer | James Laska <jlaska@redhat.com> | 2011-03-24 17:08:35 -0400 |
commit | 7de3c7373f8ebde88fac968e53f68ef9a3a6a549 (patch) | |
tree | c0adc168f3c39689a11dacaeb6fdf075dbad81ea | |
parent | 731cc4fbc20c5709031c99c14c41abbce5589a56 (diff) | |
download | scripts-7de3c7373f8ebde88fac968e53f68ef9a3a6a549.tar.gz scripts-7de3c7373f8ebde88fac968e53f68ef9a3a6a549.tar.xz scripts-7de3c7373f8ebde88fac968e53f68ef9a3a6a549.zip |
Add try/except around special imports and improved argument processing.
-rwxr-xr-x | update-blocker-wiki | 113 |
1 files changed, 56 insertions, 57 deletions
diff --git a/update-blocker-wiki b/update-blocker-wiki index 5ff268d..3e18198 100755 --- a/update-blocker-wiki +++ b/update-blocker-wiki @@ -2,12 +2,21 @@ import os import sys -import bugzilla import locale import optparse import getpass -from simplemediawiki import MediaWiki +try: + import bugzilla +except ImportError: + print "Unable to import bugzilla. Is python-bugzilla installed?" + sys.exit(1) + +try: + from simplemediawiki import MediaWiki +except ImportError: + print "Unable to import simplemediawiki. Is python-simpemediawiki installed?" + sys.exit(1) BUG_STATUS = ['NEW', 'ASSIGNED', 'ON_DEV', 'MODIFIED', 'POST', 'ON_QA', 'FAILS_QA', 'PASSES_QA', 'REOPENED', 'VERIFIED', 'RELEASE_PENDING'] @@ -24,7 +33,7 @@ NTH_ACCEPTED = {'status_whiteboard': 'AcceptedNTH', NTH_PROPOSED = {'status_whiteboard': 'AcceptedNTH RejectedNTH', 'status_whiteboard_type': 'nowords'} -# UTF8 helper +# UTF8 helper - "borrored" from python-bugzilla def to_encoding(ustring): if isinstance(ustring, basestring): if isinstance(ustring, unicode): @@ -33,8 +42,7 @@ def to_encoding(ustring): return u'' # Display list of bugs, organized by components -def display_bugs_by_component(bugs_by_component): - +def display_bugs_by_component(bugs_by_component, bugs_by_id): buf = '' components = sorted(bugs_by_component.keys()) for component in components: @@ -49,47 +57,39 @@ def display_bugs_by_component(bugs_by_component): def parse_args(): '''Set up the option parser''' parser = optparse.OptionParser(usage="%prog [options] <action> [options]") - parser.add_option('-v', '--verbose', action='store_true', - default=False, help='Enable verbosity') - parser.add_option('--hotdog', action='store_true', - default=False, help='Enable hot dog (default: %default)') - - # Required args - parser.add_option('--blocker', action='store', - default=None, help='Blocker tracking bug number') - parser.add_option('--nth', action='store', - default=None, help='Nice-to-Have tracking bug number') - parser.add_option('-n', '--name', action='store', - default='Current_Release_Blockers', + parser.add_option('-v', '--verbose', action='store_true', default=False, + help='Enable verbosity') + parser.add_option('--hotdog', action='store_true', default=False, + help='Enable hot dog (default: %default)') + + optgrp = optparse.OptionGroup(parser, "Required options") + optgrp.add_option('-n', '--name', action='store', default=None, help='Wiki page name to save results') - parser.add_option('-u', '--user', action='store', - default=None, help='Mediawiki username') - parser.add_option('-p', '--passwd', action='store', - default=None, help='Mediawiki password') + optgrp.add_option('--blocker', action='store', default=None, + help='Blocker tracking bug number') + optgrp.add_option('--nth', action='store', default=None, + help='Nice-to-Have tracking bug number') + optgrp.add_option('-u', '--user', action='store', default=None, + help='Mediawiki username') + optgrp.add_option('-p', '--passwd', action='store', default=None, + help='Mediawiki password') + parser.add_option_group(optgrp) (opts, args) = parser.parse_args() - # sanitize username - if opts.user is None and sys.stdin.isatty(): - opts.user = raw_input('Enter mediawiki username: ') - if opts.user is None: - parser.error('Must provide a valid username') - # sanitize password - if opts.passwd is None and sys.stdin.isatty(): - opts.passwd = getpass.getpass('Enter mediawiki password: ') - if opts.passwd is None: - parser.error('Must provide a valid password') - - # sanitize blocker number - if opts.blocker is None: - opts.blocker = raw_input('Enter Blocker bug number: ') - if opts.blocker is None: - parser.error('Must provide a blocker bug number') - # sanitize nth number - if opts.nth is None: - opts.nth = raw_input('Enter Nice-to-have bug number: ') - if opts.nth is None: - parser.error('Must provide a nice-to-have bug number') + # sanitize helper + def sanitize_input(parser, value, label, ispass=False): + if value is None and sys.stdin.isatty(): + value = raw_input('Enter %s: ' % label) + if value is None: + parser.error('Must provide a valid %s' % label) + return value + + opts.user = sanitize_input(parser, opts.user, "username") + opts.passwd = sanitize_input(parser, opts.passwd, "password", ispass=True) + opts.blocker = sanitize_input(parser, opts.blocker, "Blocker bug number") + opts.nth = sanitize_input(parser, opts.nth, "Nice-to-have bug number") + opts.name = sanitize_input(parser, opts.name, "Wiki page name") return opts @@ -173,7 +173,9 @@ if __name__ == '__main__': bugs_by_id[b.bug_id] = b # Generate page content - page_content = '' + page_content = ''' +This page generated automatically using [http://fedorapeople.org/gitweb?p=jlaska/public_git/scripts.git %s]. +''' % (sys.argv[0],) # Start with the dog if opts.hotdog: @@ -187,8 +189,8 @@ if __name__ == '__main__': The following list of bugs are approved blockers that must be resolved. ''' - # sorted list of approved bugs - page_content += display_bugs_by_component(accepted_blocker_by_component) + # Sorted list of approved bugs + page_content += display_bugs_by_component(accepted_blocker_by_component, bugs_by_id) # Display proposed blockers page_content += ''' @@ -196,8 +198,8 @@ The following list of bugs are approved blockers that must be resolved. The following list of bugs are not yet approved to block the release. For guidance on reviewing the following bugs, refer to [[QA:SOP_blocker_bug_process]]. ''' - # sorted list of proposed bugs - page_content += display_bugs_by_component(proposed_blocker_by_component) + # Sorted list of proposed bugs + page_content += display_bugs_by_component(proposed_blocker_by_component, bugs_by_id) # Display approved nths page_content += ''' @@ -205,8 +207,8 @@ The following list of bugs are not yet approved to block the release. For guida The following list of bugs are approved nths that must be resolved. ''' - # sorted list of approved bugs - page_content += display_bugs_by_component(accepted_nth_by_component) + # Sorted list of approved bugs + page_content += display_bugs_by_component(accepted_nth_by_component, bugs_by_id) # Display proposed nths page_content += ''' @@ -214,9 +216,8 @@ The following list of bugs are approved nths that must be resolved. The following list of bugs are not yet approved to block the release. For guidance on reviewing the following bugs, refer to [[QA:SOP_nth_bug_process]]. ''' - # sorted list of proposed bugs - page_content += display_bugs_by_component(proposed_nth_by_component) - + # Sorted list of proposed bugs + page_content += display_bugs_by_component(proposed_nth_by_component, bugs_by_id) # Create mediawiki handle if opts.verbose: print 'Connecting to mediawiki ...' @@ -224,7 +225,7 @@ The following list of bugs are not yet approved to block the release. For guida # Login to the wiki if not wiki.login(opts.user, opts.passwd): - print "Error: invalid username or password" + print "Error: invalid mediawiki username or password" sys.exit(1) # Get an edit token @@ -242,13 +243,11 @@ The following list of bugs are not yet approved to block the release. For guida q = dict(action='edit', token=edit_token.get('edittoken',''), starttimestamp=edit_token.get('starttimestamp',''), - summary='scripted update brought to you by python-simplemediawiki', + summary='This scripted update brought to you by python-simplemediawiki and python-bugzilla.', text=to_encoding(u'%s' % page_content), title=opts.name) response = wiki.call(q) - # {'edit': {'captcha': {'mime': 'text/plain', 'type': 'simple', 'id': '674992674', 'question': '78 - 6'}, 'result': 'Failure'}} - if response.get('edit',{}).get('result','').lower() == 'failure': # Is a captcha required? captcha = response.get('edit', {}).get('captcha', False) @@ -259,5 +258,5 @@ The following list of bugs are not yet approved to block the release. For guida if response.get('result','').lower() == 'failure': print "Failed to update '%s'\n%s" % (q.get('title'), response) sys.exit(1) - print "Updated '%s'" % q.get('title') + print "Updated %s" % q.get('title') sys.exit(0) |