3 from __future__
import print_function
5 import argparse, contextlib, os, re, shutil, subprocess, tempfile, time
7 if __name__ ==
"__main__":
9 if not os.path.exists(path):
raise ValueError(path+
" does not exist")
10 return os.path.abspath(path)
12 p = argparse.ArgumentParser()
13 p.add_argument(
"cfgfile", type=abspath)
14 p.add_argument(
"baddatafileslist", nargs=
"?", default=
None)
19 subprocess.check_output([
"cmsRun", cfgfile], stderr=subprocess.STDOUT)
20 except subprocess.CalledProcessError
as e:
21 if "FallbackFileOpenError" in e.output:
22 output = e.output.split(
"An exception of category 'FallbackFileOpenError' occurred while")[1]
23 filename = re.search(
"Failed to open the file '[^']*(/store/.*[.]root)", output).
group(1)
25 with open(badfilelist)
as f:
26 contents = set(f.read().
split())
27 if filename
in contents:
28 raise RuntimeError(filename+
"\nis already in\n"+badfilelist+
"\n\nExiting to avoid an infinite loop. Maybe you have this running on the same cfg file multiple times?")
29 contents.add(filename)
30 contents = sorted(contents)
31 with open(badfilelist,
"w")
as f:
32 f.write(
"\n".
join(contents)+
"\n")
33 print(
"found and added a bad file:\n"+filename)
36 return runcfg(cfgfile, badfilelist)
37 print(
"all files left are good")
39 @contextlib.contextmanager
41 """http://stackoverflow.com/a/24176022/5228524""" 43 os.chdir(os.path.expanduser(newdir))
49 def cdtemp():
return cd(tempfile.mkdtemp())
55 self.
pwd = os.getcwd()
56 self.
fd = self.
f =
None 66 self.
fd = os.open(self.
filename, os.O_CREAT | os.O_EXCL | os.O_WRONLY)
75 self.
f = os.fdopen(self.
fd,
'w')
96 self.
fd = self.
f =
None 103 def __init__(self, name, delay, message=None, printmessage=None, task="doing this"):
104 super(OneAtATime, self).
__init__(name, message=message)
106 if printmessage
is None:
107 printmessage =
"Another process is already {task}! Waiting {delay} seconds." 108 printmessage = printmessage.format(delay=delay, task=task)
113 result = super(OneAtATime, self).
__enter__()
117 time.sleep(self.
delay)
119 if __name__ ==
"__main__":
121 shutil.copy(args.cfgfile,
".")
123 badfilelist = args.badfilelist
124 if badfilelist
is None:
125 badfilelist = os.path.join(os.path.dirname(cfgfile,
"../../../run/DataFiles/baddatafiles.txt"))
127 runcfg(os.path.basename(args.cfgfile), args.badfilelist)
S & print(S &os, JobReport::InputFile const &f)
def __init__(self, name, message=None)
def runcfg(cfgfile, badfilelist)
static std::string join(char **cmd)
def __init__(self, name, delay, message=None, printmessage=None, task="doing this")