From 0f30cae8de932f681169b485870d9b7eabf04c0d Mon Sep 17 00:00:00 2001 From: Brandon King Date: Wed, 10 Jun 2009 20:13:13 +0000 Subject: [PATCH] Improved debugging output. * 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 | 50 ++++++++++++++++++++----- scripts/mark_archived_data | 19 ++++++---- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/htsworkflow/frontend/inventory/views.py b/htsworkflow/frontend/inventory/views.py index aa10696..19bcb0b 100644 --- a/htsworkflow/frontend/inventory/views.py +++ b/htsworkflow/frontend/inventory/views.py @@ -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 diff --git a/scripts/mark_archived_data b/scripts/mark_archived_data index 80c6792..bd83b3b 100755 --- a/scripts/mark_archived_data +++ b/scripts/mark_archived_data @@ -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 -- 2.30.2