forked from cms-sw/cms-sw.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process-step-commands
executable file
·83 lines (77 loc) · 2.62 KB
/
process-step-commands
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
# Process job reports and create summary file with performance information.
from argparse import ArgumentParser
from os.path import exists, join
from os import fdopen, unlink, makedirs
from xml.sax import parseString, ContentHandler
import re
from hashlib import sha1
from json import dump, dumps
from tempfile import mkstemp
from shutil import move
from cmsutils import getRelValsFiles, readRelValFile
# Schema of the output
#
# {
# "<hash>": ["<command>", "<type>"]
# }
#
# <command> is the shell command used.
# <type> is the type of the command, either CMSDRIVER or DAS.
# <hash> is the hash of the command, for fast lookup.
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("input", help="input file")
parser.add_argument("output", help="output dir")
args = parser.parse_args()
# We start with empty workflows
results = []
if not exists:
parser.error("%s does not exist")
inFiles, zipFile = getRelValsFiles(args.input, "*/cmdLog", ".*/cmdLog")
try:
[makedirs(join(args.output, x)) for x in "0123456789abcdef"]
except:
if not exists(args.output):
parser.error("Unable to create " + args.output)
exit(0)
for name in inFiles:
m = re.match("(.*/|)([0-9.]+)_([^/]*)/cmdLog", name)
if not m: continue
xpath, workflowId, workflow = m.groups()
report = readRelValFile(name,zipFile)
report += "\n#"
command = ""
lumi_cmd = ""
for l in report.split("\n"):
if not l.strip(): continue
if not l.startswith("#"):
command=command+l+"\n"
continue
if not command: continue
if ("_lumiRanges.log" in command) and (not "--lumiToProcess" in command):
lumi_cmd = command
command = ""
continue
step = [c for c in command.split(" ") if c.startswith("step")][-1].split("_",1)[0].replace('step','')
t = "CMSDRIVER"
if ("das_client" in command) or ("dasgoclient" in command):
command = lumi_cmd+re.sub(" --cache.*das-cache.file", " --cache .../das-cache.file", command)
lumi_cmd = ""
t = "DAS"
command = command.strip()
h = sha1(command).hexdigest()[0:16]
# One file per hash
(fh, filename) = mkstemp()
file = fdopen(fh, "w")
dump({"command": command, "type": t}, file)
file.close()
try:
destFile = join(args.output, h[0], h[1:])
move(filename, destFile)
except:
print "Unable to move " + destFile + " into place."
unlink(filename)
results.append((workflowId + "-" + str(step), h))
command = ""
print dumps(dict(results), sort_keys=True, indent=2, separators=(',', ': '))