14 from __future__
import print_function
27 param amiconf: name of file with AMI user and pw
29 If a valid filename is specified, it tries to read the
30 username and password from there. If that does not succeed or
31 no filename is specified, voms based authentication is tried.
33 from pyAMI.pyAMI
import AMI,pyAMIEndPoint
34 from os
import stat,path
38 if not path.exists(amiconf):
40 print (
"WARNING: AMI config file", amiconf,
"does not exist. Need to rely on valid voms proxy.")
41 elif stat(amiconf).st_mode & path.stat.S_IRUSR == 0:
43 print (
"WARNING: AMI config file", amiconf,
"exists but is not readable. Need to rely on valid voms proxy.")
48 pyAMIEndPoint.setType(
"replica")
50 ami.readConfig(amiconf)
52 print (
"... connecting to CERN AMI replica with user+pw")
54 pyAMIEndPoint.setType(
"main")
57 print (
"... connecting to AMI main server with user+pw")
60 print (
"WARNING: Authentication in config file",amiconf,
"not valid, check format, user, pw. Need to rely on valid voms proxy.")
63 pyAMIEndPoint.setType(
"replica")
66 print (
"... connecting to CERN replica using voms-proxy")
70 pyAMIEndPoint.setType(
"main")
73 print (
"... connecting to main server using voms-proxy")
78 print (
"WARNING voms-proxy authentication not valid. No access to AMI.")
86 from CoolRunQuery.utils.AtlRunQueryUtils
import runsOnServer
88 home =
"/data/atrqadm/data/"
93 conffilename = home +
"/private/AMIConf.txt"
96 print (
"ERROR: voms-proxy authentication not valid and no AMI configuration file",conffilename,
"supplied. No access to AMI!")
103 from pyAMI.pyAMI
import AMI
105 amiclient.readConfig(
"./AMIConf.txt")
108 print (
'ERROR: could not load pyAMI')
116 return result.getDict()
117 except Exception
as ex:
118 print (
"AMI exception '",
type(ex),
"' occured")
120 traceback.print_exc()
130 if run
not in cls.
store:
132 print (
'GetDataPeriodsForRun',
'-runNumber=%i' % run)
134 result = cls.
amiexec([
'GetDataPeriodsForRun',
'-runNumber=%i' % run])
136 cls.
store[run] =
sorted([ (
int(e[
'periodLevel']),e[
'period'],e[
'project'])
for e
in result[
'Element_Info'].
values() ])
140 return [x[1]
for x
in cls.
store[run]]
146 cmd = [
'ListDataPeriods',
'-createdSince=2009-01-01 00:00:00' ]
148 cmd += [
'-projectName=data%02i%%' % (year-2000) ]
150 cmd += [
'-periodLevel=%i' % level ]
154 rows = [ (e[
'period'], e[
'projectName'])
for e
in result[
'Element_Info'].
values() ]
167 p = re.compile(
r"(?P<period>(?P<periodletter>[A-Za-z]+)(?P<periodnumber>\d+)?)$")
170 for period, projectName
in result:
174 year =
int(projectName[4:6])
175 period_letter = m.group(
'periodletter')
176 period_number =
int(m.group(
'periodnumber'))
if m.group(
'periodnumber')
else 0
177 if len(period_letter)!=1:
180 pc = 10000*year + 100*(ord(period_letter.upper())-65) + period_number
181 cls.
all_periods += [ ((year, period, pc), projectName+
".period" + period) ]
185 traceback.print_exc()
193 cmd = [
'GetRunsForDataPeriod',
'-period=%s' % period]
195 cmd += [
'-projectName=data%02i%%' % (year-2000) ]
200 r =
sorted([
int(e[
'runNumber'])
for e
in result[
'Element_Info'].
values() ])
202 except (ValueError, KeyError):
208 if __name__ ==
"__main__":
212 print (
"\n1 - periods for run")
213 print (
"2 - runs for period (and year)")
214 print (
"3 - periods (by year and/or level)")
215 print (
"4 - all periods (different format)")
216 print (
"5 - test AMI authentication")
217 print (
"\n0 - exit\n")
219 choice =
input(
" enter your choice: ")
220 choice =
int(choice)
if choice.isdigit()
else 0
223 print (ARQ_AMI.get_periods_for_run( [run] ))
226 year =
input(
" year <RET> = all : ")
227 year =
int(year)
if year.isdigit()
else 0
228 print (
', '.
join([
str(x)
for x
in ARQ_AMI.get_runs(period, year)]))
230 year =
input(
" year <RET> = all : ")
231 year =
int(year)
if year.isdigit()
else 0
232 period =
input(
" period [1|2|3] <RET> = all : ")
233 period =
int(period)
if period.isdigit()
else 0
234 print (ARQ_AMI.get_periods(year, period))
236 print (ARQ_AMI.get_all_periods())
238 ami = ARQ_AMI.amiclient()
240 print (
"Successfully connected to AMI")
242 print (
"Failed to connect to AMI")