root/trunk/build_manifest.py

Revision 26, 2.3 kB (checked in by KirkMcDonald, 2 years ago)

Function wrapping improvements, and some automatic operator overload wrapping.

Line 
1 import os, os.path
2
3
4 FORBIDDEN_EXTENSIONS = [
5     '.pyc', '.pyo', # Python bytecode
6     '.marks', # jEdit bookmark files
7     '.map', # Created automatically by the DMD compiler; needn't distribute.
8     '.swp', # Vim swap files
9   ]
10
11 FORBIDDEN_DIRECTORIES = [
12     lambda d: d.lower() in ('.svn', 'cvs', 'build', 'dist'),
13     lambda d: d.startswith('__'),
14   ]
15
16 INCLUDE_ONLY_IN_SOURCE_DISTRIBUTION = [
17     'build_manifest.py',
18     'setup.py',
19   ]
20
21 EXCLUDE_PATHS = [
22     'MANIFEST',
23   ]
24
25
26 def buildManifest(outputStream, isForSourceDist):
27     includedPaths, excludedPaths = listFiles(isForSourceDist)
28     for path in includedPaths:
29         # print >> outputStream, 'include "%s"' % convertPathToDistutilsStandard(path)
30         print >> outputStream, convertPathToDistutilsStandard(path)
31
32
33 def convertPathToDistutilsStandard(path):
34     return path.replace(os.sep, '/')
35
36
37 def listFiles(isForSourceDist):
38     curDirAndSep = os.curdir + os.sep
39
40     includedPaths = []
41     excludedPaths = []
42     for rootPath, dirs, files in os.walk(os.curdir):
43         if rootPath.startswith(os.curdir + os.sep):
44             rootPath = rootPath[len(os.curdir + os.sep):]
45         elif rootPath.startswith(os.curdir):
46             rootPath = rootPath[len(os.curdir):]
47
48         # The os.walk interface specifies that destructively modifying dirs
49         # will influence which subdirs are visited, so we determine which
50         # subdirs are forbidden and remove them from dirs.
51         for subDir in dirs[:]:
52             for filterFunc in FORBIDDEN_DIRECTORIES:
53                 if filterFunc(subDir):
54                     dirs.remove(subDir)
55
56         for f in sorted(files):
57             fPath = os.path.join(rootPath, f)
58             if os.path.splitext(f)[1].lower() in FORBIDDEN_EXTENSIONS:
59                 excludedPaths.append(fPath)
60             else:
61                 includedPaths.append(fPath)
62
63     if not isForSourceDist:
64         for path in INCLUDE_ONLY_IN_SOURCE_DISTRIBUTION:
65             if path in includedPaths:
66                 includedPaths.remove(path)
67                 excludedPaths.append(path)
68
69     for path in EXCLUDE_PATHS:
70         if path in includedPaths:
71             includedPaths.remove(path)
72             excludedPaths.append(path)
73
74     return includedPaths, excludedPaths
75
76
77 if __name__ == '__main__':
78     import sys
79     buildManifest(sys.stdout, True)
Note: See TracBrowser for help on using the browser.