1 from __future__
import print_function
6 from TkAlExceptions
import AllInOneError
11 """This function replaces `.oO[key]Oo.` by `the_map[key]` in target. 14 - `target`: String which contains symbolic tags of the form `.oO[key]Oo.` 15 - `the_map`: Dictionary which has to contain the `key`s in `target` as keys 22 while ".oO[" in result
and "]Oo." in result:
25 result = result.replace(
".oO["+key+
"]Oo.",the_map[key])
28 for keykey, value
in six.iteritems(the_map[key]):
29 result = result.replace(
".oO[" + key +
"['" + keykey +
"']]Oo.", value)
30 result = result.replace(
".oO[" + key +
'["' + keykey +
'"]]Oo.', value)
31 except AttributeError:
33 for index, value
in enumerate(the_map[key]):
34 result = result.replace(
".oO[" + key +
"[" +
str(index) +
"]]Oo.", value)
36 raise TypeError(
"Something is wrong in replaceByMap! Need a string, dict, or list, but the_map(%s)=%s!"%(repr(key), repr(the_map[key])))
38 if iteration > lifeSaver:
40 for line
in result.splitlines():
41 if ".oO[" in result
and "]Oo." in line:
42 problematicLines +=
"%s\n"%line
43 msg = (
"Oh Dear, there seems to be an endless loop in " 44 "replaceByMap!!\n%s\n%s"%(problematicLines, the_map))
50 """This function executes `command` and returns it output. 53 - `command`: Shell command to be invoked by this function. 56 child = os.popen(command)
60 raise RuntimeError(
'%s failed w/ exit code %d' % (command, err))
65 """This function checks if the directory given by `path` exists. 68 - `path`: Path to castor directory 73 containingPath = os.path.join( *path.split(
"/")[:-1] )
74 dirInQuestion = path.split(
"/")[-1]
80 if line.split()[0][0] ==
"d":
81 if line.split()[8] == dirInQuestion:
86 """Replace the last occurances of a string""" 87 return new.join(string.rsplit(old,count))
89 fileExtensions = [
"_cfg.py",
".sh",
".root"]
93 return [
addIndex(filename, njobs, i)
for i
in range(njobs)]
98 for extension
in fileExtensions:
99 if filename.endswith(extension):
100 fileExtension = extension
101 if fileExtension
is None:
102 raise AllInOneError(fileName +
" does not end with any of the extensions " 103 +
str(fileExtensions))
104 return replacelast(filename, fileExtension,
"_" +
str(index) + fileExtension)
113 color =
str(getattr(ROOT, color))
115 except (AttributeError, ValueError):
118 if color.count(
"+") + color.count(
"-") == 1:
120 split = color.split(
"+")
123 return color1 + color2
126 split = color.split(
"-")
129 return color1 - color2
131 raise AllInOneError(
"color has to be an integer, a ROOT constant (kRed, kBlue, ...), or a two-term sum or difference (kGreen-5)!")
140 style =
str(getattr(ROOT,style))
142 except (AttributeError, ValueError):
145 raise AllInOneError(
"style has to be an integer or a ROOT constant (kDashed, kStar, ...)!")
149 for subcls
in cls.__subclasses__():
155 def newfunction(*args, **kwargs):
157 return cache[args, tuple(sorted(six.iteritems(kwargs)))]
159 print(args, tuple(sorted(six.iteritems(kwargs))))
162 cache[args, tuple(sorted(six.iteritems(kwargs)))] =
function(*args, **kwargs)
163 return newfunction(*args, **kwargs)
164 newfunction.__name__ = function.__name__
169 Takes a string from the configuration file 170 and makes it into a bool 173 if string.lower() ==
"true":
return True 174 if string.lower() ==
"false":
return False 181 raise ValueError(
"{} has to be true or false!".
format(name))
186 Takes a string from the configuration file 187 and makes it into a bool string for a python template 193 Takes a string from the configuration file 194 and makes it into a bool string for a C++ template 201 Wrapper for conddb, so that you can run 202 conddb("--db", "myfile.db", "listTags"), 203 like from the command line, without explicitly 204 dealing with all the functions in CondCore/Utilities. 205 getcommandoutput2(conddb ...) doesn't work, it imports 206 the wrong sqlalchemy in CondCore/Utilities/python/conddblib.py 209 from tempfile
import mkdtemp, NamedTemporaryFile
211 if conddbcode
is None:
216 with open(os.path.join(tmpdir,
"conddb"))
as f:
219 conddbcode = conddb.replace(
"sys.exit",
"sysexit")
224 namespace = {
"sysexit": sysexit,
"conddboutput":
""}
228 bkpstdout = sys.stdout
230 with NamedTemporaryFile(bufsize=0)
as sys.stdout:
231 exec(conddbcode, namespace)
233 with open(sys.stdout.name)
as f:
236 sys.argv[:] = bkpargv
237 sys.stdout = bkpstdout
243 """Transforms a string into a valid variable or method name. 250 s = re.sub(
r"[^0-9a-zA-Z_]",
"", s)
253 s = re.sub(
r"^[^a-zA-Z_]+",
"", s)
def pythonboolstring(string, name)
S & print(S &os, JobReport::InputFile const &f)
def getCommandOutput2(command)
def cppboolstring(string, name)
def addIndex(filename, njobs, index=None)
def replacelast(string, old, new, count=1)
def replaceByMap(target, the_map)
— Helpers —############################
def boolfromstring(string, name)
def castorDirExists(path)
def recursivesubclasses(cls)