| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Namespace List
- Namespace Members

Functions | Variables
merge_files Namespace Reference

## Functions
def | mergeFiles (fragFileNames, mergedFileName, commentChar, doMerge, ignoreMissing)

## 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 = lambdax:x+".stamp"
tuple | globalLock = locker.LockFile(os.environ["GAUDI_BUILD_LOCK"], temporary = True)

## Function Documentation

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

Definition at line 12 of file merge_files.py.

12 def mergeFiles( fragFileNames, mergedFileName, commentChar, doMerge, ignoreMissing ):
13
14 startMark = "%s --Beg " % commentChar
15 timeMark = "%s --Date inserted: %s" % (commentChar, datetime.now())
16 endMark = "%s --End " % commentChar
17 nameOffset = len(startMark)
18
19 basenames = map(os.path.basename, fragFileNames)
20
21 isNewFile = not os.path.exists(mergedFileName)
22
23 # create an empty file if it does not exist
24 # "append mode" ensures that, in case of two processes trying to
25 # create the file, they do not truncate each other file
26 if isNewFile:
27 # check if the destination directory exists
28 path_to_file = os.path.split(mergedFileName)[0]
29 if path_to_file and not os.path.isdir(path_to_file):
30 # if doesn't exist, create it
31 os.makedirs(path_to_file)
32 open(mergedFileName,'a')
33
34 lockFile = open( mergedFileName + '.lock', 'a' )
35
36 # locking file, gaining exclusive access to it
37 # code from locker.py, only posix relevant part - we don't support NT - did we ever ??
38 # Lock with a simple call to lockf() - this blocks until the lock is aquired
39 try:
40 fcntl.lockf( lockFile, fcntl.LOCK_EX )
41 except IOError, exc_value:
42 print "Problem when trying to lock {0}, IOError {1}".format(mergedFile, exc_value[0])
43 raise
44
45 mergedFile = open( mergedFileName, 'r' )
46
47 try:
48
49 newLines = [ ]
50 skipBlock = ""
51 for line in mergedFile.readlines():
52 if line.startswith(startMark) and line[nameOffset:].strip() in basenames:
53 skipBlock = endMark + line[nameOffset:].strip()
54 # remove all the empty lines occurring before the start mark
55 while (len(newLines) > 0) and (newLines[-1].strip() == ''):
56 newLines.pop()
57 if not skipBlock:
58 newLines.append(line)
59 if line.startswith(skipBlock):
60 skipBlock = ""
61 if skipBlock:
62 print "WARNING: missing end mark ('%s')" % skipBlock
63
64 if doMerge:
65 for f in fragFileNames:
66 if ignoreMissing and not os.path.exists(f):
67 print "WARNING: '%s' does not exist, I'm ignoring it" % f
68 continue
69 # I do not want to add 2 empty lines at the beginning of a file
70 if newLines:
71 newLines.append('\n\n')
72 bf = os.path.basename(f)
73 newLines.append(startMark + bf + '\n')
74 newLines.append(timeMark + '\n')
75 fileData = open(f, 'r').read()
76 newLines.append(fileData)
77 if fileData and fileData[-1] != '\n':
78 newLines.append('\n')
79 newLines.append(endMark + bf + '\n')
80
81 #mergedFile.seek(0)
82 #mergedFile.truncate(0)
83 #mergedFile.writelines(newLines)
84
85 newFile = open( mergedFileName + ".new" , 'w' )
86 newFile.writelines(newLines)
87 newFile.close()
88 os.rename(mergedFileName + ".new",mergedFileName)
89
90 finally:
91 # unlock file
92 fcntl.lockf( lockFile, fcntl.LOCK_UN )
93
94 return 0
95
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
Containers::map
struct GAUDI_API map
Parametrisation class for map-like implementation.
Definition: KeyedObjectManager.h:25
merge_files.mergeFiles
def mergeFiles(fragFileNames, mergedFileName, commentChar, doMerge, ignoreMissing)
Definition: merge_files.py:12

## Variable Documentation

string merge_files.action = "append"

Definition at line 103 of file merge_files.py.

string merge_files.default = []

Definition at line 105 of file merge_files.py.

string merge_files.dest = "fragFileNames"

Definition at line 104 of file merge_files.py.

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

Definition at line 187 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 106 of file merge_files.py.

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

Definition at line 99 of file merge_files.py.

tuple merge_files.sc = 1

Definition at line 167 of file merge_files.py.

tuple merge_files.stampFileName = lambdax:x+".stamp"

Definition at line 176 of file merge_files.py.