~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/librarian/web.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-12 19:27:39 UTC
  • mfrom: (13814.2.12 bug-302449)
  • Revision ID: launchpad@pqm.canonical.com-20110912192739-l51qyzomz0dll9nw
[r=bac][bug=302449] Make sure TranslationImportQueue.addOrUpdateEntry
        doesn't hit a DB constraint on (importer, potemplate, path, target).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
__metaclass__ = type
7
7
import time
8
8
from urlparse import urlparse
9
9
 
10
 
from storm.exceptions import DisconnectionError
11
10
from twisted.python import log
12
11
from twisted.web import resource, static, util, server, proxy
13
12
from twisted.internet.threads import deferToThread
27
26
        <h1>Launchpad Librarian</h1>
28
27
        <p>
29
28
        http://librarian.launchpad.net/ is a
30
 
        file repository used by
31
 
        <a href="https://launchpad.net/">Launchpad</a>.
 
29
        file repository used by <a href="https://launchpad.net/">Launchpad</a>.
32
30
        </p>
33
31
        <p><small>Copyright 2004-2009 Canonical Ltd.</small></p>
34
32
        <!-- kthxbye. -->
109
107
 
110
108
        token = request.args.get('token', [None])[0]
111
109
        path = request.path
112
 
        deferred = deferToThread(
113
 
            self._getFileAlias, self.aliasID, token, path)
 
110
        deferred = deferToThread(self._getFileAlias, self.aliasID, token, path)
114
111
        deferred.addCallback(
115
112
                self._cb_getFileAlias, filename, request
116
113
                )
128
125
            raise NotFound
129
126
 
130
127
    def _eb_getFileAlias(self, failure):
131
 
        err = failure.trap(NotFound, DisconnectionError)
132
 
        if err == DisconnectionError:
133
 
            return resource.ErrorPage(
134
 
                503, 'Database unavailable',
135
 
                'A required database is unavailable.\n'
136
 
                'See http://identi.ca/launchpadstatus '
137
 
                'for maintenance and outage notifications.')
138
 
        else:
139
 
            return fourOhFour
 
128
        failure.trap(NotFound)
 
129
        return fourOhFour
140
130
 
141
131
    def _cb_getFileAlias(
142
 
            self,
143
 
            (dbcontentID, dbfilename, mimetype, date_created, restricted),
 
132
            self, (dbcontentID, dbfilename, mimetype, date_created, restricted),
144
133
            filename, request
145
134
            ):
146
135
        # Return a 404 if the filename in the URL is incorrect. This offers
178
167
 
179
168
class File(static.File):
180
169
    isLeaf = True
181
 
 
182
170
    def __init__(
183
171
        self, contentType, encoding, modification_time, *args, **kwargs):
184
172
        # Have to convert the UTC datetime to POSIX timestamp (localtime)