1 from __future__
import print_function
2 from __future__
import absolute_import
3 from builtins
import range
8 from .TkAlExceptions
import AllInOneError
9 import CondCore.Utilities.conddblib
as conddblib
14 """This function replaces `.oO[key]Oo.` by `the_map[key]` in target.
17 - `target`: String which contains symbolic tags of the form `.oO[key]Oo.`
18 - `the_map`: Dictionary which has to contain the `key`s in `target` as keys
25 while ".oO[" in result
and "]Oo." in result:
28 result = result.replace(
".oO["+key+
"]Oo.",the_map[key])
31 for keykey, value
in six.iteritems(the_map[key]):
32 result = result.replace(
".oO[" + key +
"['" + keykey +
"']]Oo.", value)
33 result = result.replace(
".oO[" + key +
'["' + keykey +
'"]]Oo.', value)
34 except AttributeError:
36 for index, value
in enumerate(the_map[key]):
37 result = result.replace(
".oO[" + key +
"[" +
str(index) +
"]]Oo.", value)
39 raise TypeError(
"Something is wrong in replaceByMap! Need a string, dict, or list, but the_map(%s)=%s!"%(repr(key), repr(the_map[key])))
41 if iteration > lifeSaver:
43 for line
in result.splitlines():
44 if ".oO[" in result
and "]Oo." in line:
45 problematicLines +=
"%s\n"%line
46 msg = (
"Oh Dear, there seems to be an endless loop in "
47 "replaceByMap!!\n%s\n%s"%(problematicLines, the_map))
53 """This function executes `command` and returns it output.
56 - `command`: Shell command to be invoked by this function.
59 child = os.popen(command)
63 raise RuntimeError(
'%s failed w/ exit code %d' % (command, err))
68 """This function checks if the directory given by `path` exists.
71 - `path`: Path to castor directory
76 containingPath = os.path.join( *path.split(
"/")[:-1] )
77 dirInQuestion = path.split(
"/")[-1]
83 if line.split()[0][0] ==
"d":
84 if line.split()[8] == dirInQuestion:
89 """Replace the last occurances of a string"""
90 return new.join(string.rsplit(old,count))
92 fileExtensions = [
"_cfg.py",
".sh",
".root"]
101 for extension
in fileExtensions:
102 if filename.endswith(extension):
103 fileExtension = extension
104 if fileExtension
is None:
105 raise AllInOneError(fileName +
" does not end with any of the extensions "
106 +
str(fileExtensions))
107 return replacelast(filename, fileExtension,
"_" +
str(index) + fileExtension)
116 color =
str(getattr(ROOT, color))
118 except (AttributeError, ValueError):
121 if color.count(
"+") + color.count(
"-") == 1:
123 split = color.split(
"+")
126 return color1 + color2
129 split = color.split(
"-")
132 return color1 - color2
134 raise AllInOneError(
"color has to be an integer, a ROOT constant (kRed, kBlue, ...), or a two-term sum or difference (kGreen-5)!")
143 style =
str(getattr(ROOT,style))
145 except (AttributeError, ValueError):
148 raise AllInOneError(
"style has to be an integer or a ROOT constant (kDashed, kStar, ...)!")
152 for subcls
in cls.__subclasses__():
158 def newfunction(*args, **kwargs):
160 return cache[args, tuple(sorted(six.iteritems(kwargs)))]
162 print(args, tuple(sorted(six.iteritems(kwargs))))
165 cache[args, tuple(sorted(six.iteritems(kwargs)))] =
function(*args, **kwargs)
166 return newfunction(*args, **kwargs)
167 newfunction.__name__ = function.__name__
172 Takes a string from the configuration file
173 and makes it into a bool
176 if string.lower() ==
"true":
return True
177 if string.lower() ==
"false":
return False
184 raise ValueError(
"{} has to be true or false!".
format(name))
189 Takes a string from the configuration file
190 and makes it into a bool string for a python template
196 Takes a string from the configuration file
197 and makes it into a bool string for a C++ template
203 session = con.session()
206 for i
in range(0,len(session.query(TAG.object_type).order_by(TAG.name).
all())):
207 q1 = session.query(TAG.object_type).order_by(TAG.name).
all()[i][0]
208 q2 = session.query(TAG.name).order_by(TAG.name).
all()[i][0]
214 """Transforms a string into a valid variable or method name.
221 s = re.sub(
r"[^0-9a-zA-Z_]",
"", s)
224 s = re.sub(
r"^[^a-zA-Z_]+",
"", s)