4 #os.environ['DJANGO_SETTINGS_MODULE'] = 'htsworkflow.frontend.settings'
6 from htsworkflow.util.hdquery import get_hd_serial_num
8 #from django.conf import settings
9 from optparse import OptionParser
14 #FIXME: Remove hard coded URL
15 HTSW_URL = "http://localhost:8000/inventory/lts/link/"
17 def construct_parser():
20 parser = OptionParser("usage: %prog -f <flowcell> -d </dev/sdX> OR\n\t %prog -f <flowcell> -s <dev_serial_num>")
21 parser.add_option("-f", "--flowcell", action="store", type="string", dest="flowcell",
22 help="flowcell being archived")
23 parser.add_option("-d", "--device", action="store", type="string", dest="device",
24 help="device flowcell is being archived to")
25 parser.add_option("-s", "--serial", action="store", type="string", dest="serial",
26 help="serial num. of archive device")
31 def update_db(flowcell, serial):
33 Creates link between flowcell and storage device over http
35 www = urllib.urlopen(HTSW_URL+'%s/%s/' % (flowcell, serial))
36 httpcode = www.getcode()
38 print 'ERROR - HTTP OUTPUT:'
42 print "DB Update of %s & %s succeeded" % (flowcell, serial)
45 def process_args(parser):
47 returns flowcell and serial#
49 options, args = parser.parse_args()
53 # Only provide device or serial
54 if options.device is not None and options.serial is not None:
55 print "ERROR: Please only provide --device or --serial.\n" \
56 " The serial number is extracted automatically if the device is provided."
59 print options.flowcell
63 if options.flowcell is None:
64 msg.append(" --flowcell required")
66 # if device and serial missing:
67 if options.device is None and options.serial is None:
68 msg.append(" --device OR --serial required")
75 if options.device is not None:
76 serial = get_hd_serial_num(options.device)
77 update_db(flowcell=options.flowcell, serial=serial)
78 elif options.serial is not None:
79 update_db(flowcell=options.flowcell, serial=options.serial)
81 msg ="FATAL should not happen error occured; i.e. the best kind!"
89 parser = construct_parser()
92 #print "Database Updated."
95 if __name__ == '__main__':