2 from TkAlExceptions
import AllInOneError
6 """This function replaces `.oO[key]Oo.` by `the_map[key]` in target.
9 - `target`: String which contains symbolic tags of the form `.oO[key]Oo.`
10 - `the_map`: Dictionary which has to contain the `key`s in `target` as keys
17 while ".oO[" in result
and "]Oo." in result:
20 result = result.replace(
".oO["+key+
"]Oo.",the_map[key])
23 for keykey, value
in the_map[key].iteritems():
24 result = result.replace(
".oO[" + key +
"['" + keykey +
"']]Oo.", value)
25 result = result.replace(
".oO[" + key +
'["' + keykey +
'"]]Oo.', value)
26 except AttributeError:
27 for index, value
in enumerate(the_map[key]):
28 result = result.replace(
".oO[" + key +
"[" + str(index) +
"]]Oo.", value)
30 if iteration > lifeSaver:
32 for line
in result.splitlines():
33 if ".oO[" in result
and "]Oo." in line:
34 problematicLines +=
"%s\n"%line
35 msg = (
"Oh Dear, there seems to be an endless loop in "
36 "replaceByMap!!\n%s\nrepMap"%problematicLines)
42 """This function executes `command` and returns it output.
45 - `command`: Shell command to be invoked by this function.
48 child = os.popen(command)
52 raise RuntimeError,
'%s failed w/ exit code %d' % (command, err)
57 """This function checks if the directory given by `path` exists.
60 - `path`: Path to castor directory
65 containingPath = os.path.join( *path.split(
"/")[:-1] )
66 dirInQuestion = path.split(
"/")[-1]
72 if line.split()[0][0] ==
"d":
73 if line.split()[8] == dirInQuestion:
78 """Replace the last occurances of a string"""
79 return new.join(string.rsplit(old,count))
81 fileExtensions = [
"_cfg.py",
".sh",
".root"]
85 return [
addIndex(filename, njobs, i)
for i
in range(njobs)]
90 for extension
in fileExtensions:
91 if filename.endswith(extension):
92 fileExtension = extension
93 if fileExtension
is None:
94 raise AllInOneError(fileName +
" does not end with any of the extensions "
95 + str(fileExtensions))
96 return replacelast(filename, fileExtension,
"_" + str(index) + fileExtension)
def replaceByMap
— Helpers —############################