From: Diane Trout Date: Sat, 30 Jan 2010 01:28:52 +0000 (+0000) Subject: Update the inventory tracker code for the split from lanes being X-Git-Tag: 0.4.0~14 X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=htsworkflow.git;a=commitdiff_plain;h=3ae6aea930b577c29c84a0c26029be24bef9a698 Update the inventory tracker code for the split from lanes being in the flowcell table to their own stand-alone model. Also I made the mark_archived_data script take a list of runfolder archives so I can archive a whole hard disk in one go. --- diff --git a/htsworkflow/frontend/inventory/views.py b/htsworkflow/frontend/inventory/views.py index f1d4607..7ff5b40 100644 --- a/htsworkflow/frontend/inventory/views.py +++ b/htsworkflow/frontend/inventory/views.py @@ -48,7 +48,7 @@ def __expand_longtermstorage_context(context, item): for lts in item.longtermstorage_set.all(): flowcell_list.append(lts.flowcell) flowcell_id_list.append(lts.flowcell.flowcell_id) - library_id_list.extend([ lib.library_id for lib in lts.libraries.all() ]) + library_id_list.extend([ lib.id for lib in lts.libraries.all() ]) flowcell_list.sort(__flowcell_rundate_sort) context['oldest_rundate'] = flowcell_list[0].run_date @@ -295,47 +295,11 @@ def link_flowcell_and_device(request, flowcell, serial): ########################################### # Add Library Links to LTS - - 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.libraries.all(): - lts.libraries.add(fc.lane_2_library) - LIBRARY_UPDATED = True - #print 2 - - 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.libraries.all(): - lts.libraries.add(fc.lane_4_library) - LIBRARY_UPDATED = True - #print 4 - - - 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.libraries.all(): - lts.libraries.add(fc.lane_6_library) - LIBRARY_UPDATED = True - #print 6 - - 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.libraries.all(): - lts.libraries.add(fc.lane_8_library) - LIBRARY_UPDATED = True - #print 8 + + for lane in fc.lane_set.all(): + if lane.library not in lts.libraries.all(): + lts.libraries.add(lane.library) + LIBRARY_UPDATED = True # Save Changes lts.save() @@ -348,4 +312,4 @@ def link_flowcell_and_device(request, flowcell, serial): else: msg.append(' No Updates Needed.') - return HttpResponse('\n'.join(msg)) \ No newline at end of file + return HttpResponse('\n'.join(msg)) diff --git a/scripts/mark_archived_data b/scripts/mark_archived_data index eadafb6..6d72ab2 100755 --- a/scripts/mark_archived_data +++ b/scripts/mark_archived_data @@ -1,39 +1,46 @@ #!/usr/bin/env python -#import os -#os.environ['DJANGO_SETTINGS_MODULE'] = 'htsworkflow.frontend.settings' - from htsworkflow.util.hdquery import get_hd_serial_num from htsworkflow.frontend import settings -#from django.conf import settings from optparse import OptionParser - +import os +import re import sys import urllib2 +import urlparse +runfolder_pattern = re.compile(r'[0-9]{6}_[-A-Za-z\d]+_\d+_(?P[A-Z\d]+)\.tgz') - +def extract_flowcell(runfolder_name): + path, basename = os.path.split(runfolder_name) + match = runfolder_pattern.match(basename) + if match is not None: + return match.group('flowcell') + else: + return None + def construct_parser(): """ """ - parser = OptionParser("usage: %prog -f -d OR\n\t %prog -f -s ") - parser.add_option("-f", "--flowcell", action="store", type="string", dest="flowcell", - help="flowcell being archived") - parser.add_option("-d", "--device", action="store", type="string", dest="device", + msg = "usage: %prog [-d | -s ] [archived dirs]" + parser = OptionParser() + parser.add_option('-u', '--url', default=None, + help="Alternate url for marking archived flowcells") + parser.add_option("-f", "--flowcell", type="string", help="flowcell being archived") + parser.add_option("-d", "--device", type="string", 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) + 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 -def update_db(flowcell, serial, debug=False): +def update_db(root_url, flowcell, serial, debug=False): """ Creates link between flowcell and storage device over http """ - url = settings.LINK_FLOWCELL_STORAGE_DEVICE_URL+'%s/%s/' % (flowcell, serial) + url = urlparse.urljoin(root_url, '%s/%s/' % (flowcell, serial)) req = urllib2.Request(url) try: @@ -58,31 +65,47 @@ def process_args(parser): # Only provide device or serial if options.device is not None and options.serial is not None: - print "ERROR: Please only provide --device or --serial.\n" \ - " The serial number is extracted automatically if the device is provided." - sys.exit(2) - - print 'Flowcell:', options.flowcell - print ' Device:', options.device - print ' Serial:', options.serial - - if options.flowcell is None: - msg.append(" --flowcell required") - + parser.error("Please provide only --device or --serial.\n"\ + "The serial number is extracted automatically if the"\ + "device is provided.") + + # allow user to override the default destination URL + if options.url is not None: + root_url = options.url + else: + root_url = settings.LINK_FLOWCELL_STORAGE_DEVICE_URL + # if device and serial missing: if options.device is None and options.serial is None: - msg.append(" --device OR --serial required") + parser.error('One of --device or --serial is required') + + flowcells = [] - if len(msg) > 0: - print '\n'.join(msg) - sys.exit(3) + # sanitize args + for runfolder in args: + flowcell_id = extract_flowcell(runfolder) + if flowcell_id is None: + parser.error('archive names must look like YYMMDD_MACHINE_RUN_FLOWCELLID.tgz\n'\ + '(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.') + + print flowcells + sys.exit(1) # Update db records if options.device is not None: serial = get_hd_serial_num(options.device) - update_db(flowcell=options.flowcell, serial=serial, debug=options.verbose) + update_db(root_url, flowcells, serial=serial, debug=options.verbose) elif options.serial is not None: - update_db(flowcell=options.flowcell, serial=options.serial, debug=options.verbose) + update_db(root_url, flowcells, serial=options.serial, debug=options.verbose) else: msg ="FATAL should not happen error occured; i.e. the best kind!" raise ValueError, msg @@ -99,4 +122,4 @@ def main(): sys.exit(0) if __name__ == '__main__': - main() \ No newline at end of file + main()