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)!")
def replaceByMap
— Helpers —############################