Skip to content

Instantly share code, notes, and snippets.

@meyarivan
Forked from anonymous/flush_index_queue.py
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meyarivan/347af43ecb65ae6863ee to your computer and use it in GitHub Desktop.
Save meyarivan/347af43ecb65ae6863ee to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import mechanize
import logging
import sys, os
USER = 'someuser@mozilla.com'
PASSWORD = 'somepassword'
CONFLUENCE_BASE_URL = "https://mana.mozilla.org"
CONFLUENCE_MANAGE_INDEX_URL = "https://mana.mozilla.org/wiki/admin/viewindexqueue.action"
br = mechanize.Browser()
br.add_password(CONFLUENCE_BASE_URL, USER, PASSWORD)
br.set_handle_equiv(False)
br.set_handle_robots(False)
br.set_handle_referer(False)
# Don't handle Refresh redirections
#br.set_handle_refresh(False)
# Log information about HTTP redirects and Refreshes.
#br.set_debug_redirects(True)
# Log HTTP response bodies (ie. the HTML, most of the time).
#br.set_debug_responses(True)
# Print HTTP headers.
#br.set_debug_http(True)
# admin page
print >> sys.stderr, 'Fetching admin page'
br.open(CONFLUENCE_MANAGE_INDEX_URL)
response = br.response()
headers = response.info()
headers["Content-type"] = "text/html; charset=utf-8"
# auth
print >> sys.stderr, 'Authenticating as admin'
br.select_form(name = 'authenticateform')
br['password'] = PASSWORD
response = br.submit()
# flush queue
print >> sys.stderr, 'Trying to flush queue'
text = response.get_data()
try:
response = br.follow_link(text = 'Flush Queue')
print >> sys.stderr, 'Queue has been flushed'
except mechanize._mechanize.LinkNotFoundError, e:
if text.find('Queue is currently empty') != -1:
print >> sys.stderr, 'Queue is empty'
else:
print >> sys.stderr, 'Unknown content in response'
print >> sys.stderr, text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment