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
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")
27 parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False)
32 def update_db(flowcell, serial, debug=False):
34 Creates link between flowcell and storage device over http
36 url = settings.LINK_FLOWCELL_STORAGE_DEVICE_URL+'%s/%s/' % (flowcell, serial)
38 req = urllib2.Request(url)
40 response = urllib2.urlopen(req)
41 except urllib2.URLError, e:
42 print 'ERROR - HTTP OUTPUT (Return Code: %s); use -v/--verbose for more details.' % (e.code)
47 print "DB Update of %s & %s succeeded" % (flowcell, serial)
51 def process_args(parser):
53 returns flowcell and serial#
55 options, args = parser.parse_args()
59 # Only provide device or serial
60 if options.device is not None and options.serial is not None:
61 print "ERROR: Please only provide --device or --serial.\n" \
62 " The serial number is extracted automatically if the device is provided."
65 print 'Flowcell:', options.flowcell
66 print ' Device:', options.device
67 print ' Serial:', options.serial
69 if options.flowcell is None:
70 msg.append(" --flowcell required")
72 # if device and serial missing:
73 if options.device is None and options.serial is None:
74 msg.append(" --device OR --serial required")
81 if options.device is not None:
82 serial = get_hd_serial_num(options.device)
83 update_db(flowcell=options.flowcell, serial=serial, debug=options.verbose)
84 elif options.serial is not None:
85 update_db(flowcell=options.flowcell, serial=options.serial, debug=options.verbose)
87 msg ="FATAL should not happen error occured; i.e. the best kind!"
95 parser = construct_parser()
98 #print "Database Updated."
101 if __name__ == '__main__':