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:
28 for index, value
in enumerate(the_map[key]):
29 result = result.replace(
".oO[" + key +
"[" + str(index) +
"]]Oo.", value)
31 raise TypeError(
"Something is wrong in replaceByMap! Need a string, dict, or list, but the_map(%s)=%s!"%(repr(key), repr(the_map[key])))
33 if iteration > lifeSaver:
35 for line
in result.splitlines():
36 if ".oO[" in result
and "]Oo." in line:
37 problematicLines +=
"%s\n"%line
38 msg = (
"Oh Dear, there seems to be an endless loop in "
39 "replaceByMap!!\n%s\nrepMap"%problematicLines)
45 """This function executes `command` and returns it output.
48 - `command`: Shell command to be invoked by this function.
51 child = os.popen(command)
55 raise RuntimeError,
'%s failed w/ exit code %d' % (command, err)
60 """This function checks if the directory given by `path` exists.
63 - `path`: Path to castor directory
68 containingPath = os.path.join( *path.split(
"/")[:-1] )
69 dirInQuestion = path.split(
"/")[-1]
75 if line.split()[0][0] ==
"d":
76 if line.split()[8] == dirInQuestion:
81 """Replace the last occurances of a string"""
82 return new.join(string.rsplit(old,count))
84 fileExtensions = [
"_cfg.py",
".sh",
".root"]
88 return [
addIndex(filename, njobs, i)
for i
in range(njobs)]
93 for extension
in fileExtensions:
94 if filename.endswith(extension):
95 fileExtension = extension
96 if fileExtension
is None:
97 raise AllInOneError(fileName +
" does not end with any of the extensions "
98 + str(fileExtensions))
99 return replacelast(filename, fileExtension,
"_" + str(index) + fileExtension)
def replaceByMap
— Helpers —############################