5 from __future__
import print_function
8 Generate run list for each period using the pyAMI interface to the COMA db.
10 Need to authenticate (once) and setup pyami via:
12 source /afs/cern.ch/atlas/software/tools/atlasmeta/setup.sh
13 export PYAMI_CONFIG_DIR=~/private/.pyami
17 __author__ =
'Carl Gwilliam'
19 __usage__ =
'''%prog [options]'''
25 from optparse
import OptionParser
26 parser = OptionParser(usage=__usage__, version=__version__)
27 parser.add_option(
'-c',
'--config', dest=
'config', default=
'', help=
'AMI authentication file')
28 (options,args) = parser.parse_args()
33 self.
ami=pyAMI.client.Client(
'atlas')
42 sys.exit(
'No authentication file specified')
48 Execute an AMI command given as a list of command and paramters (ami format) or
49 space separated string (for convenience)
51 if isinstance(cmd, str):
54 print (
'PRINT AMI CMD', cmd )
55 results = self.
ami.
execute(cmd,format=
'dict_object')
57 return results.get_rows()
59 def periods(self, period=None, level=None, project=None, status=None):
60 "Get list of periods. By default return all periods"
62 cmd =
'ListDataPeriods'
63 if period: cmd +=
' period='+period
64 if level: cmd +=
' periodLevel='+level
65 if project: cmd +=
' projectName='+project
66 if status: cmd +=
' status='+status
70 "Get info on runs for a particular period"
72 cmd =
'GetRunsForDataPeriod period='+period
73 cmd +=
' projectName='+project
79 Generate files containing run lists for periods if they don't already exist
89 projectDir =path.normpath(location +
'/' + p[
'projectName'])
91 if not path.exists(projectDir):
92 os.makedirs(projectDir)
94 filename =
'%s/%s.runs.list' % (projectDir,p[
'period'])
99 if path.exists(filename):
100 os.system(
'rm ' + filename)
102 print (
'* Creating run list for %(projectName)s %(period)s ...' % p)
111 runList =
'\n'.
join(
sorted([r[
'runNumber']
for r
in runs]))
114 with open(filename,
'w')
as f:
117 print (
' ... written to', filename,
'\n' )
120 print (
'* No new period infomation to create')
122 if __name__ ==
'__main__':
124 ami.runListsPerPeriod()