7 Generate run list for each period using the pyAMI interface to the COMA db.
9 Need to authenticate (once) and setup pyami via:
11 source /afs/cern.ch/atlas/software/tools/atlasmeta/setup.sh
12 export PYAMI_CONFIG_DIR=~/private/.pyami
16 __author__ =
'Carl Gwilliam'
18 __usage__ =
'''%prog [options]'''
24 from optparse
import OptionParser
25 parser = OptionParser(usage=__usage__, version=__version__)
26 parser.add_option(
'-c',
'--config', dest=
'config', default=
'', help=
'AMI authentication file')
27 (options,args) = parser.parse_args()
32 self.
ami=pyAMI.client.Client(
'atlas')
41 sys.exit(
'No authentication file specified')
47 Execute an AMI command given as a list of command and paramters (ami format) or
48 space separated string (for convenience)
50 if isinstance(cmd, str):
53 print (
'PRINT AMI CMD', cmd )
54 results = self.
ami.
execute(cmd,format=
'dict_object')
56 return results.get_rows()
58 def periods(self, period=None, level=None, project=None, status=None):
59 "Get list of periods. By default return all periods"
61 cmd =
'ListDataPeriods'
62 if period: cmd +=
' period='+period
63 if level: cmd +=
' periodLevel='+level
64 if project: cmd +=
' projectName='+project
65 if status: cmd +=
' status='+status
69 "Get info on runs for a particular period"
71 cmd =
'GetRunsForDataPeriod period='+period
72 cmd +=
' projectName='+project
78 Generate files containing run lists for periods if they don't already exist
88 projectDir =path.normpath(location +
'/' + p[
'projectName'])
90 if not path.exists(projectDir):
91 os.makedirs(projectDir)
93 filename =
'%s/%s.runs.list' % (projectDir,p[
'period'])
98 if path.exists(filename):
99 os.system(
'rm ' + filename)
101 print (
'* Creating run list for %(projectName)s %(period)s ...' % p)
110 runList =
'\n'.
join(
sorted([r[
'runNumber']
for r
in runs]))
113 with open(filename,
'w')
as f:
116 print (
' ... written to', filename,
'\n' )
119 print (
'* No new period infomation to create')
121 if __name__ ==
'__main__':
123 ami.runListsPerPeriod()