~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/launchpad_loggerhead/app.py

Merged db-devel into replication.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
import os
6
6
import threading
7
7
import urllib
 
8
import urllib2
8
9
import urlparse
9
10
import xmlrpclib
10
11
 
187
188
        lp_server = get_lp_server(user, branch_transport=self.get_transport())
188
189
        lp_server.start_server()
189
190
        try:
 
191
 
190
192
            try:
191
193
                transport_type, info, trail = self.branchfs.translatePath(
192
194
                    user, urlutils.escape(path))
236
238
            if not os.path.isdir(cachepath):
237
239
                os.makedirs(cachepath)
238
240
            self.log.info('branch_url: %s', branch_url)
 
241
            branch_api_url = urlparse.urljoin(
 
242
                config.appserver_root_url('api'), 'devel', branch_name)
 
243
            self.log.info('branch_api_url: %s', branch_api_url)
 
244
            req = urllib2.Request(branch_api_url)
 
245
            private = False
 
246
            try:
 
247
                # We need to determine if the branch is private
 
248
                response = urllib2.urlopen(req)
 
249
            except urllib2.HTTPError as response:
 
250
                if response.getcode() in (400, 403):
 
251
                    ## 400 and 403 are the possible returns for api requests
 
252
                    ## on a private branch without authentication.
 
253
                    self.log.info("Branch is private")
 
254
                    private = True
 
255
                self.log.info(
 
256
                    "Branch state not determined; api error, return code: %s",
 
257
                    response.getcode())
 
258
            else:
 
259
                self.log.info("Branch is public")
 
260
 
239
261
            try:
240
262
                bzr_branch = safe_open(
241
263
                    lp_server.get_url().strip(':/'), branch_url)
247
269
                view = BranchWSGIApp(
248
270
                    bzr_branch, branch_name, {'cachepath': cachepath},
249
271
                    self.graph_cache, branch_link=branch_link,
250
 
                    served_url=None)
 
272
                    served_url=None, private=private)
251
273
                return view.app(environ, start_response)
252
274
            finally:
253
275
                bzr_branch.unlock()