| | 75 | |
|---|
| | 76 | def projectURL(projectName): |
|---|
| | 77 | """ |
|---|
| | 78 | """ |
|---|
| | 79 | return "/trac/%s/wiki/Start_%s" % (projectName, projectName) |
|---|
| | 80 | |
|---|
| | 81 | |
|---|
| | 82 | class API(object): |
|---|
| | 83 | """ |
|---|
| | 84 | """ |
|---|
| | 85 | def __init__(self, vhostPath, projectName, request): |
|---|
| | 86 | self.packageName = projectName.lower().replace("-", "_") |
|---|
| | 87 | path = "/api/%s/%s.html" % (projectName, self.packageName) |
|---|
| | 88 | newURL = (request.scheme, request.host, path, '', '', '') |
|---|
| | 89 | filePath = ospath.join(vhostPath, newURL[2].lstrip("/")) |
|---|
| | 90 | if ospath.exists(filePath): |
|---|
| | 91 | d = defer.succeed(None) |
|---|
| | 92 | else: |
|---|
| | 93 | tmpDir = tempfile.mkdtemp() |
|---|
| | 94 | d = self.svn(tmpDir, projectName) |
|---|
| | 95 | d.addCallback( |
|---|
| | 96 | lambda _: self.pydoctor(tmpDir, vhostPath, projectName)) |
|---|
| | 97 | d.addCallback(lambda _: shutil.rmtree(tmpDir)) |
|---|
| | 98 | d.addCallback(lambda _: (resource.RedirectResource(*newURL), ())) |
|---|
| | 99 | self.d = d |
|---|
| | 100 | |
|---|
| | 101 | def executable(self, name): |
|---|
| | 102 | """ |
|---|
| | 103 | """ |
|---|
| | 104 | result = procutils.which(name)[0] |
|---|
| | 105 | if not result: |
|---|
| | 106 | raise ImportError("Can't locate %s executable" % name) |
|---|
| | 107 | |
|---|
| | 108 | def svn(self, tmpDir, vhostPath, projectName): |
|---|
| | 109 | """ |
|---|
| | 110 | TODO |
|---|
| | 111 | """ |
|---|
| | 112 | return defer.succeed(None) |
|---|
| | 113 | |
|---|
| | 114 | def pydoctor(self, tmpDir, vhostPath, projectName): |
|---|
| | 115 | """ |
|---|
| | 116 | TODO |
|---|
| | 117 | """ |
|---|
| | 118 | return |
|---|
| | 119 | # TODO: Nothing below does anything yet |
|---|
| | 120 | args = [ |
|---|
| | 121 | "--add-package=%s" % self.packageName, |
|---|
| | 122 | "--project-name=%s" % projectName, |
|---|
| | 123 | "--make-html", |
|---|
| | 124 | "--html-output=%s/api/%s" % (vhostPath, projectName), |
|---|
| | 125 | "--project-url=%s" % projectURL(projectName)] |
|---|
| | 126 | return util.getProcessValue( |
|---|
| | 127 | self.executable('pydoctor'), args=args, path=tmpDir) |
|---|
| | 128 | |
|---|
| 187 | | elif section == 'browser': |
|---|
| 188 | | extendRequest('projects', self._reformat(projectName), 'trunk') |
|---|
| 189 | | elif section == 'api': |
|---|
| 190 | | subSegments.append("classIndex.html") |
|---|
| 191 | | if subSegments[0] == 'api': |
|---|
| 192 | | return self.apiResource(projectName, subSegments[1]), () |
|---|
| 193 | | else: |
|---|
| 194 | | possibleResult = self._possibleStatic('trac', *subSegments) |
|---|
| 195 | | if possibleResult: |
|---|
| 196 | | return possibleResult, () |
|---|
| | 242 | elif root == 'browser': |
|---|
| | 243 | extendRequest('projects', projectName.lower(), 'trunk') |
|---|
| | 244 | elif root == 'api': |
|---|
| | 245 | return API(self.vhostPath, projectName, request).d |
|---|
| | 246 | possibleResult = self._possibleStatic('trac', *subSegments) |
|---|
| | 247 | if possibleResult: |
|---|
| | 248 | return possibleResult, () |
|---|
| 198 | | |
|---|
| 199 | | def apiResource(self, projectName, fileName): |
|---|
| 200 | | """ |
|---|
| 201 | | Returns a L{static.File} child resource directed to an API document for |
|---|
| 202 | | the specified project, dynamically generating the document with |
|---|
| 203 | | pyDoctor as needed. |
|---|
| 204 | | |
|---|
| 205 | | TODO: SVN export, pydoctor, static.File(...), temp file cleanup |
|---|
| 206 | | """ |
|---|
| 207 | | projectDir = self._reformat(projectName) |
|---|
| 208 | | return self._possibleStatic('api', projectDir, fileName) |
|---|