mark the example submission rule files as being raw, so the escapes dont get confused
[htsworkflow.git] / scripts / htsw-record-runfolder
index 288ec1ac00c1f05d327c48a0cb4cf735e16d6f3c..674cd52fb918db49e7650d8ae6a8aa716e211722 100755 (executable)
@@ -1,8 +1,5 @@
 #!/usr/bin/env python
 
-from htsworkflow.util.hdquery import get_hd_serial_num
-from htsworkflow.frontend import settings
-
 from optparse import OptionParser
 import os
 import re
@@ -10,6 +7,10 @@ import sys
 import urllib2
 import urlparse
 
+from django.conf import settings
+
+from htsworkflow.util.hdquery import get_hd_serial_num
+
 runfolder_pattern = re.compile(r'[0-9]{6}_[-A-Za-z\d]+_\d+_(?P<flowcell>[A-Z\d]+)\.tgz')
 
 def extract_flowcell(runfolder_name):
@@ -19,7 +20,7 @@ def extract_flowcell(runfolder_name):
         return match.group('flowcell')
     else:
         return None
-    
+
 def construct_parser():
     """
     """
@@ -32,7 +33,7 @@ def construct_parser():
                       help="device flowcell is being archived to")
     parser.add_option("-s", "--serial", type="string", help="serial num. of archive device")
     parser.add_option("-v", "--verbose", action="store_true", default=False)
-    
+
     return parser
 
 
@@ -42,7 +43,7 @@ def update_db(root_url, flowcells, serial, debug=False):
     """
     for fc in flowcells:
         url = urlparse.urljoin(root_url, '%s/%s/' % (fc, serial))
-        
+
         req = urllib2.Request(url)
         try:
             response = urllib2.urlopen(req)
@@ -51,19 +52,19 @@ def update_db(root_url, flowcells, serial, debug=False):
             if debug:
                 print e.read()
             sys.exit(e.code)
-        
+
         print "DB Update of %s & %s succeeded" % (fc, serial)
         print response.read()
-    
+
 
 def process_args(parser):
     """
     returns flowcell and serial#
     """
     options, args = parser.parse_args()
-    
+
     msg = []
-    
+
     # Only provide device or serial
     if options.device is not None and options.serial is not None:
         parser.error("Please provide only --device or --serial.\n"\
@@ -76,13 +77,16 @@ def process_args(parser):
     else:
         root_url = settings.LINK_FLOWCELL_STORAGE_DEVICE_URL
 
+    if root_url is None:
+        parser.error("Please set path to flowcell storage url")
+
     # if device and serial missing:
     if options.device is None and options.serial is None:
         parser.error('One of --device or --serial is required')
 
     flowcells = []
-    
-    # sanitize args    
+
+    # sanitize args
     for runfolder in args:
         flowcell_id = extract_flowcell(runfolder)
         if flowcell_id is None:
@@ -90,10 +94,10 @@ def process_args(parser):
                          '(got %s)' % (runfolder,))
         else:
             flowcells.append(flowcell_id)
-            
+
     if options.flowcell is not None:
         flowcells.append(options.flowcell)
-        
+
     if len(flowcells) == 0:
         parser.error('please specify a  --flowcell or list of runfolder archives\n'\
                      'for archival. I need something to do.')
@@ -107,15 +111,15 @@ def process_args(parser):
     else:
         msg ="FATAL should not happen error occured; i.e. the best kind!"
         raise ValueError, msg
-    
-    
+
+
 
 def main():
     """
     """
     parser = construct_parser()
     process_args(parser)
-    
+
     #print "Database Updated."
     sys.exit(0)