Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions | Variables
merge_files Namespace Reference

Functions

def mergeFiles
 

Variables

tuple parser OptionParser(usage="usage: %prog [options]")
 
string action "append"
 
string dest "fragFileNames"
 
list default []
 
string help "The path and name of the file one wants to merge into the 'master' one"
 
int sc 1
 
string stampFileName ".stamp"
 
tuple globalLock locker.LockFile(os.environ["GAUDI_BUILD_LOCK"], temporary = True)
 

Function Documentation

def merge_files.mergeFiles (   fragFileNames,
  mergedFileName,
  commentChar,
  doMerge 
)

Definition at line 12 of file merge_files.py.

12 
13 def mergeFiles( fragFileNames, mergedFileName, commentChar, doMerge ):
14 
15  startMark = "%s --Beg " % commentChar
16  timeMark = "%s --Date inserted: %s" % (commentChar, datetime.now())
17  endMark = "%s --End " % commentChar
18  nameOffset = len(startMark)
19 
20  basenames = map(os.path.basename, fragFileNames)
21 
22  isNewFile = not os.path.exists(mergedFileName)
23 
24  # create an empty file if it does not exist
25  # "append mode" ensures that, in case of two processes trying to
26  # create the file, they do not truncate each other file
27  if isNewFile:
28  # check if the destination directory exists
29  path_to_file = os.path.split(mergedFileName)[0]
30  if path_to_file and not os.path.isdir(path_to_file):
31  # if doesn't exist, create it
32  os.makedirs(path_to_file)
33  open(mergedFileName,'a')
34 
35  mergedFile = open( mergedFileName, 'r+' )
36 
37  # locking file, gaining exclusive access to it
38  lock = locker.lock( mergedFile )
39  try:
40 
41  newLines = [ ]
42  skipBlock = ""
43  for line in mergedFile.readlines():
44  if line.startswith(startMark) and line[nameOffset:].strip() in basenames:
45  skipBlock = endMark + line[nameOffset:].strip()
46  # remove all the empty lines occurring before the start mark
47  while (len(newLines) > 0) and (newLines[-1].strip() == ''):
48  newLines.pop()
49  if not skipBlock:
50  newLines.append(line)
51  if line.startswith(skipBlock):
52  skipBlock = ""
53  if skipBlock:
54  print "WARNING: missing end mark ('%s')" % skipBlock
55 
56  if doMerge:
57  for f in fragFileNames:
58  # I do not want to add 2 empty lines at the beginning of a file
59  if newLines:
60  newLines.append('\n\n')
61  bf = os.path.basename(f)
62  newLines.append(startMark + bf + '\n')
63  newLines.append(timeMark + '\n')
64  fileData = open(f, 'r').read()
65  newLines.append(fileData)
66  if fileData and fileData[-1] != '\n':
67  newLines.append('\n')
68  newLines.append(endMark + bf + '\n')
69 
70  mergedFile.seek(0)
71  mergedFile.truncate(0)
72  mergedFile.writelines(newLines)
73 
74  finally:
75  # unlock file
76  locker.unlock( mergedFile )
77 
78  return 0

Variable Documentation

string merge_files.action "append"

Definition at line 86 of file merge_files.py.

string merge_files.default []

Definition at line 88 of file merge_files.py.

string merge_files.dest "fragFileNames"

Definition at line 87 of file merge_files.py.

merge_files.globalLock locker.LockFile(os.environ["GAUDI_BUILD_LOCK"], temporary = True)

Definition at line 163 of file merge_files.py.

string merge_files.help "The path and name of the file one wants to merge into the 'master' one"

Definition at line 89 of file merge_files.py.

tuple merge_files.parser OptionParser(usage="usage: %prog [options]")

Definition at line 82 of file merge_files.py.

tuple merge_files.sc 1

Definition at line 144 of file merge_files.py.

tuple merge_files.stampFileName ".stamp"

Definition at line 153 of file merge_files.py.


Generated at Wed Nov 28 2012 12:17:41 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004