Changelog update.
[debian_buildbot.git] / apidocs / epyrun
bloba1ce067e41a068c2bd0032ab41f0fe2f55666f1c
1 #!/usr/bin/env python
3 import sys
4 import os
6 from twisted.python import reflect
7 from twisted.internet import reactor
9 # epydoc
10 import epydoc
11 from epydoc.cli import cli
13 if epydoc.__version__[0] == '2':
14 # Fix support for epydoc 2.x. Unneeded for 3.x
15 class FakeModule:
16 def __init__(self, name, level):
17 self.__level = level
18 self.__name__ = name
20 def __repr__(self):
21 return '<Fake %s>' % self.__name__
22 __str__ = __repr__
24 def __nonzero__(self):
25 return 1
27 def __call__(self, *args, **kw):
28 pass #print 'Called:', args
30 def __getattr__(self, attr):
31 if self.__level == 0:
32 raise AttributeError
33 return FakeModule(self.__name__+'.'+attr, self.__level-1)
35 def __cmp__(self, other):
36 if not hasattr(other, '___name__'):
37 return -1
38 return cmp(self.__name__, other.__name__)
41 def fakeOut(modname):
42 modpath = modname.split('.')
43 prevmod = None
44 for m in range(len(modpath)):
45 mp = '.'.join(modpath[:m+1])
46 nm = FakeModule(mp, 4)
47 if prevmod:
48 setattr(prevmod, modpath[m], nm)
49 sys.modules[mp] = nm
50 prevmod = nm
52 #fakeOut("twisted")
54 # HACK: Another "only doc what we tell you". We don't want epydoc to
55 # automatically recurse into subdirectories: "twisted"'s presence was
56 # causing "twisted/test" to be docced, even thought we explicitly
57 # didn't put any twisted/test in our modnames.
59 from epydoc import imports
60 orig_find_modules = imports.find_modules
62 import re
64 def find_modules(dirname):
65 if not os.path.isdir(dirname): return []
66 found_init = 0
67 modules = {}
68 dirs = []
70 # Search for directories & modules, and check for __init__.py.
71 # Don't include duplicates (like foo.py and foo.pyc), and give
72 # precedance to the .py files.
73 for file in os.listdir(dirname):
74 filepath = os.path.join(dirname, file)
75 if os.path.isdir(filepath): dirs.append(filepath)
76 elif not re.match(r'\w+.py.?', file):
77 continue # Ignore things like ".#foo.py" or "a-b.py"
78 elif file[-3:] == '.py':
79 modules[file] = os.path.join(dirname, file)
80 if file == '__init__.py': found_init = 1
81 elif file[-4:-1] == '.py':
82 modules.setdefault(file[:-1], file)
83 if file[:-1] == '__init__.py': found_init = 1
84 modules = modules.values()
86 # If there was no __init__.py, then this isn't a package
87 # directory; return nothing.
88 if not found_init: return []
90 # Recurse to the child directories.
91 # **twisted** here's the change: commented next line out
92 #for d in dirs: modules += find_modules(d)
93 return modules
95 imports.find_modules = find_modules
98 # Now, set up the list of modules for epydoc to document
99 modnames = []
100 def addMod(arg, path, files):
101 for fn in files:
102 file = os.path.join(path, fn).replace('%s__init__'%os.sep, '')
103 if file.count('%stest%s' % (os.sep,os.sep)): continue
104 if file.count('%sbroken_test%s' % (os.sep,os.sep)): continue
105 if file[-3:] == '.py':
106 modName = file[:-3].replace(os.sep,'.')
107 try:
108 #print 'pre-loading', modName
109 reflect.namedModule(modName)
110 except ImportError, e:
111 print 'import error:', modName, e
112 except Exception, e:
113 print 'other error:', modName, e
114 else:
115 modnames.append(modName)
117 def main():
118 document_all = True # are we doing a full build?
119 names = ['buildbot/'] #default, may be overriden below
121 #get list of modules/pkgs on cmd-line
122 try:
123 i = sys.argv.index("--modules")
124 except:
125 pass
126 else:
127 names = sys.argv[i+1:]
128 document_all = False
129 sys.argv[i:] = []
130 #sanity check on names
131 for i in range(len(names)):
132 try:
133 j = names[i].rindex('buildbot/')
134 except:
135 raise SystemExit, 'You can only specify buildbot modules or packages'
136 else:
137 #strip off any leading directories before the 'twisted/'
138 #dir. this makes it easy to specify full paths, such as
139 #from TwistedEmacs
140 names[i] = names[i][j:]
142 old_out_dir = "html"
143 #if -o was specified, we need to change it to point to a tmp dir
144 #otherwise add our own -o option
145 try:
146 i = sys.argv.index('-o')
147 old_out_dir = sys.argv[i+1]
148 try:
149 os.mkdir(tmp_dir)
150 except OSError:
151 pass
152 sys.argv[i+1] = tmp_dir
153 except ValueError:
154 sys.argv[1:1] = ['-o', tmp_dir]
156 osrv = sys.argv
157 sys.argv=["IGNORE"]
159 for name in names:
160 if name.endswith(".py"):
161 # turn it in to a python module name
162 name = name[:-3].replace(os.sep, ".")
163 try:
164 reflect.namedModule(name)
165 except ImportError:
166 print 'import error:', name
167 except:
168 print 'other error:', name
169 else:
170 modnames.append(name)
171 else: #assume it's a dir
172 os.path.walk(name, addMod, None)
174 sys.argv = osrv
176 if 'buildbot.test' in modnames:
177 modnames.remove('buildbot.test')
178 if 'buildbot.broken_test' in modnames:
179 modnames.remove('buildbot.broken_test')
180 ##if 'twisted' in modnames:
181 ## modnames.remove('twisted')
183 sys.argv.extend(modnames)
185 import buildbot
187 sys.argv[1:1] = [
188 '-n', 'BuildBot %s' % buildbot.version,
189 '-u', 'http://buildbot.net/trac', '--no-private']
191 # Make it easy to profile epyrun
192 if 0:
193 import profile
194 profile.run('cli()', 'epyrun.prof')
195 else:
196 cli()
198 print 'Done!'
201 if __name__ == '__main__':
202 main()