Guest User

reload_tool.py

a guest
Aug 2nd, 2013
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import subprocess
  3. from optparse import OptionParser
  4. import re
  5. import os
  6.  
  7. def get_request():
  8.   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 ]
  9.  
  10. def search_one_line( regex, line ):
  11.   searcher = re.compile( r'.*{0}'.format( regex ))
  12.   if re.search( searcher, line ) is not None:
  13.     return line
  14.  
  15. def search_request_for_tool( tool_name ):
  16.   request_data = get_request().split( '\n' )
  17.   matches = [ search_one_line( tool_name, line ) for line in request_data ]
  18.   matches = [ item for item in matches if item is not None]
  19.   return matches[ 0 ]
  20.  
  21. def get_complex_tool_name_from_line( line ):
  22.   match = re.search( r'(?<=value=").+(?=")', line ).group( 0 )
  23.   return match
  24.  
  25. def reload_found_tool( tool ):
  26.   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 ]
  27.  
  28. def parse_args():
  29.   parser = OptionParser()
  30.   parser.add_option( "-n", "--name", dest="tool_name", help="the tool name to reload", type="string")
  31.   arg, x = parser.parse_args()
  32.   matching_line = search_request_for_tool( arg.tool_name )
  33.   real_tool_name = get_complex_tool_name_from_line( matching_line )
  34.   reload_found_tool( real_tool_name )
  35.  
  36. os.chdir( os.path.dirname( os.path.abspath( __file__ ) ) )
  37. parse_args()
Advertisement
Add Comment
Please, Sign In to add comment