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")
30 def update_db(flowcell, serial):
32 Creates link between flowcell and storage device over http
34 www = urllib.urlopen(settings.LINK_FLOWCELL_STORAGE_DEVICE_URL+'%s/%s/' % (flowcell, serial))
35 httpcode = www.getcode()
37 print 'ERROR - HTTP OUTPUT:'
41 print "DB Update of %s & %s succeeded" % (flowcell, serial)
44 def process_args(parser):
46 returns flowcell and serial#
48 options, args = parser.parse_args()
52 # Only provide device or serial
53 if options.device is not None and options.serial is not None:
54 print "ERROR: Please only provide --device or --serial.\n" \
55 " The serial number is extracted automatically if the device is provided."
58 print options.flowcell
62 if options.flowcell is None:
63 msg.append(" --flowcell required")
65 # if device and serial missing:
66 if options.device is None and options.serial is None:
67 msg.append(" --device OR --serial required")
74 if options.device is not None:
75 serial = get_hd_serial_num(options.device)
76 update_db(flowcell=options.flowcell, serial=serial)
77 elif options.serial is not None:
78 update_db(flowcell=options.flowcell, serial=options.serial)
80 msg ="FATAL should not happen error occured; i.e. the best kind!"
88 parser = construct_parser()
91 #print "Database Updated."
94 if __name__ == '__main__':