Updated xmlrpc patch to address comments
[buildbot.git] / docs / epyrun
blobdb60b5a2870ee4dfba98177916c30d2c78a26ad7
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 assert epydoc.__version__[0] == '2', "You need epydoc 2.x!"
12 from epydoc.cli import cli
14 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
99 # Now, set up the list of modules for epydoc to document
100 modnames = []
101 def addMod(arg, path, files):
102 for fn in files:
103 file = os.path.join(path, fn).replace('%s__init__'%os.sep, '')
104 if file[-3:] == '.py' and not file.count('%stest%s' % (os.sep,os.sep)):
105 modName = file[:-3].replace(os.sep,'.')
106 try:
107 #print 'pre-loading', modName
108 reflect.namedModule(modName)
109 except ImportError, e:
110 print 'import error:', modName, e
111 except Exception, e:
112 print 'other error:', modName, e
113 else:
114 modnames.append(modName)
116 document_all = True # are we doing a full build?
117 names = ['buildbot/'] #default, may be overriden below
119 #get list of modules/pkgs on cmd-line
120 try:
121 i = sys.argv.index("--modules")
122 except:
123 pass
124 else:
125 names = sys.argv[i+1:]
126 document_all = False
127 sys.argv[i:] = []
128 #sanity check on names
129 for i in range(len(names)):
130 try:
131 j = names[i].rindex('buildbot/')
132 except:
133 raise SystemExit, 'You can only specify buildbot modules or packages'
134 else:
135 #strip off any leading directories before the 'twisted/'
136 #dir. this makes it easy to specify full paths, such as
137 #from TwistedEmacs
138 names[i] = names[i][j:]
140 old_out_dir = "html"
141 #if -o was specified, we need to change it to point to a tmp dir
142 #otherwise add our own -o option
143 try:
144 i = sys.argv.index('-o')
145 old_out_dir = sys.argv[i+1]
146 try:
147 os.mkdir(tmp_dir)
148 except OSError:
149 pass
150 sys.argv[i+1] = tmp_dir
151 except ValueError:
152 sys.argv[1:1] = ['-o', tmp_dir]
154 osrv = sys.argv
155 sys.argv=["IGNORE"]
157 for name in names:
158 if name.endswith(".py"):
159 # turn it in to a python module name
160 name = name[:-3].replace(os.sep, ".")
161 try:
162 reflect.namedModule(name)
163 except ImportError:
164 print 'import error:', name
165 except:
166 print 'other error:', name
167 else:
168 modnames.append(name)
169 else: #assume it's a dir
170 os.path.walk(name, addMod, None)
172 sys.argv = osrv
174 if 'buildbot.test' in modnames:
175 modnames.remove('buildbot.test')
176 ##if 'twisted' in modnames:
177 ## modnames.remove('twisted')
179 sys.argv.extend(modnames)
181 import buildbot
184 sys.argv[1:1] = [
185 '-n', 'BuildBot %s' % buildbot.version,
186 '-u', 'http://buildbot.sourceforge.net/', '--no-private']
188 # Make it easy to profile epyrun
189 if 0:
190 import profile
191 profile.run('cli()', 'epyrun.prof')
192 else:
193 cli()
195 print 'Done!'