Merge lp:~leonardr/launchpad/multiversion-wadl into lp:launchpad/db-devel

Proposed by Leonard Richardson
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~leonardr/launchpad/multiversion-wadl
Merge into: lp:launchpad/db-devel
Diff against target: 483 lines (+168/-95)
9 files modified
Makefile (+17/-9)
configs/development/launchpad-lazr.conf (+1/-1)
configs/testrunner-appserver/launchpad-lazr.conf (+1/-1)
configs/testrunner/launchpad-lazr.conf (+1/-1)
lib/canonical/launchpad/doc/webapp-publication.txt (+1/-1)
lib/canonical/launchpad/pagetests/webservice/xx-wadl.txt (+43/-17)
lib/canonical/launchpad/systemhomes.py (+35/-32)
lib/lp/code/stories/webservice/xx-branchmergeproposal.txt (+37/-18)
utilities/create-lp-wadl.py (+32/-15)
To merge this branch: bzr merge lp:~leonardr/launchpad/multiversion-wadl
Reviewer Review Type Date Requested Status
Gary Poster (community) Approve
Tim Penhey (community) release-critical Approve
Review via email: mp+20405@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Leonard Richardson (leonardr) wrote :

This branch changes the build process so that it generates a static WADL file for every version of the web service, not just one file. There were a number of parts of this system that I didn't understand and might not be necessary anymore (mainly the fake 'development' WADL file, which only seems to get in the way), but I left them alone rather than make this branch more complex.

Revision history for this message
Gary Poster (gary) wrote :

Thank you, Leonard.

review: Approve
Revision history for this message
Tim Penhey (thumper) :
review: Approve (release-critical)
Revision history for this message
Leonard Richardson (leonardr) wrote :

This needs another review. Two tests failed when I ran the ec2 suite. Both of them were fallout from when I changed the 'api' vhost's root url from "http://api.launchpad.dev/beta/" to "http://api.launchpad.dev/".

The fix to webapp-publication.txt was trivial. The fix to xx-branchmergeproposal.txt was not. canonical_url() had no idea how to incorporate the version of a web service request, and the test wasn't specifying which version of the web service was desired. I had to make canonical_url work when passed a versioned web service request, and then change the test to create a versioned request and pass it into canonical_url.

ec2 test is running again and will hopefully come up roses in the morning.

Revision history for this message
Leonard Richardson (leonardr) wrote :
Revision history for this message
Leonard Richardson (leonardr) wrote :

OK, one more. My earlier fix to xx-branchmergeproposal broke a whole lot of other tests because it changed the ways all URLs were generated, just for the sake of one test. This update reverts the change to canonical_url() and instead changes xx-branchmergeproposal to use the standard way of generating web service URLs from a browser-initiated request.

The problem here is that the web service URLs generated by a browser-initiated request look like "http://launchpad.dev/api/". Ordinarily this is fine, but xx-branchmergeproposal generates URLs from a browser-initiated request and then passes them into a web service client that expects URLs that look like "http://api.launchpad.dev/". Rather than try to come up with a standard way of doing this, I created a helper method in the test that does the translation.

This branch also upgrades the version of lazr.restful used. I'm not 100% sure that this new version of lazr.restful is necessary, and I'm going to do some preliminary tests with the old version before landing.

Incremental diff: http://pastebin.ubuntu.com/387107/

Revision history for this message
Leonard Richardson (leonardr) wrote :

I should mention that I'm still trying to track down a launchpadlib test failure.

Revision history for this message
Gary Poster (gary) wrote :

r10428 and r10429 approved. I'd like fix_url to be removed eventually, but I'll not worry about it now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2010-02-19 22:02:36 +0000
3+++ Makefile 2010-03-03 00:11:15 +0000
4@@ -28,8 +28,10 @@
5
6 BZR_VERSION_INFO = bzr-version-info.py
7
8-WADL_FILE = lib/canonical/launchpad/apidoc/wadl-$(LPCONFIG).xml
9-API_INDEX = lib/canonical/launchpad/apidoc/index.html
10+APIDOC_DIR = lib/canonical/launchpad/apidoc
11+WADL_TEMPLATE = $(APIDOC_DIR).tmp/wadl-$(LPCONFIG)-%(version)s.xml
12+DEVEL_WADL_FILE = $(APIDOC_DIR)/wadl-$(LPCONFIG)-devel.xml
13+API_INDEX = $(APIDOC_DIR)/index.html
14
15 # DO NOT ALTER : this should just build by default
16 default: inplace
17@@ -44,12 +46,14 @@
18 hosted_branches: $(PY)
19 $(PY) ./utilities/make-dummy-hosted-branches
20
21-$(WADL_FILE): $(BZR_VERSION_INFO)
22- LPCONFIG=$(LPCONFIG) $(PY) ./utilities/create-lp-wadl.py > $@.tmp
23- mv $@.tmp $@
24+$(DEVEL_WADL_FILE): $(BZR_VERSION_INFO)
25+ mkdir $(APIDOC_DIR).tmp
26+ LPCONFIG=$(LPCONFIG) $(PY) ./utilities/create-lp-wadl.py "$(WADL_TEMPLATE)"
27+ mv $(APIDOC_DIR).tmp/* $(APIDOC_DIR)
28+ rmdir $(APIDOC_DIR).tmp
29
30-$(API_INDEX): $(WADL_FILE)
31- bin/apiindex $(WADL_FILE) > $@.tmp
32+$(API_INDEX): $(DEVEL_WADL_FILE)
33+ bin/apiindex $(DEVEL_WADL_FILE) > $@.tmp
34 mv $@.tmp $@
35
36 apidoc: compile $(API_INDEX)
37@@ -240,7 +244,7 @@
38 $(BZR_VERSION_INFO):
39 scripts/update-bzr-version-info.sh
40
41-support_files: $(WADL_FILE) $(BZR_VERSION_INFO)
42+support_files: $(DEVEL_WADL_FILE) $(BZR_VERSION_INFO)
43
44 # Intended for use on developer machines
45 start: inplace stop support_files initscript-start
46@@ -309,7 +313,11 @@
47 $(RM) -r lib/mailman
48 $(RM) -rf lib/canonical/launchpad/icing/build/*
49 $(RM) -r $(CODEHOSTING_ROOT)
50- $(RM) $(WADL_FILE) $(API_INDEX)
51+ mv $(APIDOC_DIR)/wadl-testrunner-devel.xml \
52+ $(APIDOC_DIR)/wadl-testrunner-devel.xml.bak
53+ $(RM) $(APIDOC_DIR)/wadl*.xml $(API_INDEX)
54+ mv $(APIDOC_DIR)/wadl-testrunner-devel.xml.bak \
55+ $(APIDOC_DIR)/wadl-testrunner-devel.xml
56 $(RM) $(BZR_VERSION_INFO)
57 $(RM) _pythonpath.py
58 $(RM) -rf \
59
60=== modified file 'configs/development/launchpad-lazr.conf'
61--- configs/development/launchpad-lazr.conf 2010-02-24 05:00:02 +0000
62+++ configs/development/launchpad-lazr.conf 2010-03-03 00:11:15 +0000
63@@ -262,7 +262,7 @@
64
65 [vhost.api]
66 hostname: api.launchpad.dev
67-rooturl: https://api.launchpad.dev/beta/
68+rooturl: https://api.launchpad.dev/
69
70 [vhost.blueprints]
71 hostname: blueprints.launchpad.dev
72
73=== modified file 'configs/testrunner-appserver/launchpad-lazr.conf'
74--- configs/testrunner-appserver/launchpad-lazr.conf 2010-02-12 19:34:42 +0000
75+++ configs/testrunner-appserver/launchpad-lazr.conf 2010-03-03 00:11:15 +0000
76@@ -23,7 +23,7 @@
77 rooturl: http://launchpad.dev:8085/
78
79 [vhost.api]
80-rooturl: http://api.launchpad.dev:8085/beta/
81+rooturl: http://api.launchpad.dev:8085/
82
83 [vhost.blueprints]
84 rooturl: http://blueprints.launchpad.dev:8085/
85
86=== modified file 'configs/testrunner/launchpad-lazr.conf'
87--- configs/testrunner/launchpad-lazr.conf 2010-02-24 05:00:02 +0000
88+++ configs/testrunner/launchpad-lazr.conf 2010-03-03 00:11:15 +0000
89@@ -229,7 +229,7 @@
90 rooturl: http://launchpad.dev/
91
92 [vhost.api]
93-rooturl: http://api.launchpad.dev/beta/
94+rooturl: http://api.launchpad.dev/
95
96 [vhosts]
97 use_https: False
98
99=== renamed file 'lib/canonical/launchpad/apidoc/wadl-testrunner.xml' => 'lib/canonical/launchpad/apidoc/wadl-testrunner-devel.xml'
100=== modified file 'lib/canonical/launchpad/doc/webapp-publication.txt'
101--- lib/canonical/launchpad/doc/webapp-publication.txt 2010-02-12 19:34:42 +0000
102+++ lib/canonical/launchpad/doc/webapp-publication.txt 2010-03-03 00:11:15 +0000
103@@ -38,7 +38,7 @@
104 althosts:
105 ----
106 api @ api.launchpad.dev
107- rooturl: http://api.launchpad.dev/beta/
108+ rooturl: http://api.launchpad.dev/
109 althosts:
110 ----
111 blueprints @ blueprints.launchpad.dev
112
113=== modified file 'lib/canonical/launchpad/pagetests/webservice/xx-wadl.txt'
114--- lib/canonical/launchpad/pagetests/webservice/xx-wadl.txt 2009-08-20 04:46:48 +0000
115+++ lib/canonical/launchpad/pagetests/webservice/xx-wadl.txt 2010-03-03 00:11:15 +0000
116@@ -1,16 +1,18 @@
117 = Launchpad's WADL caching =
118
119-Because Launchpad's main WADL file is so big, we cache it internally.
120-Because it only changes when the Launchpad software changes, it is
121-cached to a file. Right now, the Launchpad webservice serves a
122-special test file (canonical/launchpad/apidoc/wadl-testrunner.xml)
123-when a client asks for the big WADL definition. It was loaded on
124-module import using the canonical.config.config.instance_name, so a
125-development instance will use the file
126-canonical/launchpad/apidoc/wadl-development.xml.
127+Because Launchpad's main WADL files are so big, we cache them
128+internally: one WADL file for every version of the web service.
129+Because the WADL only changes when the Launchpad software changes,
130+these documents are cached to files. Right now, the Launchpad
131+webservice serves a special test file
132+(canonical/launchpad/apidoc/wadl-testrunner-devel.xml) when a client
133+asks for the big WADL definition for the 'devel' version. The
134+'testrunner' part comes from canonical.config.config.instance_name, so
135+a development instance will use the file
136+canonical/launchpad/apidoc/wadl-development-{version}.xml.
137
138 >>> test_wadl = webservice.get(
139- ... '/', 'application/vd.sun.wadl+xml').body
140+ ... '/', 'application/vd.sun.wadl+xml', api_version='devel').body
141 >>> print test_wadl
142 <?xml version="1.0"?>
143 <wadl:application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
144@@ -24,15 +26,16 @@
145 </wadl:application>
146 <BLANKLINE>
147
148-Let's look at the real contents, though. To do this, we need to do
149-what utilities/create-lp-wadl.py does: clear out the cache on the
150-class.
151+Let's look at the real contents, though. To do this, we need to
152+deactivate the cache. Simply clearing it out will just cause it to be
153+filled up again.
154
155 >>> from canonical.launchpad.systemhomes import WebServiceApplication
156+ >>> old_cached_wadl = WebServiceApplication.cached_wadl
157 >>> WebServiceApplication.cached_wadl = None
158
159 >>> wadl = webservice.get(
160- ... '/', 'application/vd.sun.wadl+xml').body
161+ ... '/', 'application/vd.sun.wadl+xml', api_version='devel').body
162 >>> wadl = wadl.decode('UTF-8')
163
164 The real file is much bigger than the test file.
165@@ -40,15 +43,38 @@
166 >>> len(wadl) > len(test_wadl)
167 True
168
169-The new output is now cached on the WebServiceApplication class.
170-
171- >>> WebServiceApplication.cached_wadl == wadl
172+The WADL we received is keyed to the 'devel' version of the web
173+service. This version will always be present.
174+
175+ >>> 'http://api.launchpad.dev/devel/' in wadl
176+ True
177+
178+If we retrieve the WADL for the '1.0' version of the web service,
179+we'll get a document keyed to the '1.0' version. The '1.0' version
180+will be deprecated along with the Lucid release of Ubuntu.
181+
182+ >>> wadl_10 = webservice.get(
183+ ... '/', 'application/vd.sun.wadl+xml', api_version='1.0').body
184+ >>> wadl_10 = wadl_10.decode('UTF-8')
185+
186+ >>> 'http://api.launchpad.dev/1.0/' in wadl_10
187+ True
188+
189+If we retrieve the WADL for the 'beta' version of the web service,
190+we'll get a document keyed to the 'beta' version. The '1.0' version
191+will be deprecated along with the Karmic release of Ubuntu.
192+
193+ >>> wadl_beta = webservice.get(
194+ ... '/', 'application/vd.sun.wadl+xml', api_version='beta').body
195+ >>> wadl_beta = wadl_beta.decode('UTF-8')
196+
197+ >>> 'http://api.launchpad.dev/beta/' in wadl_beta
198 True
199
200 We don't need the cache anymore, so we'll reinstate the testing
201 version. This way, other tests will have a clean slate.
202
203- >>> WebServiceApplication.cached_wadl = test_wadl
204+ >>> WebServiceApplication.cached_wadl = old_cached_wadl
205
206 Like all lazr.restful applications, Launchpad's web service generates
207 valid WADL.
208
209=== modified file 'lib/canonical/launchpad/systemhomes.py'
210--- lib/canonical/launchpad/systemhomes.py 2010-02-16 14:07:17 +0000
211+++ lib/canonical/launchpad/systemhomes.py 2010-03-03 00:11:15 +0000
212@@ -343,15 +343,8 @@
213 class WebServiceApplication(ServiceRootResource):
214 """See `IWebServiceApplication`.
215
216- This implementation adds a 'cached_wadl' attribute. If set, it will be
217- served by `toWADL` rather than calculating the toWADL result.
218-
219- On import, the class tries to load a file to populate this attribute. By
220- doing it on import, this makes it easy to clear, as is needed by
221- utilities/create-lp-wadl.py.
222-
223- If the attribute is not set, toWADL will set the attribute on the class
224- once it is calculated.
225+ This implementation adds a 'cached_wadl' attribute, which starts
226+ out as an empty dict and is populated as needed.
227 """
228 implements(IWebServiceApplication, ICanonicalUrlData)
229
230@@ -359,31 +352,41 @@
231 path = ''
232 rootsite = None
233
234- _wadl_filename = os.path.join(
235- os.path.dirname(os.path.normpath(__file__)),
236- 'apidoc', 'wadl-%s.xml' % config.instance_name)
237-
238- cached_wadl = None
239-
240- # Attempt to load the WADL.
241- _wadl_fd = None
242- try:
243- _wadl_fd = codecs.open(_wadl_filename, encoding='UTF-8')
244- try:
245- cached_wadl = _wadl_fd.read()
246- finally:
247- _wadl_fd.close()
248- except IOError:
249- pass
250- del _wadl_fd
251+ cached_wadl = {}
252
253 def toWADL(self):
254- """See `IWebServiceApplication`."""
255- if self.cached_wadl is not None:
256- return self.cached_wadl
257- wadl = super(WebServiceApplication, self).toWADL()
258- self.__class__.cached_wadl = wadl
259- return wadl
260+ """See `IWebServiceApplication`.
261+
262+ Look for a cached WADL file for the request version at the
263+ location used by the script
264+ utilities/create-launchpad-wadl.py. If the file is present,
265+ load the file and cache its contents rather than generating
266+ new WADL. Otherwise, generate new WADL and cache it.
267+ """
268+ version = self.request.version
269+ if self.__class__.cached_wadl is None:
270+ # The cache has been disabled for testing
271+ # purposes. Generate the WADL.
272+ return super(WebServiceApplication, self).toWADL()
273+ if version not in self.__class__.cached_wadl:
274+ # It's not cached. Look for it on disk.
275+ _wadl_filename = os.path.join(
276+ os.path.dirname(os.path.normpath(__file__)),
277+ 'apidoc', 'wadl-%s-%s.xml' % (config.instance_name, version))
278+
279+ _wadl_fd = None
280+ try:
281+ _wadl_fd = codecs.open(_wadl_filename, encoding='UTF-8')
282+ try:
283+ wadl = _wadl_fd.read()
284+ finally:
285+ _wadl_fd.close()
286+ except IOError:
287+ # It's not on disk; generate it.
288+ wadl = super(WebServiceApplication, self).toWADL()
289+ del _wadl_fd
290+ self.__class__.cached_wadl[version] = wadl
291+ return self.__class__.cached_wadl[version]
292
293
294 class TestOpenIDApplication:
295
296=== modified file 'lib/lp/code/stories/webservice/xx-branchmergeproposal.txt'
297--- lib/lp/code/stories/webservice/xx-branchmergeproposal.txt 2010-02-26 09:54:20 +0000
298+++ lib/lp/code/stories/webservice/xx-branchmergeproposal.txt 2010-03-03 00:11:15 +0000
299@@ -7,13 +7,31 @@
300 >>> from lazr.restful.testing.webservice import pprint_entry
301 >>> login('admin@canonical.com')
302 >>> target = factory.makeBranch()
303- >>> target_url = str(canonical_url(target, rootsite='api'))
304+
305+ >>> from canonical.launchpad.webapp.servers import WebServiceTestRequest
306+ >>> request = WebServiceTestRequest(version="beta")
307+ >>> request.processInputs()
308+
309+ >>> from lazr.restful.utils import get_current_web_service_request
310+ >>> request = get_current_web_service_request()
311+
312+ >>> def fix_url(url):
313+ ... """Convert a browser request to a web service client request.
314+ ... This is a bit of a hack, but it's the simplest way to get a
315+ ... URL that the web service client will respect."""
316+ ... return url.replace("launchpad.dev/api/", "api.launchpad.dev/")
317+
318+ >>> target_url = fix_url(str(canonical_url(
319+ ... target, request=request, rootsite='api')))
320 >>> source = factory.makeBranchTargetBranch(target.target)
321- >>> source_url = str(canonical_url(source, rootsite='api'))
322+ >>> source_url = fix_url(str(
323+ ... canonical_url(source, request=request, rootsite='api')))
324 >>> prerequisite = factory.makeBranchTargetBranch(target.target)
325- >>> prerequisite_url = canonical_url(prerequisite, rootsite='api')
326+ >>> prerequisite_url = fix_url(str(canonical_url(
327+ ... prerequisite, request=request, rootsite='api')))
328 >>> registrant = source.registrant
329- >>> reviewer_url = canonical_url(factory.makePerson(), rootsite='api')
330+ >>> reviewer_url = fix_url(str(canonical_url(
331+ ... factory.makePerson(), request=request, rootsite='api')))
332 >>> logout()
333 >>> registrant_webservice = webservice_for_person(
334 ... registrant, permission=OAuthPermission.WRITE_PUBLIC)
335@@ -28,7 +46,7 @@
336 >>> pprint_entry(bmp)
337 address: u'mp+...@code.launchpad.dev'
338 all_comments_collection_link:
339- u'http://api.launchpad.dev/beta/~.../+merge/.../all_comments'
340+ u'http://api.launchpad.dev/devel/~.../+merge/.../all_comments'
341 commit_message: u'It was merged!\n'
342 date_created: u'...'
343 date_merged: None
344@@ -38,40 +56,40 @@
345 description: u'Merge\nit!'
346 merge_reporter_link: None
347 merged_revno: None
348- prerequisite_branch_link: u'http://api.launchpad.dev/beta/~...'
349+ prerequisite_branch_link: u'http://api.launchpad.dev/devel/~...'
350 preview_diff_link: None
351 private: False
352 queue_position: None
353 queue_status: u'Needs review'
354 queued_revid: None
355 queuer_link: None
356- registrant_link: u'http://api.launchpad.dev/beta/~person-name...'
357+ registrant_link: u'http://api.launchpad.dev/devel/~person-name...'
358 resource_type_link:
359- u'http://api.launchpad.dev/beta/#branch_merge_proposal'
360+ u'http://api.launchpad.dev/devel/#branch_merge_proposal'
361 reviewed_revid: None
362 reviewer_link: None
363- self_link: u'http://api.launchpad.dev/beta/~.../+merge/...'
364- source_branch_link: u'http://api.launchpad.dev/beta/~...'
365+ self_link: u'http://api.launchpad.dev/devel/~.../+merge/...'
366+ source_branch_link: u'http://api.launchpad.dev/devel/~...'
367 superseded_by_link: None
368 supersedes_link: None
369- target_branch_link: u'http://api.launchpad.dev/beta/~...'
370+ target_branch_link: u'http://api.launchpad.dev/devel/~...'
371 votes_collection_link:
372- u'http://api.launchpad.dev/beta/~.../+merge/.../votes'
373+ u'http://api.launchpad.dev/devel/~.../+merge/.../votes'
374
375 Our review request is listed in the votes collection.
376
377 >>> votes = webservice.get(
378 ... bmp['votes_collection_link']).jsonBody()
379 >>> pprint_entry(votes['entries'][0])
380- branch_merge_proposal_link: u'http://api.launchpad.dev/beta/~.../+merge/...'
381+ branch_merge_proposal_link: u'http://api.launchpad.dev/devel/~.../+merge/...'
382 comment_link: None
383 date_created: u'...'
384 is_pending: True
385- registrant_link: u'http://api.launchpad.dev/beta/~person-name...'
386- resource_type_link: u'http://api.launchpad.dev/beta/#code_review_vote_reference'
387+ registrant_link: u'http://api.launchpad.dev/devel/~person-name...'
388+ resource_type_link: u'http://api.launchpad.dev/devel/#code_review_vote_reference'
389 review_type: u'green'
390- reviewer_link: u'http://api.launchpad.dev/beta/~person-name...'
391- self_link: u'http://api.launchpad.dev/beta/~...'
392+ reviewer_link: u'http://api.launchpad.dev/devel/~person-name...'
393+ self_link: u'http://api.launchpad.dev/devel/~...'
394
395
396 == Get an existing merge proposal ==
397@@ -96,7 +114,8 @@
398 ... vote=CodeReviewVote.ABSTAIN, parent=comment,
399 ... merge_proposal=fixit_proposal)
400
401- >>> proposal_url = canonical_url(fixit_proposal, rootsite='api')
402+ >>> proposal_url = fix_url(canonical_url(
403+ ... fixit_proposal, request=request, rootsite='api'))
404 >>> new_person = factory.makePerson()
405 >>> target_owner = fixit_proposal.target_branch.owner
406 >>> logout()
407
408=== modified file 'utilities/create-lp-wadl.py'
409--- utilities/create-lp-wadl.py 2009-10-17 14:06:03 +0000
410+++ utilities/create-lp-wadl.py 2010-03-03 00:11:15 +0000
411@@ -7,12 +7,15 @@
412
413 Usage hint:
414
415-% LPCONFIG="edge" utilities/create-lp-wadl.py > launchpad.wadl
416+% LPCONFIG="edge" utilities/create-lp-wadl.py launchpad-%(version)s.wadl
417 """
418
419 import _pythonpath
420
421 import sys
422+import urlparse
423+
424+from zope.component import getUtility
425
426 from canonical.launchpad.ftests import login, ANONYMOUS
427 from canonical.launchpad.scripts import execute_zcml_for_scripts
428@@ -20,27 +23,41 @@
429 WebServicePublication, WebServiceTestRequest)
430 from canonical.launchpad.webapp.vhosts import allvhosts
431 from canonical.launchpad.systemhomes import WebServiceApplication
432+from lazr.restful.interfaces import IWebServiceConfiguration
433
434-def main():
435+def main(path_template):
436 WebServiceApplication.cached_wadl = None # do not use cached file version
437 execute_zcml_for_scripts()
438+ config = getUtility(IWebServiceConfiguration)
439
440 # Request the WADL from the root resource.
441 # We do this by creating a request object asking for a WADL
442 # representation.
443- request = WebServiceTestRequest(environ={
444- 'SERVER_URL': allvhosts.configs['api'].rooturl,
445- 'HTTP_HOST': allvhosts.configs['api'].hostname,
446- 'HTTP_ACCEPT': 'application/vd.sun.wadl+xml'
447- })
448- # We then bypass the usual publisher processing by associating
449- # the request with the WebServicePublication (usually done by the
450- # publisher) and then calling the root resource - retrieved through
451- # getApplication().
452- request.setPublication(WebServicePublication(None))
453- login(ANONYMOUS, request)
454- print request.publication.getApplication(request)(request)
455+ for version in config.active_versions:
456+ url = urlparse.urljoin(allvhosts.configs['api'].rooturl, version)
457+ request = WebServiceTestRequest(version=version, environ={
458+ 'SERVER_URL': url,
459+ 'HTTP_HOST': allvhosts.configs['api'].hostname,
460+ 'HTTP_ACCEPT': 'application/vd.sun.wadl+xml'
461+ })
462+ # We then bypass the usual publisher processing by associating
463+ # the request with the WebServicePublication (usually done by the
464+ # publisher) and then calling the root resource - retrieved through
465+ # getApplication().
466+ request.setPublication(WebServicePublication(None))
467+ login(ANONYMOUS, request)
468+ filename = path_template % {'version' : version}
469+ print "Writing WADL for version %s to %s." % (version, filename)
470+ f = open(filename, 'w')
471+ content = request.publication.getApplication(request)(request)
472+ f.write(content)
473+ f.close()
474 return 0
475
476 if __name__ == '__main__':
477- sys.exit(main())
478+ if len(sys.argv) != 2:
479+ print "Usage: %s [WADL path template]" % sys.argv[0]
480+ print " Example: %s path/to/wadl/wadl-%%(version).xml" % (
481+ sys.argv[0])
482+ sys.exit(-1)
483+ sys.exit(main(sys.argv[1]))

Subscribers

People subscribed via source and target branches

to status/vote changes: