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
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 the_map[key].
items():
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))
47 raise AllInOneError(msg)
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"]
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(kwargs.items()))]
161 print(args, tuple(sorted(kwargs.items())))
164 cache[args, tuple(sorted(kwargs.items()))] =
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
179 return str(bool(int(string)))
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
202 session = con.session()
205 for i
in range(0,len(session.query(TAG.object_type).order_by(TAG.name).
all())):
206 q1 = session.query(TAG.object_type).order_by(TAG.name).
all()[i][0]
207 q2 = session.query(TAG.name).order_by(TAG.name).
all()[i][0]
213 """Transforms a string into a valid variable or method name.
220 s = re.sub(
r"[^0-9a-zA-Z_]",
"", s)
223 s = re.sub(
r"^[^a-zA-Z_]+",
"", s)
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def replaceByMap
— Helpers —############################