Improved debugging output.
authorBrandon King <kingb@caltech.edu>
Wed, 10 Jun 2009 20:13:13 +0000 (20:13 +0000)
committerBrandon King <kingb@caltech.edu>
Wed, 10 Jun 2009 20:13:13 +0000 (20:13 +0000)
  * added a -v/--verbose option
  * Report if a record already existed and therefore did not need to be updated

Fixed a minor logic bug... wasn't actually causing problems.

htsworkflow/frontend/inventory/views.py
scripts/mark_archived_data

index aa106961c7580ec69690d24ebf7952fad2ef32d4..19bcb0b0d85d228ff28a953e9a539dcc63cfbdee 100644 (file)
@@ -11,6 +11,10 @@ def link_flowcell_and_device(request, flowcell, serial):
     """
     assert flowcell is not None
     assert serial is not None
+    
+    LTS_UPDATED = False
+    SD_UPDATED = False
+    LIBRARY_UPDATED = False
         
     ###########################################
     # Retrieve Storage Device
@@ -44,44 +48,70 @@ def link_flowcell_and_device(request, flowcell, serial):
         lts.flowcell = fc
         # Need a primary keey before linking to storage devices
         lts.save()
+        LTS_UPDATED = True
         
         
     ############################################
     # Link Storage to Flowcell
     
     # Add a link to this storage device if it is not already linked.
-    if sd not in lts.storage_devices.values():
+    if sd not in lts.storage_devices.all():
         lts.storage_devices.add(sd)
+        SD_UPDATED = True
     
     ###########################################
     # Add Library Links to LTS
     
-    if fc.lane_1_library not in lts.storage_devices.values():
+    if fc.lane_1_library not in lts.libraries.all():
         lts.libraries.add(fc.lane_1_library)
+        LIBRARY_UPDATED = True
+        print 1
     
-    if fc.lane_2_library not in lts.storage_devices.values():
+    if fc.lane_2_library not in lts.libraries.all():
         lts.libraries.add(fc.lane_2_library)
+        LIBRARY_UPDATED = True
+        print 2
     
-    if fc.lane_3_library not in lts.storage_devices.values():
+    if fc.lane_3_library not in lts.libraries.all():
         lts.libraries.add(fc.lane_3_library)
+        LIBRARY_UPDATED = True
+        print 3
     
-    if fc.lane_4_library not in lts.storage_devices.values():
+    if fc.lane_4_library not in lts.libraries.all():
         lts.libraries.add(fc.lane_4_library)
+        LIBRARY_UPDATED = True
+        print 4
     
     
-    if fc.lane_5_library not in lts.storage_devices.values():
+    if fc.lane_5_library not in lts.libraries.all():
         lts.libraries.add(fc.lane_5_library)
+        LIBRARY_UPDATED = True
+        print 5
     
-    if fc.lane_6_library not in lts.storage_devices.values():
+    if fc.lane_6_library not in lts.libraries.all():
         lts.libraries.add(fc.lane_6_library)
+        LIBRARY_UPDATED = True
+        print 6
     
-    if fc.lane_7_library not in lts.storage_devices.values():
+    if fc.lane_7_library not in lts.libraries.all():
         lts.libraries.add(fc.lane_7_library)
+        LIBRARY_UPDATED = True
+        print 7
     
-    if fc.lane_8_library not in lts.storage_devices.values():
+    if fc.lane_8_library not in lts.libraries.all():
         lts.libraries.add(fc.lane_8_library)
+        LIBRARY_UPDATED = True
+        print 8
         
     # Save Changes
     lts.save()
     
-    return HttpResponse("Success")
\ No newline at end of file
+    msg = ['Success:']
+    if LTS_UPDATED or SD_UPDATED or LIBRARY_UPDATED:
+        msg.append('  LongTermStorage (LTS) Created: %s' % (LTS_UPDATED))
+        msg.append('   Storage Device Linked to LTS: %s' % (SD_UPDATED))
+        msg.append('       Libraries updated in LTS: %s' % (LIBRARY_UPDATED))
+    else:
+        msg.append('  No Updates Needed.')
+    
+    return HttpResponse('\n'.join(msg))
\ No newline at end of file
index 80c6792af9e26b8818cec9e734201049a26d5e60..bd83b3bc9469e5984acf8a5b09bd1ba85de0a999 100755 (executable)
@@ -23,22 +23,25 @@ def construct_parser():
                       help="device flowcell is being archived to")
     parser.add_option("-s", "--serial", action="store", type="string", dest="serial",
                       help="serial num. of archive device")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False)
     
     return parser
 
 
-def update_db(flowcell, serial):
+def update_db(flowcell, serial, debug=False):
     """
     Creates link between flowcell and storage device over http
     """
     www = urllib.urlopen(settings.LINK_FLOWCELL_STORAGE_DEVICE_URL+'%s/%s/' % (flowcell, serial))
     httpcode = www.getcode()
     if httpcode != 200:
-        print 'ERROR - HTTP OUTPUT:'
-        print www.read()
+        print 'ERROR - HTTP OUTPUT (Return Code: %s); use -v/--verbose for more details.' % (httpcode)
+        if debug:
+            print www.read()
         sys.exit(httpcode)
     
     print "DB Update of %s & %s succeeded" % (flowcell, serial)
+    print www.read()
 
 
 def process_args(parser):
@@ -55,9 +58,9 @@ def process_args(parser):
               "  The serial number is extracted automatically if the device is provided."
         sys.exit(2)
     
-    print options.flowcell
-    print options.device
-    print options.serial
+    print 'Flowcell:', options.flowcell
+    print '  Device:', options.device
+    print '  Serial:', options.serial
     
     if options.flowcell is None:
         msg.append("  --flowcell required")
@@ -73,9 +76,9 @@ def process_args(parser):
     # Update db records
     if options.device is not None:
         serial = get_hd_serial_num(options.device)
-        update_db(flowcell=options.flowcell, serial=serial)
+        update_db(flowcell=options.flowcell, serial=serial, debug=options.verbose)
     elif options.serial is not None:
-        update_db(flowcell=options.flowcell, serial=options.serial)
+        update_db(flowcell=options.flowcell, serial=options.serial, debug=options.verbose)
     else:
         msg ="FATAL should not happen error occured; i.e. the best kind!"
         raise ValueError, msg