ATLAS Offline Software
removeValsFromFile.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import uploadTools
4 
5 basepath="/afs/cern.ch/atlas/groups/Generators/CrossSectionInfo/ScriptsCentralPage/"
6 
7 def main():
8 
9  # parse options from command line
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)")
19 
20  parser.set_defaults(verbose=False,alwaysyes=False,infile=None,xsreffile=basepath+"InputInformation/CrossSectionReference",istest="TRUE",delim=';',explanation=None)
21 
22  (opts, args) = parser.parse_args()
23 
24  if not opts.explanation:
25  print "ERROR: No explanation found - Should be JIRA ticket or similar"
26  return
27  elif 'CENTRPAGE' not in opts.explanation:
28  print "WARNING: Explanation found, but does not include CENTRPAGE - this should usually be a JIRA ticket"
29 
30  if opts.istest=="FALSE":
31  opts.istest=False
32 
33  UT=uploadTools.UT(opts=opts)
34  cols=UT.colors
35 
36  if not opts.istest:
37  print cols.FAIL+"INFO: THIS IS NOT A TEST - UPLOADING FOR REALS!"+cols.ENDC
38  else:
39  print cols.OKGREEN+"INFO: THIS IS A TEST - Nothing will be uploaded!"+cols.ENDC
40 
41 
42 
43 
44  currentfile=UT.getCurrentVals(UT.getDSListFromFile(opts.infile))
45  UT.currentVals=UT.getDetailsFromFile(currentfile)
46  print UT.currentVals
47 
48  uploadVals=UT.getDetailsFromFile(opts.infile)
49  print uploadVals
50 
51  for ds in uploadVals:
52  if ds in UT.currentVals:
53  print cols.OKGREEN+"INFO: Working on datset %s"%(ds)+cols.ENDC
54  for param in uploadVals[ds]:
55  if param in UT.currentVals[ds]:
56  if len(uploadVals[ds][param].strip()) or uploadVals[ds][param].strip()=="#UNKNOWN#":
57  if uploadVals[ds][param]!=UT.currentVals[ds][param]:
58  print cols.WARNING+"INFO: Upload %s = %s (current val = %s)"%(param,uploadVals[ds][param],UT.currentVals[ds][param])+cols.ENDC
59  UT.uploadValue(ds,param,uploadVals[ds][param],opts.explanation,uploadVals[ds]["crossSectionRef"])
60  else:
61  print "INFO: Inputted %s value is identical to current DB value (%s) - ignoring"%(param,UT.currentVals[ds][param])
62  else:
63  print "INFO: %s value empty or unknown - ignoring"%(param)
64  else:
65  print "WARNING: Parameter %s not found in current AMI vals dictionary for %s"%(param,ds)
66  else:
67  print "WARNING: Parameter dataset %s not found in current AMI val dictionary"%(ds)
68 
69  #UT.updateXS("test","mc15","1234","Just a test")
70 
71 if __name__ == '__main__':
72  main()
73 
removeValsFromFile.main
def main()
Definition: removeValsFromFile.py:7
uploadTools.UT
Definition: uploadTools.py:10