Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import subprocess
- from optparse import OptionParser
- import re
- import os
- def get_request():
- return subprocess.Popen( [ "curl", "--silent", "--cookie", "galaxy_cookie.txt", "--data-ascii", "reload_tool_button=Reload", "http://localhost:8080/admin/ - - - reload_tool" ], stdout=subprocess.PIPE ).communicate()[ 0 ]
- def search_one_line( regex, line ):
- searcher = re.compile( r'.*{0}'.format( regex ))
- if re.search( searcher, line ) is not None:
- return line
- def search_request_for_tool( tool_name ):
- request_data = get_request().split( '\n' )
- matches = [ search_one_line( tool_name, line ) for line in request_data ]
- matches = [ item for item in matches if item is not None]
- return matches[ 0 ]
- def get_complex_tool_name_from_line( line ):
- match = re.search( r'(?<=value=").+(?=")', line ).group( 0 )
- return match
- def reload_found_tool( tool ):
- return subprocess.Popen( [ "curl", "--silent", "--cookie", "galaxy_cookie.txt", "--data-ascii", "tool_id={0}&reload_tool_button=Reload".format( tool ), - - - "http://localhost:8080/admin/reload_tool" ], stdout=subprocess.PIPE ).communicate()[ 0 ]
- def parse_args():
- parser = OptionParser()
- parser.add_option( "-n", "--name", dest="tool_name", help="the tool name to reload", type="string")
- arg, x = parser.parse_args()
- matching_line = search_request_for_tool( arg.tool_name )
- real_tool_name = get_complex_tool_name_from_line( matching_line )
- reload_found_tool( real_tool_name )
- os.chdir( os.path.dirname( os.path.abspath( __file__ ) ) )
- parse_args()
Advertisement
Add Comment
Please, Sign In to add comment