3 from TkAlExceptions
import AllInOneError
7 """This function replaces `.oO[key]Oo.` by `the_map[key]` in target. 10 - `target`: String which contains symbolic tags of the form `.oO[key]Oo.` 11 - `the_map`: Dictionary which has to contain the `key`s in `target` as keys 18 while ".oO[" in result
and "]Oo." in result:
21 result = result.replace(
".oO["+key+
"]Oo.",the_map[key])
24 for keykey, value
in the_map[key].iteritems():
25 result = result.replace(
".oO[" + key +
"['" + keykey +
"']]Oo.", value)
26 result = result.replace(
".oO[" + key +
'["' + keykey +
'"]]Oo.', value)
27 except AttributeError:
29 for index, value
in enumerate(the_map[key]):
30 result = result.replace(
".oO[" + key +
"[" +
str(index) +
"]]Oo.", value)
32 raise TypeError(
"Something is wrong in replaceByMap! Need a string, dict, or list, but the_map(%s)=%s!"%(repr(key), repr(the_map[key])))
34 if iteration > lifeSaver:
36 for line
in result.splitlines():
37 if ".oO[" in result
and "]Oo." in line:
38 problematicLines +=
"%s\n"%line
39 msg = (
"Oh Dear, there seems to be an endless loop in " 40 "replaceByMap!!\n%s\n%s"%(problematicLines, the_map))
46 """This function executes `command` and returns it output. 49 - `command`: Shell command to be invoked by this function. 52 child = os.popen(command)
56 raise RuntimeError(
'%s failed w/ exit code %d' % (command, err))
61 """This function checks if the directory given by `path` exists. 64 - `path`: Path to castor directory 69 containingPath = os.path.join( *path.split(
"/")[:-1] )
70 dirInQuestion = path.split(
"/")[-1]
76 if line.split()[0][0] ==
"d":
77 if line.split()[8] == dirInQuestion:
82 """Replace the last occurances of a string""" 83 return new.join(string.rsplit(old,count))
85 fileExtensions = [
"_cfg.py",
".sh",
".root"]
89 return [
addIndex(filename, njobs, i)
for i
in range(njobs)]
94 for extension
in fileExtensions:
95 if filename.endswith(extension):
96 fileExtension = extension
97 if fileExtension
is None:
98 raise AllInOneError(fileName +
" does not end with any of the extensions " 99 +
str(fileExtensions))
100 return replacelast(filename, fileExtension,
"_" +
str(index) + fileExtension)
109 color =
str(getattr(ROOT, color))
111 except (AttributeError, ValueError):
114 if color.count(
"+") + color.count(
"-") == 1:
116 split = color.split(
"+")
119 return color1 + color2
122 split = color.split(
"-")
125 return color1 - color2
127 raise AllInOneError(
"color has to be an integer, a ROOT constant (kRed, kBlue, ...), or a two-term sum or difference (kGreen-5)!")
136 style =
str(getattr(ROOT,style))
138 except (AttributeError, ValueError):
141 raise AllInOneError(
"style has to be an integer or a ROOT constant (kDashed, kStar, ...)!")
145 for subcls
in cls.__subclasses__():
151 def newfunction(*args, **kwargs):
153 return cache[args, tuple(sorted(kwargs.iteritems()))]
155 print args, tuple(sorted(kwargs.iteritems()))
158 cache[args, tuple(sorted(kwargs.iteritems()))] =
function(*args, **kwargs)
159 return newfunction(*args, **kwargs)
160 newfunction.__name__ = function.__name__
165 Takes a string from the configuration file 166 and makes it into a bool 169 if string.lower() ==
"true":
return True 170 if string.lower() ==
"false":
return False 173 return str(bool(
int(string)))
177 raise ValueError(
"{} has to be true or false!".
format(name))
182 Takes a string from the configuration file 183 and makes it into a bool string for a python template 189 Takes a string from the configuration file 190 and makes it into a bool string for a C++ template
def pythonboolstring(string, name)
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)