Created
December 14, 2012 21:32
-
-
Save garlandkr/4288829 to your computer and use it in GitHub Desktop.
Jenkins restoration from thinBackup plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import argparse | |
import mechanize | |
def get_args(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--url", dest="url", required=True, | |
help="Give the URL for jenkins backup restoration.") | |
return parser.parse_args() | |
def create_browser(url): | |
br = mechanize.Browser() | |
br.set_handle_equiv(True) | |
br.set_handle_redirect(True) | |
br.set_handle_referer(True) | |
br.set_handle_robots(False) | |
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1) | |
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')] | |
try: | |
br.open(url) | |
return br | |
except Exception, e: | |
print e | |
def run(): | |
args = get_args() | |
socket.setdefaulttimeout(25) | |
# Let's try our restore | |
try: | |
br = create_browser(args.url) | |
br.select_form(nr=1) | |
br.form["restorePlugins"] = ['on'] | |
br.submit() | |
except Exception, e: | |
print e | |
if __name__ == '__main__': | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment