5 from TkAlExceptions
import AllInOneError
9 """This function replaces `.oO[key]Oo.` by `the_map[key]` in target. 12 - `target`: String which contains symbolic tags of the form `.oO[key]Oo.` 13 - `the_map`: Dictionary which has to contain the `key`s in `target` as keys 20 while ".oO[" in result
and "]Oo." in result:
23 result = result.replace(
".oO["+key+
"]Oo.",the_map[key])
26 for keykey, value
in the_map[key].iteritems():
27 result = result.replace(
".oO[" + key +
"['" + keykey +
"']]Oo.", value)
28 result = result.replace(
".oO[" + key +
'["' + keykey +
'"]]Oo.', value)
29 except AttributeError:
31 for index, value
in enumerate(the_map[key]):
32 result = result.replace(
".oO[" + key +
"[" +
str(index) +
"]]Oo.", value)
34 raise TypeError(
"Something is wrong in replaceByMap! Need a string, dict, or list, but the_map(%s)=%s!"%(repr(key), repr(the_map[key])))
36 if iteration > lifeSaver:
38 for line
in result.splitlines():
39 if ".oO[" in result
and "]Oo." in line:
40 problematicLines +=
"%s\n"%line
41 msg = (
"Oh Dear, there seems to be an endless loop in " 42 "replaceByMap!!\n%s\n%s"%(problematicLines, the_map))
48 """This function executes `command` and returns it output. 51 - `command`: Shell command to be invoked by this function. 54 child = os.popen(command)
58 raise RuntimeError(
'%s failed w/ exit code %d' % (command, err))
63 """This function checks if the directory given by `path` exists. 66 - `path`: Path to castor directory 71 containingPath = os.path.join( *path.split(
"/")[:-1] )
72 dirInQuestion = path.split(
"/")[-1]
78 if line.split()[0][0] ==
"d":
79 if line.split()[8] == dirInQuestion:
84 """Replace the last occurances of a string""" 85 return new.join(string.rsplit(old,count))
87 fileExtensions = [
"_cfg.py",
".sh",
".root"]
91 return [
addIndex(filename, njobs, i)
for i
in range(njobs)]
96 for extension
in fileExtensions:
97 if filename.endswith(extension):
98 fileExtension = extension
99 if fileExtension
is None:
100 raise AllInOneError(fileName +
" does not end with any of the extensions " 101 +
str(fileExtensions))
102 return replacelast(filename, fileExtension,
"_" +
str(index) + fileExtension)
111 color =
str(getattr(ROOT, color))
113 except (AttributeError, ValueError):
116 if color.count(
"+") + color.count(
"-") == 1:
118 split = color.split(
"+")
121 return color1 + color2
124 split = color.split(
"-")
127 return color1 - color2
129 raise AllInOneError(
"color has to be an integer, a ROOT constant (kRed, kBlue, ...), or a two-term sum or difference (kGreen-5)!")
138 style =
str(getattr(ROOT,style))
140 except (AttributeError, ValueError):
143 raise AllInOneError(
"style has to be an integer or a ROOT constant (kDashed, kStar, ...)!")
147 for subcls
in cls.__subclasses__():
153 def newfunction(*args, **kwargs):
155 return cache[args, tuple(sorted(kwargs.iteritems()))]
157 print args, tuple(sorted(kwargs.iteritems()))
160 cache[args, tuple(sorted(kwargs.iteritems()))] =
function(*args, **kwargs)
161 return newfunction(*args, **kwargs)
162 newfunction.__name__ = function.__name__
167 Takes a string from the configuration file 168 and makes it into a bool 171 if string.lower() ==
"true":
return True 172 if string.lower() ==
"false":
return False 179 raise ValueError(
"{} has to be true or false!".
format(name))
184 Takes a string from the configuration file 185 and makes it into a bool string for a python template 191 Takes a string from the configuration file 192 and makes it into a bool string for a C++ template 198 Wrapper for conddb, so that you can run 199 conddb("--db", "myfile.db", "listTags"), 200 like from the command line, without explicitly 201 dealing with all the functions in CondCore/Utilities. 202 getcommandoutput2(conddb ...) doesn't work, it imports 203 the wrong sqlalchemy in CondCore/Utilities/python/conddblib.py 205 from tempfile
import NamedTemporaryFile
213 namespace = {
"sysexit": sysexit,
"conddboutput":
""}
215 conddb = conddb.replace(
"sys.exit",
"sysexit")
219 bkpstdout = sys.stdout
220 with NamedTemporaryFile(bufsize=0)
as sys.stdout:
221 exec conddb
in namespace
223 with open(sys.stdout.name)
as f:
226 sys.argv[:] = bkpargv
227 sys.stdout = bkpstdout
233 """Transforms a string into a valid variable or method name. 240 s = re.sub(
r"[^0-9a-zA-Z_]",
"", s)
243 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)