10 from optparse
import OptionParser
11 parser = OptionParser(usage =
"usage: %prog arguments", version=
"%prog")
12 parser.add_option(
"-v",
"--verbose", action=
"store_true", dest=
"verbose", help=
"Set verbose mode (default: %default)")
13 parser.add_option(
"-y",
"--alwaysyes", action=
"store_true", dest=
"alwaysyes", help=
"Always answer yes to checks (default: %default)")
14 parser.add_option(
"-i",
"--infile", action=
"store", dest=
"infile", help=
"Input file (default: %default)")
15 parser.add_option(
"-x",
"--xsreffile", action=
"store", dest=
"xsreffile", help=
"Cross section reference file (default: %default)")
16 parser.add_option(
"-t",
"--istest", action=
"store", dest=
"istest", help=
"Is test (no actual upload to AMI) (default: %default)")
17 parser.add_option(
"-d",
"--delim", action=
"store", dest=
"delim", help=
"Delimiter for input file (default: %default)")
18 parser.add_option(
"-e",
"--explanation",action=
"store", dest=
"explanation",help=
"Comment for explanation field (default: %default)")
20 parser.set_defaults(verbose=
False,alwaysyes=
False,infile=
None,xsreffile=basepath+
"InputInformation/CrossSectionReference",istest=
"TRUE",delim=
';',explanation=
None)
22 (opts, args) = parser.parse_args()
24 if not opts.explanation:
25 print "ERROR: No explanation found - Should be JIRA ticket or similar"
27 elif 'CENTRPAGE' not in opts.explanation:
28 print "WARNING: Explanation found, but does not include CENTRPAGE - this should usually be a JIRA ticket"
30 if opts.istest==
"FALSE":
33 UT=
uploadTools.UT(istest=opts.istest,verbose=opts.verbose,alwaysyes=opts.alwaysyes,xsRefFile=opts.xsreffile
if hasattr(opts,
"xsreffile")
else None,delim=opts.delim
if hasattr(opts,
"delim")
else None)
38 print cols.FAIL+
"INFO: THIS IS NOT A TEST - UPLOADING FOR REALS!"+cols.ENDC
40 print cols.OKGREEN+
"INFO: THIS IS A TEST - Nothing will be uploaded!"+cols.ENDC
45 currentfile=UT.getCurrentVals(UT.getDSListFromFile(opts.infile),UT.getFieldsInFile(opts.infile))
46 UT.currentVals=UT.getDetailsFromFile(currentfile)
49 UT.newVals=uploadVals=UT.getDetailsFromFile(opts.infile)
53 if ds
in UT.currentVals:
54 print cols.OKGREEN+
"INFO: Working on datset %s"%(ds)+cols.ENDC
55 for param
in uploadVals[ds]:
56 if param
in UT.currentVals[ds]:
57 if len(uploadVals[ds][param].strip())
or uploadVals[ds][param].strip()==
"#UNKNOWN#":
58 newval=uploadVals[ds][param]
59 currentval=UT.currentVals[ds][param]
60 if param
in [
"genFiltEff",
"crossSection",
"kFactor"]
and "unknown" not in newval.lower()
and "unknown" not in currentval.lower():
61 newval=
float(uploadVals[ds][param])
62 currentval=
float(UT.currentVals[ds][param])
63 if newval!=currentval:
64 print cols.WARNING+
"INFO: Upload %s = %s (current val = %s)"%(param,uploadVals[ds][param],UT.currentVals[ds][param])+cols.ENDC
65 UT.updateValue(ds,param,uploadVals[ds][param],opts.explanation,uploadVals[ds][
"crossSectionRef"])
67 print "INFO: Inputted %s value is identical to current DB value (%s) - ignoring"%(param,UT.currentVals[ds][param])
69 print "INFO: %s value empty or unknown - ignoring"%(param)
71 print "WARNING: Parameter %s not found in current AMI vals dictionary for %s"%(param,ds)
73 print "WARNING: Parameter dataset %s not found in current AMI val dictionary"%(ds)