4 from TkAlExceptions
import AllInOneError
8 """This function replaces `.oO[key]Oo.` by `the_map[key]` in target. 11 - `target`: String which contains symbolic tags of the form `.oO[key]Oo.` 12 - `the_map`: Dictionary which has to contain the `key`s in `target` as keys 19 while ".oO[" in result
and "]Oo." in result:
22 result = result.replace(
".oO["+key+
"]Oo.",the_map[key])
25 for keykey, value
in the_map[key].iteritems():
26 result = result.replace(
".oO[" + key +
"['" + keykey +
"']]Oo.", value)
27 result = result.replace(
".oO[" + key +
'["' + keykey +
'"]]Oo.', value)
28 except AttributeError:
30 for index, value
in enumerate(the_map[key]):
31 result = result.replace(
".oO[" + key +
"[" +
str(index) +
"]]Oo.", value)
33 raise TypeError(
"Something is wrong in replaceByMap! Need a string, dict, or list, but the_map(%s)=%s!"%(repr(key), repr(the_map[key])))
35 if iteration > lifeSaver:
37 for line
in result.splitlines():
38 if ".oO[" in result
and "]Oo." in line:
39 problematicLines +=
"%s\n"%line
40 msg = (
"Oh Dear, there seems to be an endless loop in " 41 "replaceByMap!!\n%s\n%s"%(problematicLines, the_map))
47 """This function executes `command` and returns it output. 50 - `command`: Shell command to be invoked by this function. 53 child = os.popen(command)
57 raise RuntimeError(
'%s failed w/ exit code %d' % (command, err))
62 """This function checks if the directory given by `path` exists. 65 - `path`: Path to castor directory 70 containingPath = os.path.join( *path.split(
"/")[:-1] )
71 dirInQuestion = path.split(
"/")[-1]
77 if line.split()[0][0] ==
"d":
78 if line.split()[8] == dirInQuestion:
83 """Replace the last occurances of a string""" 84 return new.join(string.rsplit(old,count))
86 fileExtensions = [
"_cfg.py",
".sh",
".root"]
90 return [
addIndex(filename, njobs, i)
for i
in range(njobs)]
95 for extension
in fileExtensions:
96 if filename.endswith(extension):
97 fileExtension = extension
98 if fileExtension
is None:
99 raise AllInOneError(fileName +
" does not end with any of the extensions " 100 +
str(fileExtensions))
101 return replacelast(filename, fileExtension,
"_" +
str(index) + fileExtension)
110 color =
str(getattr(ROOT, color))
112 except (AttributeError, ValueError):
115 if color.count(
"+") + color.count(
"-") == 1:
117 split = color.split(
"+")
120 return color1 + color2
123 split = color.split(
"-")
126 return color1 - color2
128 raise AllInOneError(
"color has to be an integer, a ROOT constant (kRed, kBlue, ...), or a two-term sum or difference (kGreen-5)!")
137 style =
str(getattr(ROOT,style))
139 except (AttributeError, ValueError):
142 raise AllInOneError(
"style has to be an integer or a ROOT constant (kDashed, kStar, ...)!")
146 for subcls
in cls.__subclasses__():
152 def newfunction(*args, **kwargs):
154 return cache[args, tuple(sorted(kwargs.iteritems()))]
156 print args, tuple(sorted(kwargs.iteritems()))
159 cache[args, tuple(sorted(kwargs.iteritems()))] =
function(*args, **kwargs)
160 return newfunction(*args, **kwargs)
161 newfunction.__name__ = function.__name__
166 Takes a string from the configuration file 167 and makes it into a bool 170 if string.lower() ==
"true":
return True 171 if string.lower() ==
"false":
return False 174 return str(bool(
int(string)))
178 raise ValueError(
"{} has to be true or false!".
format(name))
183 Takes a string from the configuration file 184 and makes it into a bool string for a python template 190 Takes a string from the configuration file 191 and makes it into a bool string for a C++ template 197 Wrapper for conddb, so that you can run 198 conddb("--db", "myfile.db", "listTags"), 199 like from the command line, without explicitly 200 dealing with all the functions in CondCore/Utilities. 201 getcommandoutput2(conddb ...) doesn't work, it imports 202 the wrong sqlalchemy in CondCore/Utilities/python/conddblib.py 204 from tempfile
import NamedTemporaryFile
212 namespace = {
"sysexit": sysexit,
"conddboutput":
""}
214 conddb = conddb.replace(
"sys.exit",
"sysexit")
218 bkpstdout = sys.stdout
219 with NamedTemporaryFile(bufsize=0)
as sys.stdout:
220 exec conddb
in namespace
222 with open(sys.stdout.name)
as f:
225 sys.argv[:] = bkpargv
226 sys.stdout = bkpstdout
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)