CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
helperFunctions Namespace Reference

Functions

def addIndex
 
def castorDirExists
 
def getCommandOutput2
 
def replaceByMap
 — Helpers —############################ More...
 
def replacelast
 

Variables

list fileExtensions = ["_cfg.py", ".sh", ".root"]
 

Function Documentation

def helperFunctions.addIndex (   filename,
  njobs,
  index = None 
)

Definition at line 86 of file helperFunctions.py.

References replacelast().

Referenced by genericValidation.GenericValidation.createFiles(), genericValidation.GenericValidationData.createScript(), and genericValidation.GenericValidationData.getRepMap().

86 
87 def addIndex(filename, njobs, index = None):
88  if index is None:
89  return [addIndex(filename, njobs, i) for i in range(njobs)]
90  if njobs == 1:
91  return filename
92 
93  fileExtension = None
94  for extension in fileExtensions:
95  if filename.endswith(extension):
96  fileExtension = extension
97  if fileExtension is None:
98  raise AllInOneError(fileName + " does not end with any of the extensions "
99  + str(fileExtensions))
100  return replacelast(filename, fileExtension, "_" + str(index) + fileExtension)
def helperFunctions.castorDirExists (   path)
This function checks if the directory given by `path` exists.

Arguments:
- `path`: Path to castor directory

Definition at line 59 of file helperFunctions.py.

References getCommandOutput2().

59 
60 def castorDirExists(path):
61  """This function checks if the directory given by `path` exists.
62 
63  Arguments:
64  - `path`: Path to castor directory
65  """
66 
67  if path[-1] == "/":
68  path = path[:-1]
69  containingPath = os.path.join( *path.split("/")[:-1] )
70  dirInQuestion = path.split("/")[-1]
71  try:
72  rawLines = getCommandOutput2("rfdir /"+containingPath).splitlines()
73  except RuntimeError:
74  return False
75  for line in rawLines:
76  if line.split()[0][0] == "d":
77  if line.split()[8] == dirInQuestion:
78  return True
79  return False
def helperFunctions.getCommandOutput2 (   command)
This function executes `command` and returns it output.

Arguments:
- `command`: Shell command to be invoked by this function.

Definition at line 44 of file helperFunctions.py.

Referenced by castorDirExists(), validateAlignments.main(), and validateAlignments.ValidationJob.runJob().

44 
45 def getCommandOutput2(command):
46  """This function executes `command` and returns it output.
47 
48  Arguments:
49  - `command`: Shell command to be invoked by this function.
50  """
51 
52  child = os.popen(command)
53  data = child.read()
54  err = child.close()
55  if err:
56  raise RuntimeError('%s failed w/ exit code %d' % (command, err))
57  return data
58 
def helperFunctions.replaceByMap (   target,
  the_map 
)

— Helpers —############################

This function replaces `.oO[key]Oo.` by `the_map[key]` in target.

Arguments:
- `target`: String which contains symbolic tags of the form `.oO[key]Oo.`
- `the_map`: Dictionary which has to contain the `key`s in `target` as keys

Definition at line 5 of file helperFunctions.py.

Referenced by geometryComparison.GeometryComparison.createConfiguration(), validateAlignments.createExtendedValidationScript(), genericValidation.GenericValidation.createFiles(), validateAlignments.createMergeScript(), validateAlignments.createOfflineParJobsMergeScript(), geometryComparison.GeometryComparison.createScript(), validateAlignments.createTrackSplitPlotScript(), alignment.Alignment.getConditions(), and genericValidation.GenericValidationData.getRepMap().

5 
6 def replaceByMap(target, the_map):
7  """This function replaces `.oO[key]Oo.` by `the_map[key]` in target.
8 
9  Arguments:
10  - `target`: String which contains symbolic tags of the form `.oO[key]Oo.`
11  - `the_map`: Dictionary which has to contain the `key`s in `target` as keys
12  """
13 
14  result = target
15  for key in the_map:
16  lifeSaver = 10e3
17  iteration = 0
18  while ".oO[" in result and "]Oo." in result:
19  for key in the_map:
20  try:
21  result = result.replace(".oO["+key+"]Oo.",the_map[key])
22  except TypeError: #try a dict
23  try:
24  for keykey, value in the_map[key].iteritems():
25  result = result.replace(".oO[" + key + "['" + keykey + "']]Oo.", value)
26  result = result.replace(".oO[" + key + '["' + keykey + '"]]Oo.', value)
27  except AttributeError: #try a list
28  try:
29  for index, value in enumerate(the_map[key]):
30  result = result.replace(".oO[" + key + "[" + str(index) + "]]Oo.", value)
31  except TypeError:
32  raise TypeError("Something is wrong in replaceByMap! Need a string, dict, or list, but the_map(%s)=%s!"%(repr(key), repr(the_map[key])))
33  iteration += 1
34  if iteration > lifeSaver:
35  problematicLines = ""
36  for line in result.splitlines():
37  if ".oO[" in result and "]Oo." in line:
38  problematicLines += "%s\n"%line
39  msg = ("Oh Dear, there seems to be an endless loop in "
40  "replaceByMap!!\n%s\nrepMap"%problematicLines)
41  raise AllInOneError(msg)
42  return result
43 
def replaceByMap
— Helpers —############################
def helperFunctions.replacelast (   string,
  old,
  new,
  count = 1 
)
Replace the last occurances of a string

Definition at line 80 of file helperFunctions.py.

Referenced by addIndex().

80 
81 def replacelast(string, old, new, count = 1):
82  """Replace the last occurances of a string"""
83  return new.join(string.rsplit(old,count))

Variable Documentation

list helperFunctions.fileExtensions = ["_cfg.py", ".sh", ".root"]

Definition at line 84 of file helperFunctions.py.