1 from __future__
import print_function
2 from __future__
import absolute_import
3 from builtins
import range
8 from .TkAlExceptions
import AllInOneError
13 """This function replaces `.oO[key]Oo.` by `the_map[key]` in target. 16 - `target`: String which contains symbolic tags of the form `.oO[key]Oo.` 17 - `the_map`: Dictionary which has to contain the `key`s in `target` as keys 24 while ".oO[" in result
and "]Oo." in result:
27 result = result.replace(
".oO["+key+
"]Oo.",the_map[key])
30 for keykey, value
in six.iteritems(the_map[key]):
31 result = result.replace(
".oO[" + key +
"['" + keykey +
"']]Oo.", value)
32 result = result.replace(
".oO[" + key +
'["' + keykey +
'"]]Oo.', value)
33 except AttributeError:
35 for index, value
in enumerate(the_map[key]):
36 result = result.replace(
".oO[" + key +
"[" +
str(index) +
"]]Oo.", value)
38 raise TypeError(
"Something is wrong in replaceByMap! Need a string, dict, or list, but the_map(%s)=%s!"%(repr(key), repr(the_map[key])))
40 if iteration > lifeSaver:
42 for line
in result.splitlines():
43 if ".oO[" in result
and "]Oo." in line:
44 problematicLines +=
"%s\n"%line
45 msg = (
"Oh Dear, there seems to be an endless loop in " 46 "replaceByMap!!\n%s\n%s"%(problematicLines, the_map))
52 """This function executes `command` and returns it output. 55 - `command`: Shell command to be invoked by this function. 58 child = os.popen(command)
62 raise RuntimeError(
'%s failed w/ exit code %d' % (command, err))
67 """This function checks if the directory given by `path` exists. 70 - `path`: Path to castor directory 75 containingPath = os.path.join( *path.split(
"/")[:-1] )
76 dirInQuestion = path.split(
"/")[-1]
82 if line.split()[0][0] ==
"d":
83 if line.split()[8] == dirInQuestion:
88 """Replace the last occurances of a string""" 89 return new.join(string.rsplit(old,count))
91 fileExtensions = [
"_cfg.py",
".sh",
".root"]
95 return [
addIndex(filename, njobs, i)
for i
in range(njobs)]
100 for extension
in fileExtensions:
101 if filename.endswith(extension):
102 fileExtension = extension
103 if fileExtension
is None:
104 raise AllInOneError(fileName +
" does not end with any of the extensions " 105 +
str(fileExtensions))
106 return replacelast(filename, fileExtension,
"_" +
str(index) + fileExtension)
115 color =
str(getattr(ROOT, color))
117 except (AttributeError, ValueError):
120 if color.count(
"+") + color.count(
"-") == 1:
122 split = color.split(
"+")
125 return color1 + color2
128 split = color.split(
"-")
131 return color1 - color2
133 raise AllInOneError(
"color has to be an integer, a ROOT constant (kRed, kBlue, ...), or a two-term sum or difference (kGreen-5)!")
142 style =
str(getattr(ROOT,style))
144 except (AttributeError, ValueError):
147 raise AllInOneError(
"style has to be an integer or a ROOT constant (kDashed, kStar, ...)!")
151 for subcls
in cls.__subclasses__():
157 def newfunction(*args, **kwargs):
159 return cache[args, tuple(sorted(six.iteritems(kwargs)))]
161 print(args, tuple(sorted(six.iteritems(kwargs))))
164 cache[args, tuple(sorted(six.iteritems(kwargs)))] =
function(*args, **kwargs)
165 return newfunction(*args, **kwargs)
166 newfunction.__name__ = function.__name__
171 Takes a string from the configuration file 172 and makes it into a bool 175 if string.lower() ==
"true":
return True 176 if string.lower() ==
"false":
return False 183 raise ValueError(
"{} has to be true or false!".
format(name))
188 Takes a string from the configuration file 189 and makes it into a bool string for a python template 195 Takes a string from the configuration file 196 and makes it into a bool string for a C++ template 203 Wrapper for conddb, so that you can run 204 conddb("--db", "myfile.db", "listTags"), 205 like from the command line, without explicitly 206 dealing with all the functions in CondCore/Utilities. 207 getcommandoutput2(conddb ...) doesn't work, it imports 208 the wrong sqlalchemy in CondCore/Utilities/python/conddblib.py 211 from tempfile
import mkdtemp, NamedTemporaryFile
213 if conddbcode
is None:
218 with open(os.path.join(tmpdir,
"conddb"))
as f:
221 conddbcode = conddb.replace(
"sys.exit",
"sysexit")
226 namespace = {
"sysexit": sysexit,
"conddboutput":
""}
230 bkpstdout = sys.stdout
232 with NamedTemporaryFile(bufsize=0)
as sys.stdout:
233 exec(conddbcode, namespace)
235 with open(sys.stdout.name)
as f:
238 sys.argv[:] = bkpargv
239 sys.stdout = bkpstdout
245 """Transforms a string into a valid variable or method name. 252 s = re.sub(
r"[^0-9a-zA-Z_]",
"", s)
255 s = re.sub(
r"^[^a-zA-Z_]+",
"", s)
def pythonboolstring(string, name)
S & print(S &os, JobReport::InputFile const &f)
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)