16 from __future__
import print_function
25 amicommand = [
'SearchQuery',
'''-sql="SELECT V_AMITags.tagType, V_AMITags.tagNumber FROM V_AMITags WHERE V_AMITags.tagType = 'h' ORDER BY V_AMITags.tagNumber DESC"'''
26 '-project="AMITags"',
'-processingStep=production']
30 result = amiclient.execute(amicommand, format=
'dict_object')
31 resultlist = result.get_rows(
'Element_Info')
32 latestTag =
'h' + resultlist[0][
'tagNumber']
38 nextTag = latestTag[0] +
str(
int(latestTag[1:])+1)
40 print (
'Latest AMI tag is', latestTag)
41 print (
'Will create AMI tag', nextTag)
44 amicommand = [
'AMIGetAMITagInfo',
'-amiTag='+latestTag]
46 result = amiclient.execute(amicommand, format=
'dict_object')
51 rv = result.get_rows(
'amiTagInfo')[0]
54 print (
'-------------------------------------')
55 print (
'Info of current AMI tag ...')
56 for key, val
in rv.items():
57 print (
' %s:' % key, val)
59 for k, v
in rv.items():
64 for k
in (
'tag',
'createdBy',
'modifiedBy',
'tagStatus',
'tagNumber',
'tagType',
65 'locked',
'updates',
'created',
'lastModified',
'processingStep',
66 'transformationName',
'baseRelease',
'modified',
'phconfig'):
71 for k
in (
'inputs',
'outputs',
'moreInfo',
'trfsetupcmd',
73 rv1[k] =
'"%s"' %
str(rv1[k].__str__())
79 nextTag = latestTag[0] +
str(
int(latestTag[1:])+1)
86 basedir = os.path.abspath(indir)
88 print (
'Looking for configurations in subdirectories of', indir)
90 types = [
'minutes10',
'minutes30',
'run']
91 searchparams = [(
'Cosmics',
'cosmics'), (
'Collisions',
'collisions'),
92 (
'HeavyIons',
'heavyions')]
97 for dir1, fn
in searchparams:
99 filepathdict[dir1] = {}
101 print (
' ', t,
'...',)
102 fname = os.path.join(basedir, dir1,
103 '%s_%s.current.hcfg' % (fn, t))
104 if os.access(fname, os.R_OK):
106 if os.path.islink(fname)
and os.path.isfile(fname):
107 realname = os.readlink(fname)
108 if not os.path.isabs(realname):
109 realname = os.path.join(os.path.dirname(fname), realname)
110 print (
'is symlink to', realname)
111 filepathdict[dir1][t] = realname
112 filelist.append(realname)
114 print (
'but is not valid symlink')
117 if filepathdict[dir1] == {}:
118 del filepathdict[dir1]
120 commonpart = os.path.dirname(os.path.commonprefix(filelist)) + os.sep
122 filepathdict[
'basename'] = commonpart
125 for dir1, fn
in searchparams:
128 filepathdict[dir1][t] = filepathdict[dir1][t].
replace(commonpart,
'')
133 print (
'-------------------------------------')
134 print (
'File path dictionary to upload:')
136 print (
'-------------------------------------')
139 val = updict.get(
'phconfig', {})
140 if isinstance(val, str):
142 val[
'filepaths'] = filepathdict
143 updict[
'phconfig'] =
'"%s"' % val
148 basedir = os.path.abspath(indir)
150 print (
'Looking for configurations in subdirectories of', indir)
152 types = [
'minutes10',
'run']
153 searchparams = [(
'Cosmics',
'cosmics'), (
'Collisions',
'collisions'),
154 (
'HeavyIons',
'heavyions')]
159 for dir1, fn
in searchparams:
161 filepathdict[dir1] = {}
163 print (
' ', t,
'...',)
164 fname = os.path.join(basedir,
'%s_%s.hcfg' % (fn, t))
165 if os.access(fname, os.R_OK):
166 print (
'found %s' % (dir1))
167 if os.path.isfile(fname):
168 filepathdict[dir1][t] = fname
169 filelist.append(fname)
172 if filepathdict[dir1] == {}:
173 del filepathdict[dir1]
175 commonpart = os.path.dirname(os.path.commonprefix(filelist)) + os.sep
177 filepathdict[
'basename'] = commonpart
180 for dir1, fn
in searchparams:
183 filepathdict[dir1][t] = filepathdict[dir1][t].
replace(commonpart,
'')
188 print (
'-------------------------------------')
189 print (
'File path dictionary to upload:')
191 print (
'-------------------------------------')
194 val = updict.get(
'phconfig', {})
195 if isinstance(val, str):
197 val[
'filepaths'] = filepathdict
198 updict[
'phconfig'] =
'"%s"' % val
203 relSp=release.split(
"-")
205 s=
"ERROR: Expected parameter 'release' in the form Project-number, got "+release
206 raise RuntimeError(s)
209 relNbr, _=relSp[1].
split(
',', 1)
211 relNbr, _=relSp[1],
None
213 baseRelNbr=
".".
join(relNbr.split(
".")[:2])
214 relPath =
"/cvmfs/atlas.cern.ch/repo/sw/software/%s/%s/%s" % (baseRelNbr, relProj, relNbr)
215 if not os.path.isdir(relPath):
216 s=
"ERROR Release directory " + relPath +
" does not exist"
217 raise RuntimeError(s)
220 extraSetup =
" oracleCOOL"
221 if relProj ==
"AtlasProduction":
222 extraSetup +=
" AtlasProduction"
223 elif relProj ==
"Athena":
224 extraSetup +=
" Athena"
225 elif relProj ==
"AthDataQuality":
226 extraSetup +=
" AthDataQuality"
227 elif relProj !=
"AtlasOffline":
228 s=
"ERROR: The project specified (" + relProj +
") is not Athena, AtlasOffline or AtlasProduction. Are you sure?"
229 raise RuntimeError(s)
232 tasktransinfo = {
'trfpath':
'DQM_Tier0Wrapper_tf.py',
233 'trfsetupcmd':
"/afs/cern.ch/atlas/tzero/software/setup/usetuptrf.sh " + relNbr + extraSetup}
234 updict[
'moreInfo'] =
'"{\'tasktransinfo\': %s}"' % tasktransinfo.__str__()
235 updict[
'SWReleaseCache'] = release.replace(
'-',
'_')
236 updict[
'groupName'] = relProj
237 updict[
'cacheName'] = relSp[1]
238 updict[
'description'] =
"'Trf for combined DQM histogram merging and DQM webpage creation, to get periodic DQ monitoring updates. Using " + release +
"'"
239 updict[
'trfsetupcmd'] =
'"%s"' % tasktransinfo[
'trfsetupcmd']
245 amicommand = [
'AddAMITag',
'tagType="h"', ]
247 for key, val
in updict.items():
248 amicommand.append(
'%s=%s' % (key, val))
250 print (
'-------------------------------------')
252 print (
'Now uploading new AMI tag')
253 print (
'AMI command:', amicommand)
255 result = amiclient.execute(amicommand)
260 if __name__ ==
'__main__':
263 parser = optparse.OptionParser(usage=
'Usage: %prog [options] cmd arg\n'
265 ' configs: update only DQ configurations; args should be the config base directory\n'
266 ' release: update only the release; args should be the new release'
269 parser.set_defaults(certificate=
False)
270 parser.add_option(
'-u',
'--user', dest=
'amiuser', help=
'Set AMI user; should set password at the same time.')
271 parser.add_option(
'-p',
'--password', dest=
'amipass', help=
'Set AMI password; should set user at the same time.')
272 parser.add_option(
'-c',
'--certificate', dest=
'certificate',
274 help=
'Use grid certificate/VOMS proxy.')
276 options, args = parser.parse_args()
279 parser.error(
'Must provide type of operation and argument!')
281 if args[0].lower()
not in (
'configs',
'release'):
282 parser.error(
'cmd must be "configs" or "release"')
301 import pyAMI.atlas.api
as AtlasAPI
302 amiclient = pyAMI.client.Client(
'atlas')
308 if args[0].lower() ==
'configs':
309 if '/afs/cern.ch/user/a/atlasdqm/' in str(args[1]):
311 elif 'cvmfs' in str(args[1]):
314 s=
"Invalid directory given. hcfg files should exist in cvmfs or the atlasdqm afs space"
315 raise RuntimeError(s)
316 elif args[0].lower() ==
'release':