DummyOptions didn't define a genome_dir member before trying to access it
[htsworkflow.git] / gaworkflow / pipeline / retrieve_config.py
index 232ad2a02e23c499f32259f1b5c7d4f7337d84dc..6ffa7bbfb2d330a37e60450b9a56909cc515c17a 100644 (file)
@@ -10,10 +10,21 @@ import urllib
 CONFIG_SYSTEM = '/etc/ga_frontend/ga_frontend.conf'
 CONFIG_USER = os.path.expanduser('~/.ga_frontend.conf')
 
+#Disable or enable commandline arg parsing; disabled by default.
+DISABLE_CMDLINE = True
 
 class FlowCellNotFound(Exception): pass
 class WebError404(Exception): pass
 
+class DummyOptions:
+  """
+  Used when command line parsing is disabled; default
+  """
+  def __init__(self):
+    self.url = None
+    self.output_filepath = None
+    self.flowcell = None
+    self.genome_dir = None
 
 class PreformattedDescriptionFormatter(IndentedHelpFormatter):
   
@@ -39,6 +50,11 @@ def constructOptionParser():
   """
   returns a pre-setup optparser
   """
+  global DISABLE_CMDLINE
+  
+  if DISABLE_CMDLINE:
+    return None
+  
   parser = OptionParser(formatter=PreformattedDescriptionFormatter())
 
   parser.set_description('Retrieves eland config file from ga_frontend web frontend.')
@@ -66,6 +82,9 @@ Config File:
   
   parser.add_option("-f", "--flowcell",
                     action="store", type="string", dest="flowcell")
+
+  parser.add_option("-g", "--genome_dir",
+                    action="store", type="string", dest="genome_dir")
   
   #parser.set_default("url", "default")
   
@@ -79,6 +98,8 @@ def constructConfigParser():
   parser.read([CONFIG_SYSTEM, CONFIG_USER])
   if not parser.has_section('config_file_server'):
     parser.add_section('config_file_server')
+  if not parser.has_section('local_setup'):
+    parser.add_section('local_setup')
   
   return parser
 
@@ -91,16 +112,24 @@ def getCombinedOptions():
   cl_parser = constructOptionParser()
   conf_parser = constructConfigParser()
   
-  options, args = cl_parser.parse_args()
+  if cl_parser is None:
+    options = DummyOptions()
+  else:
+    options, args = cl_parser.parse_args()
   
   if options.url is None:
     if conf_parser.has_option('config_file_server', 'base_host_url'):
       options.url = conf_parser.get('config_file_server', 'base_host_url')
+
+  if options.genome_dir is None:
+    if conf_parser.has_option('local_setup', 'genome_dir'):
+      options.genome_dir = conf_parser.get('local_setup', 'genome_dir')
   
   print 'USING OPTIONS:'
   print ' URL:', options.url
   print ' OUT:', options.output_filepath
   print '  FC:', options.flowcell
+  print 'GDIR:', options.genome_dir
   print ''
   
   return options