#!/usr/bin/env python
-from optparse import OptionParser
+from optparse import OptionParser, IndentedHelpFormatter
from ConfigParser import SafeConfigParser
import os
import sys
import urllib
+CONFIG_SYSTEM = '/etc/ga_frontend/ga_frontend.conf'
+CONFIG_USER = os.path.expanduser('~/.ga_frontend.conf')
+
+class PreformattedDescriptionFormatter(IndentedHelpFormatter):
+
+ #def format_description(self, description):
+ #
+ # if description:
+ # return description + "\n"
+ # else:
+ # return ""
+
+ def format_epilog(self, epilog):
+ """
+ It was removing my preformated epilog, so this should override
+ that behavior! Muhahaha!
+ """
+ if epilog:
+ return "\n" + epilog + "\n"
+ else:
+ return ""
+
def constructOptionParser():
- parser = OptionParser()
+ """
+ returns a pre-setup optparser
+ """
+ parser = OptionParser(formatter=PreformattedDescriptionFormatter())
+
+ parser.set_description('Retrieves eland config file from ga_frontend web frontend.')
+
+ parser.epilog = """
+Config File:
+ * %s (System wide)
+ * %s (User specific; overrides system)
+ * command line overrides all config file options
+
+ Example Config File:
+ [server_info]
+ base_host_url=http://somewhere.domain:port
+""" % (CONFIG_SYSTEM, CONFIG_USER)
+
+ #Special formatter for allowing preformatted description.
+ ##parser.format_epilog(PreformattedDescriptionFormatter())
+
parser.add_option("-u", "--url",
action="store", type="string", dest="url")
return parser
def constructConfigParser():
+ """
+ returns a pre-setup config parser
+ """
parser = SafeConfigParser()
- parser.read(['/etc/elandifier/elandifier.conf',
- os.path.expanduser('~/.elandifier.conf')])
+ parser.read([CONFIG_SYSTEM, CONFIG_USER])
if not parser.has_section('server_info'):
parser.add_section('server_info')
def getCombinedOptions():
+ """
+ Returns optparse options after it has be updated with ConfigParser
+ config files and merged with parsed commandline options.
+ """
cl_parser = constructOptionParser()
conf_parser = constructConfigParser()
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
+ print 'USING OPTIONS:'
+ print ' URL:', options.url
+ print ' OUT:', options.output_filepath
+ print ' FC:', options.flowcell
+ print ''
return options
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)
+ url = base_host_url + '/eland_config/%s/' % (flowcell)
f = open(output_filepath, 'w')
- web = urllib.urlopen(url)
+ try:
+ web = urllib.urlopen(url)
+ except IOError, msg:
+ if str(msg).find("Connection refused") >= 0:
+ print 'Error: Connection refused for: %s' % (url)
+ f.close()
+ sys.exit(1)
+ elif str(msg).find("Name or service not known") >= 0:
+ print 'Error: Invalid domain or ip address for: %s' % (url)
+ f.close()
+ sys.exit(2)
+ else:
+ raise IOError, msg
+
f.write(web.read())
web.close()
f.close()
+ print 'Wrote config file to %s' % (output_filepath)
if __name__ == '__main__':
+ #Display help if no args are presented
+ if len(sys.argv) == 1:
+ sys.argv.append('-h')
+
options = getCombinedOptions()
msg_list = ['ERROR MESSAGES:']
if options.output_filepath is None: