summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Laska <jlaska@redhat.com>2011-04-06 15:09:36 -0400
committerJames Laska <jlaska@redhat.com>2011-04-06 15:09:36 -0400
commit1b282edae37f39fdb26c6517e916f5e17b45d335 (patch)
tree2a1e90156543fc756228530279ee32601b89bea0
parent40fd9738b416e98ffeadb0f7e3ecbf7b911e6234 (diff)
downloadscripts-1b282edae37f39fdb26c6517e916f5e17b45d335.tar.gz
scripts-1b282edae37f39fdb26c6517e916f5e17b45d335.tar.xz
scripts-1b282edae37f39fdb26c6517e916f5e17b45d335.zip
Correct handling of cookiefile. Additional error checks.
-rwxr-xr-xupdate-blocker-wiki48
1 files changed, 42 insertions, 6 deletions
diff --git a/update-blocker-wiki b/update-blocker-wiki
index c2a263d..06e9c7e 100755
--- a/update-blocker-wiki
+++ b/update-blocker-wiki
@@ -93,7 +93,26 @@ def parse_args():
parser.error('Must provide a valid %s' % label)
return value
- if not os.path.exists(opts.cookiefile):
+ def valid_cookiefile(parser, cookiefile):
+ # if it doesn't exist, it can't be valid
+ if not os.path.exists(cookiefile):
+ return False
+
+ # Check if it contains valid data
+ fd = open(cookiefile, 'r')
+ buf = fd.read()
+ fd.close()
+ valid = False
+ # Any non-empty non-comment line is good
+ for line in buf.split('\n'):
+ if line.startswith('#') or len(line) == 0:
+ continue
+ return True
+
+ # Otherwise, no valid content found
+ return False
+
+ if not valid_cookiefile(parser, opts.cookiefile):
opts.user = sanitize_input(parser, opts.user, "username")
opts.passwd = sanitize_input(parser, opts.passwd, "password", ispass=True)
@@ -247,7 +266,7 @@ bugs, refer to [[QA:SOP_nth_bug_process]].
wiki = MediaWiki('https://fedoraproject.org/w/api.php', cookie_file=opts.cookiefile)
# Login to the wiki
- if opts.cookiefile is None:
+ if opts.user:
if opts.verbose: print 'Logging into mediawiki ...'
if not wiki.login(opts.user, opts.passwd):
print "Error: invalid mediawiki username or password"
@@ -275,6 +294,8 @@ bugs, refer to [[QA:SOP_nth_bug_process]].
title=opts.name)
response = wiki.call(q)
+ url = "https://fedoraproject.org/wiki/%s" % q.get('title')
+ # Failure - Captcha
if response.get('edit',{}).get('result','').lower() == 'failure':
# Is a captcha required?
captcha = response.get('edit', {}).get('captcha', False)
@@ -282,9 +303,24 @@ bugs, refer to [[QA:SOP_nth_bug_process]].
q.update(dict(captchaid=captcha.get('id'),
captchaword=eval(captcha.get('question'))))
response = wiki.call(q)
- if response.get('result','').lower() == 'failure':
- print "Failed to update '%s'\n%s" % (q.get('title'), response)
- sys.exit(1)
- print "Updated https://fedoraproject.org/wiki/%s" % q.get('title')
+ # Error - Permission denied
+ if response.has_key('error'):
+ print "Failed to update '%s'\n%s" % (q.get('title'), response.get('error',{}).get('info',''))
+ sys.exit(1)
+ if response.get('result','').lower() == 'failure':
+ print "Failed to update '%s'\n%s" % (q.get('title'), response)
+ sys.exit(1)
+
+ # Info - nochange
+ elif response.get('edit',{}).has_key('nochange'):
+ print "No changes, %s not updated" % (q.get('title'),)
+ # Success
+ elif response.get('edit',{}).has_key('newrevid'):
+ print "Updated %s (revision: %s)" % (url,
+ response.get('edit',{}).get('newrevid'))
+ # Unknown
+ else:
+ print "Unknown result while updating %s\n%s" % (q.get('title'), response)
+
sys.exit(0)