4 #os.environ['DJANGO_SETTINGS_MODULE'] = 'htsworkflow.frontend.settings'
6 from htsworkflow.util.hdquery import get_hd_serial_num
7 from htsworkflow.frontend import settings
9 #from django.conf import settings
10 from optparse import OptionParser
16 def construct_parser():
19 parser = OptionParser("usage: %prog -f <flowcell> -d </dev/sdX> OR\n\t %prog -f <flowcell> -s <dev_serial_num>")
20 parser.add_option("-f", "--flowcell", action="store", type="string", dest="flowcell",
21 help="flowcell being archived")
22 parser.add_option("-d", "--device", action="store", type="string", dest="device",
23 help="device flowcell is being archived to")
24 parser.add_option("-s", "--serial", action="store", type="string", dest="serial",
25 help="serial num. of archive device")
26 parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False)
31 def update_db(flowcell, serial, debug=False):
33 Creates link between flowcell and storage device over http
35 www = urllib.urlopen(settings.LINK_FLOWCELL_STORAGE_DEVICE_URL+'%s/%s/' % (flowcell, serial))
36 httpcode = www.getcode()
38 print 'ERROR - HTTP OUTPUT (Return Code: %s); use -v/--verbose for more details.' % (httpcode)
43 print "DB Update of %s & %s succeeded" % (flowcell, serial)
47 def process_args(parser):
49 returns flowcell and serial#
51 options, args = parser.parse_args()
55 # Only provide device or serial
56 if options.device is not None and options.serial is not None:
57 print "ERROR: Please only provide --device or --serial.\n" \
58 " The serial number is extracted automatically if the device is provided."
61 print 'Flowcell:', options.flowcell
62 print ' Device:', options.device
63 print ' Serial:', options.serial
65 if options.flowcell is None:
66 msg.append(" --flowcell required")
68 # if device and serial missing:
69 if options.device is None and options.serial is None:
70 msg.append(" --device OR --serial required")
77 if options.device is not None:
78 serial = get_hd_serial_num(options.device)
79 update_db(flowcell=options.flowcell, serial=serial, debug=options.verbose)
80 elif options.serial is not None:
81 update_db(flowcell=options.flowcell, serial=options.serial, debug=options.verbose)
83 msg ="FATAL should not happen error occured; i.e. the best kind!"
91 parser = construct_parser()
94 #print "Database Updated."
97 if __name__ == '__main__':