[project @ First working version of script which retrieves eland config file from...
authorBrandon King <kingb@caltech.edu>
Fri, 9 Nov 2007 23:45:20 +0000 (23:45 +0000)
committerBrandon King <kingb@caltech.edu>
Fri, 9 Nov 2007 23:45:20 +0000 (23:45 +0000)
bin/retrieve_eland_config.py [new file with mode: 0644]

diff --git a/bin/retrieve_eland_config.py b/bin/retrieve_eland_config.py
new file mode 100644 (file)
index 0000000..af8733a
--- /dev/null
@@ -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 <filepath> or --output=<filepath>")
+    
+  if options.flowcell is None:
+    msg_list.append("  Flow cell argument required. -f <flowcell> or --flowcell=<flowcell>")
+    
+  if options.url is None:
+    msg_list.append("  URL argument required (-u <url> or --url=<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)
+