26 param amiconf: name of file with AMI user and pw
28 If a valid filename is specified, it tries to read the
29 username and password from there. If that does not succeed or
30 no filename is specified, voms based authentication is tried.
32 from pyAMI.pyAMI
import AMI,pyAMIEndPoint
33 from os
import stat,path
37 if not path.exists(amiconf):
39 print (
"WARNING: AMI config file", amiconf,
"does not exist. Need to rely on valid voms proxy.")
40 elif stat(amiconf).st_mode & path.stat.S_IRUSR == 0:
42 print (
"WARNING: AMI config file", amiconf,
"exists but is not readable. Need to rely on valid voms proxy.")
47 pyAMIEndPoint.setType(
"replica")
49 ami.readConfig(amiconf)
51 print (
"... connecting to CERN AMI replica with user+pw")
53 pyAMIEndPoint.setType(
"main")
56 print (
"... connecting to AMI main server with user+pw")
59 print (
"WARNING: Authentication in config file",amiconf,
"not valid, check format, user, pw. Need to rely on valid voms proxy.")
62 pyAMIEndPoint.setType(
"replica")
65 print (
"... connecting to CERN replica using voms-proxy")
69 pyAMIEndPoint.setType(
"main")
72 print (
"... connecting to main server using voms-proxy")
77 print (
"WARNING voms-proxy authentication not valid. No access to AMI.")
85 from CoolRunQuery.utils.AtlRunQueryUtils
import runsOnServer
87 home =
"/data/atrqadm/data/"
92 conffilename = home +
"/private/AMIConf.txt"
95 print (
"ERROR: voms-proxy authentication not valid and no AMI configuration file",conffilename,
"supplied. No access to AMI!")
102 from pyAMI.pyAMI
import AMI
104 amiclient.readConfig(
"./AMIConf.txt")
107 print (
'ERROR: could not load pyAMI')
115 return result.getDict()
116 except Exception
as ex:
117 print (
"AMI exception '",
type(ex),
"' occured")
119 traceback.print_exc()
129 if run
not in cls.
store:
131 print (
'GetDataPeriodsForRun',
'-runNumber=%i' % run)
133 result = cls.
amiexec([
'GetDataPeriodsForRun',
'-runNumber=%i' % run])
135 cls.
store[run] =
sorted([ (
int(e[
'periodLevel']),e[
'period'],e[
'project'])
for e
in result[
'Element_Info'].
values() ])
139 return [x[1]
for x
in cls.
store[run]]
145 cmd = [
'ListDataPeriods',
'-createdSince=2009-01-01 00:00:00' ]
147 cmd += [
'-projectName=data%02i%%' % (year-2000) ]
149 cmd += [
'-periodLevel=%i' % level ]
153 rows = [ (e[
'period'], e[
'projectName'])
for e
in result[
'Element_Info'].
values() ]
166 p = re.compile(
r"(?P<period>(?P<periodletter>[A-Za-z]+)(?P<periodnumber>\d+)?)$")
169 for period, projectName
in result:
173 year =
int(projectName[4:6])
174 period_letter = m.group(
'periodletter')
175 period_number =
int(m.group(
'periodnumber'))
if m.group(
'periodnumber')
else 0
176 if len(period_letter)!=1:
179 pc = 10000*year + 100*(ord(period_letter.upper())-65) + period_number
180 cls.
all_periods += [ ((year, period, pc), projectName+
".period" + period) ]
184 traceback.print_exc()
192 cmd = [
'GetRunsForDataPeriod',
'-period=%s' % period]
194 cmd += [
'-projectName=data%02i%%' % (year-2000) ]
199 r =
sorted([
int(e[
'runNumber'])
for e
in result[
'Element_Info'].
values() ])
201 except (ValueError, KeyError):
207 if __name__ ==
"__main__":
211 print (
"\n1 - periods for run")
212 print (
"2 - runs for period (and year)")
213 print (
"3 - periods (by year and/or level)")
214 print (
"4 - all periods (different format)")
215 print (
"5 - test AMI authentication")
216 print (
"\n0 - exit\n")
218 choice = input(
" enter your choice: ")
219 choice =
int(choice)
if choice.isdigit()
else 0
221 run =
int(input(
" run number: "))
222 print (ARQ_AMI.get_periods_for_run( [run] ))
224 period = input(
" period : ")
225 year = input(
" year <RET> = all : ")
226 year =
int(year)
if year.isdigit()
else 0
227 print (
', '.
join([
str(x)
for x
in ARQ_AMI.get_runs(period, year)]))
229 year = input(
" year <RET> = all : ")
230 year =
int(year)
if year.isdigit()
else 0
231 period = input(
" period [1|2|3] <RET> = all : ")
232 period =
int(period)
if period.isdigit()
else 0
233 print (ARQ_AMI.get_periods(year, period))
235 print (ARQ_AMI.get_all_periods())
237 ami = ARQ_AMI.amiclient()
239 print (
"Successfully connected to AMI")
241 print (
"Failed to connect to AMI")