-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_manifest.py
81 lines (62 loc) · 2.35 KB
/
build_manifest.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
77
78
79
80
81
import os, os.path
FORBIDDEN_EXTENSIONS = [
'.pyc', '.pyo', # Python bytecode
'.marks', # jEdit bookmark files
'.map', # Created automatically by the DMD compiler; needn't distribute.
'.swp', # Vim swap files
'~', # Vim backup files
]
FORBIDDEN_DIRECTORIES = [
lambda d: d.lower() in ('.svn', '.git', '.hg', 'cvs', 'build', 'dist'),
lambda d: d.startswith('__'),
]
INCLUDE_ONLY_IN_SOURCE_DISTRIBUTION = [
'build_manifest.py',
'setup.py',
]
EXCLUDE_PATHS = [
'MANIFEST',
'.gitignore',
]
def buildManifest(outputStream, isForSourceDist):
includedPaths, excludedPaths = listFiles(isForSourceDist)
for path in includedPaths:
# print >> outputStream, 'include "%s"' % convertPathToDistutilsStandard(path)
print >> outputStream, convertPathToDistutilsStandard(path)
def convertPathToDistutilsStandard(path):
return path.replace(os.sep, '/')
def listFiles(isForSourceDist):
curDirAndSep = os.curdir + os.sep
includedPaths = []
excludedPaths = []
for rootPath, dirs, files in os.walk(os.curdir):
if rootPath.startswith(os.curdir + os.sep):
rootPath = rootPath[len(os.curdir + os.sep):]
elif rootPath.startswith(os.curdir):
rootPath = rootPath[len(os.curdir):]
# The os.walk interface specifies that destructively modifying dirs
# will influence which subdirs are visited, so we determine which
# subdirs are forbidden and remove them from dirs.
for subDir in dirs[:]:
for filterFunc in FORBIDDEN_DIRECTORIES:
if filterFunc(subDir):
dirs.remove(subDir)
for f in sorted(files):
fPath = os.path.join(rootPath, f)
if any(f.endswith(ext) for ext in FORBIDDEN_EXTENSIONS):
excludedPaths.append(fPath)
else:
includedPaths.append(fPath)
if not isForSourceDist:
for path in INCLUDE_ONLY_IN_SOURCE_DISTRIBUTION:
if path in includedPaths:
includedPaths.remove(path)
excludedPaths.append(path)
for path in EXCLUDE_PATHS:
if path in includedPaths:
includedPaths.remove(path)
excludedPaths.append(path)
return includedPaths, excludedPaths
if __name__ == '__main__':
import sys
buildManifest(sys.stdout, True)