From f08ccf41ccb58d8d5f071b07d0e6753c4d61b88b Mon Sep 17 00:00:00 2001 From: Brandon King Date: Fri, 9 Nov 2007 23:45:20 +0000 Subject: [PATCH] [project @ First working version of script which retrieves eland config file from ga_frontend.] --- bin/retrieve_eland_config.py | 85 ++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 bin/retrieve_eland_config.py diff --git a/bin/retrieve_eland_config.py b/bin/retrieve_eland_config.py new file mode 100644 index 0000000..af8733a --- /dev/null +++ b/bin/retrieve_eland_config.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python + +from optparse import OptionParser +from ConfigParser import SafeConfigParser + +import os +import sys +import urllib + + +def constructOptionParser(): + parser = OptionParser() + + parser.add_option("-u", "--url", + action="store", type="string", dest="url") + + parser.add_option("-o", "--output", + action="store", type="string", dest="output_filepath") + + parser.add_option("-f", "--flowcell", + action="store", type="string", dest="flowcell") + + #parser.set_default("url", "default") + + return parser + +def constructConfigParser(): + parser = SafeConfigParser() + parser.read(['/etc/elandifier/elandifier.conf', + os.path.expanduser('~/.elandifier.conf')]) + if not parser.has_section('server_info'): + parser.add_section('server_info') + + return parser + + +def getCombinedOptions(): + cl_parser = constructOptionParser() + conf_parser = constructConfigParser() + + options, args = cl_parser.parse_args() + + if options.url is None: + if conf_parser.has_option('server_info', 'base_host_url'): + options.url = conf_parser.get('server_info', 'base_host_url') + + print 'URL:', options.url + print 'OUT:', options.output_filepath + print ' FC:', options.flowcell + + return options + + +def saveConfigFile(flowcell, base_host_url, output_filepath): + """ + retrieves the flowcell eland config file, give the base_host_url + (i.e. http://sub.domain.edu:port) + """ + url = base_host_url + '/elandifier/config/%s/' % (flowcell) + + f = open(output_filepath, 'w') + web = urllib.urlopen(url) + f.write(web.read()) + web.close() + f.close() + +if __name__ == '__main__': + options = getCombinedOptions() + msg_list = ['ERROR MESSAGES:'] + if options.output_filepath is None: + msg_list.append(" Output filepath argument required. -o or --output=") + + if options.flowcell is None: + msg_list.append(" Flow cell argument required. -f or --flowcell=") + + if options.url is None: + msg_list.append(" URL argument required (-u or --url=), or entry\n" \ + " in /etc/elandifier/elandifer.conf or ~/.elandifier.conf") + + if len(msg_list) > 1: + print '\n'.join(msg_list) + sys.exit(0) + + saveConfigFile(options.flowcell, options.url, options.output_filepath) + -- 2.30.2