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 83 of file helperFunctions.py.

References replacelast().

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

83 
84 def addIndex(filename, njobs, index = None):
85  if index is None:
86  return [addIndex(filename, njobs, i) for i in range(njobs)]
87  if njobs == 1:
88  return filename
89 
90  fileExtension = None
91  for extension in fileExtensions:
92  if filename.endswith(extension):
93  fileExtension = extension
94  if fileExtension is None:
95  raise AllInOneError(fileName + " does not end with any of the extensions "
96  + str(fileExtensions))
97  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 56 of file helperFunctions.py.

References getCommandOutput2().

56 
57 def castorDirExists(path):
58  """This function checks if the directory given by `path` exists.
59 
60  Arguments:
61  - `path`: Path to castor directory
62  """
63 
64  if path[-1] == "/":
65  path = path[:-1]
66  containingPath = os.path.join( *path.split("/")[:-1] )
67  dirInQuestion = path.split("/")[-1]
68  try:
69  rawLines = getCommandOutput2("rfdir /"+containingPath).splitlines()
70  except RuntimeError:
71  return False
72  for line in rawLines:
73  if line.split()[0][0] == "d":
74  if line.split()[8] == dirInQuestion:
75  return True
76  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 41 of file helperFunctions.py.

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

41 
42 def getCommandOutput2(command):
43  """This function executes `command` and returns it output.
44 
45  Arguments:
46  - `command`: Shell command to be invoked by this function.
47  """
48 
49  child = os.popen(command)
50  data = child.read()
51  err = child.close()
52  if err:
53  raise RuntimeError('%s failed w/ exit code %d' % (command, err))
54  return data
55 
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  for index, value in enumerate(the_map[key]):
29  result = result.replace(".oO[" + key + "[" + str(index) + "]]Oo.", value)
30  iteration += 1
31  if iteration > lifeSaver:
32  problematicLines = ""
33  for line in result.splitlines():
34  if ".oO[" in result and "]Oo." in line:
35  problematicLines += "%s\n"%line
36  msg = ("Oh Dear, there seems to be an endless loop in "
37  "replaceByMap!!\n%s\nrepMap"%problematicLines)
38  raise AllInOneError(msg)
39  return result
40 
def replaceByMap
— Helpers —############################
def helperFunctions.replacelast (   string,
  old,
  new,
  count = 1 
)
Replace the last occurances of a string

Definition at line 77 of file helperFunctions.py.

Referenced by addIndex().

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

Variable Documentation

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

Definition at line 81 of file helperFunctions.py.