-
Notifications
You must be signed in to change notification settings - Fork 9
/
strip-cvs-keywords.py
executable file
·77 lines (66 loc) · 1.58 KB
/
strip-cvs-keywords.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
"""
Python script to remove CVS keywords from a whole tree of files.
Locates the files and uses Sed to do the hard work.
"""
import os
import subprocess
import sys
# List of file extensions we want to work with.
EXTENSIONS = (
'.conf',
'.css',
'.drush',
'.htm',
'.html',
'.inc',
'.info',
'.ini',
'.install',
'.js',
'.module',
'.mysql',
'.pgsql',
'.php',
'.pl',
'.po',
'.pot',
'.profile',
'.sh',
'.sql',
'.template',
'.test',
'.theme',
'.tpl',
'.txt',
'.xml',
'.xhtml',
)
FILE_NAMES = (
'INSTALL',
'README',
'readme',
)
SED_FILE = os.path.join(os.path.dirname(__file__), 'strip-cvs-keywords.sed')
def main():
try:
# If a dirname is passed as the first parameter, use that.
path = os.path.realpath(sys.argv[1])
except IndexError:
# Fall back on the current working directory.
path = os.getcwd()
if not os.path.isdir(path):
sys.exit('"%s" is not a directory.' % path)
for root, dirs, files in os.walk(path):
# Don't mess with VCS files.
if 'CVS' in dirs:
dirs.remove('CVS')
if '.git' in dirs:
dirs.remove('.git')
for filename in files:
name, extension = os.path.splitext(filename)
if extension.lower() in EXTENSIONS or name in FILE_NAMES:
abs_path = os.path.realpath(os.path.join(path, root, filename))
subprocess.Popen(('sed', '-i', '-f', SED_FILE, abs_path))
if __name__ == "__main__":
main()