1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# Explore directory recursively and append the specified line
# to all .cvsignore.
# put together by a newbie to python, use at your own risk!
import os
def addEOL( line ):
if len(line) > 0:
line = line.rstrip( '\n\r' ) + '\n'
return line
def listFiles( dummy, dirName, fileNames ):
print "* Content of directory: ", os.path.abspath(dirName), ":"
for file in fileNames:
print file
def updateCVSIgnore( linesToAdd, cvsignorePath ):
fread = file( cvsignorePath, 'r' )
lines = fread.readlines()
fread.close()
lines.extend( linesToAdd )
lines = [addEOL(line) for line in lines]
fwrite = file( cvsignorePath, 'w+' )
fwrite.writelines( lines )
fwrite.close()
print 'Updated: ', cvsignorePath
def listCVSIgnore( linesToAdd, dirName, fileNames ):
print "Exploring: ", os.path.abspath( dirName )
if ( fileNames.count( 'CVS' ) > 0 ):
fileNames.remove( 'CVS' )
if ( fileNames.count( '.cvsignore' ) > 0 ):
cvsignorePath = os.path.join( dirName, '.cvsignore' )
updateCVSIgnore( linesToAdd, os.path.abspath( cvsignorePath ) )
#if __name__ == '__main__':
# os.path.walk(sys.argv[1], lister, None) # dir name in cmdline
lines = [ 'SunWS_cache', 'ir.out' ]
os.path.walk( ".", listCVSIgnore, lines )
|