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
18 def construct_parser():
21 parser = OptionParser("usage: %prog -f <flowcell> -d </dev/sdX> OR\n\t %prog -f <flowcell> -s <dev_serial_num>")
22 parser.add_option("-f", "--flowcell", action="store", type="string", dest="flowcell",
23 help="flowcell being archived")
24 parser.add_option("-d", "--device", action="store", type="string", dest="device",
25 help="device flowcell is being archived to")
26 parser.add_option("-s", "--serial", action="store", type="string", dest="serial",
27 help="serial num. of archive device")
28 parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False)
33 def update_db(flowcell, serial, debug=False):
35 Creates link between flowcell and storage device over http
37 url = settings.LINK_FLOWCELL_STORAGE_DEVICE_URL+'%s/%s/' % (flowcell, serial)
39 req = urllib2.Request(url)
41 response = urllib2.urlopen(req)
42 except urllib2.URLError, e:
43 print 'ERROR - HTTP OUTPUT (Return Code: %s); use -v/--verbose for more details.' % (e.code)
48 print "DB Update of %s & %s succeeded" % (flowcell, serial)
52 def process_args(parser):
54 returns flowcell and serial#
56 options, args = parser.parse_args()
60 # Only provide device or serial
61 if options.device is not None and options.serial is not None:
62 print "ERROR: Please only provide --device or --serial.\n" \
63 " The serial number is extracted automatically if the device is provided."
66 print 'Flowcell:', options.flowcell
67 print ' Device:', options.device
68 print ' Serial:', options.serial
70 if options.flowcell is None:
71 msg.append(" --flowcell required")
73 # if device and serial missing:
74 if options.device is None and options.serial is None:
75 msg.append(" --device OR --serial required")
82 if options.device is not None:
83 serial = get_hd_serial_num(options.device)
84 update_db(flowcell=options.flowcell, serial=serial, debug=options.verbose)
85 elif options.serial is not None:
86 update_db(flowcell=options.flowcell, serial=options.serial, debug=options.verbose)
88 msg ="FATAL should not happen error occured; i.e. the best kind!"
96 parser = construct_parser()
99 #print "Database Updated."
102 if __name__ == '__main__':