5 from TkAlExceptions
import AllInOneError
10 """This function replaces `.oO[key]Oo.` by `the_map[key]` in target. 13 - `target`: String which contains symbolic tags of the form `.oO[key]Oo.` 14 - `the_map`: Dictionary which has to contain the `key`s in `target` as keys 21 while ".oO[" in result
and "]Oo." in result:
24 result = result.replace(
".oO["+key+
"]Oo.",the_map[key])
27 for keykey, value
in six.iteritems(the_map[key]):
28 result = result.replace(
".oO[" + key +
"['" + keykey +
"']]Oo.", value)
29 result = result.replace(
".oO[" + key +
'["' + keykey +
'"]]Oo.', value)
30 except AttributeError:
32 for index, value
in enumerate(the_map[key]):
33 result = result.replace(
".oO[" + key +
"[" +
str(index) +
"]]Oo.", value)
35 raise TypeError(
"Something is wrong in replaceByMap! Need a string, dict, or list, but the_map(%s)=%s!"%(repr(key), repr(the_map[key])))
37 if iteration > lifeSaver:
39 for line
in result.splitlines():
40 if ".oO[" in result
and "]Oo." in line:
41 problematicLines +=
"%s\n"%line
42 msg = (
"Oh Dear, there seems to be an endless loop in " 43 "replaceByMap!!\n%s\n%s"%(problematicLines, the_map))
49 """This function executes `command` and returns it output. 52 - `command`: Shell command to be invoked by this function. 55 child = os.popen(command)
59 raise RuntimeError(
'%s failed w/ exit code %d' % (command, err))
64 """This function checks if the directory given by `path` exists. 67 - `path`: Path to castor directory 72 containingPath = os.path.join( *path.split(
"/")[:-1] )
73 dirInQuestion = path.split(
"/")[-1]
79 if line.split()[0][0] ==
"d":
80 if line.split()[8] == dirInQuestion:
85 """Replace the last occurances of a string""" 86 return new.join(string.rsplit(old,count))
88 fileExtensions = [
"_cfg.py",
".sh",
".root"]
92 return [
addIndex(filename, njobs, i)
for i
in range(njobs)]
97 for extension
in fileExtensions:
98 if filename.endswith(extension):
99 fileExtension = extension
100 if fileExtension
is None:
101 raise AllInOneError(fileName +
" does not end with any of the extensions " 102 +
str(fileExtensions))
103 return replacelast(filename, fileExtension,
"_" +
str(index) + fileExtension)
112 color =
str(getattr(ROOT, color))
114 except (AttributeError, ValueError):
117 if color.count(
"+") + color.count(
"-") == 1:
119 split = color.split(
"+")
122 return color1 + color2
125 split = color.split(
"-")
128 return color1 - color2
130 raise AllInOneError(
"color has to be an integer, a ROOT constant (kRed, kBlue, ...), or a two-term sum or difference (kGreen-5)!")
139 style =
str(getattr(ROOT,style))
141 except (AttributeError, ValueError):
144 raise AllInOneError(
"style has to be an integer or a ROOT constant (kDashed, kStar, ...)!")
148 for subcls
in cls.__subclasses__():
154 def newfunction(*args, **kwargs):
156 return cache[args, tuple(sorted(six.iteritems(kwargs)))]
158 print args, tuple(sorted(six.iteritems(kwargs)))
161 cache[args, tuple(sorted(six.iteritems(kwargs)))] =
function(*args, **kwargs)
162 return newfunction(*args, **kwargs)
163 newfunction.__name__ = function.__name__
168 Takes a string from the configuration file 169 and makes it into a bool 172 if string.lower() ==
"true":
return True 173 if string.lower() ==
"false":
return False 180 raise ValueError(
"{} has to be true or false!".
format(name))
185 Takes a string from the configuration file 186 and makes it into a bool string for a python template 192 Takes a string from the configuration file 193 and makes it into a bool string for a C++ template 199 Wrapper for conddb, so that you can run 200 conddb("--db", "myfile.db", "listTags"), 201 like from the command line, without explicitly 202 dealing with all the functions in CondCore/Utilities. 203 getcommandoutput2(conddb ...) doesn't work, it imports 204 the wrong sqlalchemy in CondCore/Utilities/python/conddblib.py 206 from tempfile
import NamedTemporaryFile
214 namespace = {
"sysexit": sysexit,
"conddboutput":
""}
216 conddb = conddb.replace(
"sys.exit",
"sysexit")
220 bkpstdout = sys.stdout
221 with NamedTemporaryFile(bufsize=0)
as sys.stdout:
222 exec(conddb, namespace)
224 with open(sys.stdout.name)
as f:
227 sys.argv[:] = bkpargv
228 sys.stdout = bkpstdout
234 """Transforms a string into a valid variable or method name. 241 s = re.sub(
r"[^0-9a-zA-Z_]",
"", s)
244 s = re.sub(
r"^[^a-zA-Z_]+",
"", s)
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)