~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/fileservice_lib/listing.py

  • Committer: Matt Giuca
  • Date: 2009-04-23 07:51:29 UTC
  • Revision ID: matt.giuca@gmail.com-20090423075129-94mf4vlwllpew0xn
ivle.svn: Added revision_is_dir (like os.path.isdir for revision history).
ivle.fileservice_lib.listing: Refactored such that the SVN revision is found
    in the top-level handler, and passed down into the individual handlers.
    This is done so that the revision information can be used to make the
    decisions (which will be required to fix the revision history browsing).
    This doesn't yet change the behaviour.

Show diffs side-by-side

added added

removed removed

Lines of Context:
151
151
        req.status = req.HTTP_FORBIDDEN
152
152
        req.headers_out['X-IVLE-Return-Error'] = 'Forbidden'
153
153
        req.write("Forbidden")
154
 
    elif not os.access(path, os.R_OK):
 
154
        return
 
155
 
 
156
    # If this is a repository-revision request, it needs to be treated
 
157
    # differently than if it were a regular file request.
 
158
    # Note: If there IS a revision requested but the file doesn't exist in
 
159
    # that revision, this will terminate.
 
160
    revision = _get_revision_or_die(req, svnclient, path)
 
161
 
 
162
    if not os.access(path, os.R_OK):
155
163
        req.status = req.HTTP_NOT_FOUND
156
164
        req.headers_out['X-IVLE-Return-Error'] = 'File not found'
157
165
        req.write("File not found")
160
168
        req.content_type = mime_dirlisting
161
169
        req.headers_out['X-IVLE-Return'] = 'Dir'
162
170
        # TODO: Fix this dirty, dirty hack
163
 
        newjson = get_dirlisting(req, svnclient, path)
 
171
        newjson = get_dirlisting(req, svnclient, path, revision)
164
172
        if ("X-IVLE-Action-Error" in req.headers_out):
165
173
            newjson["Error"] = req.headers_out["X-IVLE-Action-Error"]
166
174
        req.write(cjson.encode(newjson))
174
182
        req.content_type = type
175
183
        req.headers_out['X-IVLE-Return'] = 'File'
176
184
 
177
 
        send_file(req, svnclient, path)
 
185
        send_file(req, svnclient, path, revision)
178
186
    else:
179
187
        # It's a file. Return a "fake directory listing" with just this file.
180
188
        req.content_type = mime_dirlisting
181
189
        req.headers_out['X-IVLE-Return'] = 'File'
182
 
        req.write(cjson.encode(get_dirlisting(req, svnclient, path)))
 
190
        req.write(cjson.encode(get_dirlisting(req, svnclient, path,
 
191
                                              revision)))
183
192
 
184
193
def _get_revision_or_die(req, svnclient, path):
185
194
    """Looks for a revision specification in req's URL.
206
215
        sys.exit()
207
216
    return revision
208
217
 
209
 
def send_file(req, svnclient, path):
210
 
    revision = _get_revision_or_die(req, svnclient, path)
 
218
def send_file(req, svnclient, path, revision):
 
219
    """Given a local absolute path to a file, sends the contents of the file
 
220
    to the client.
 
221
 
 
222
    @param req: Request object. Will not be mutated; just reads the session.
 
223
    @param svnclient: Svn client object.
 
224
    @param path: String. Absolute path on the local file system. Not checked,
 
225
        must already be guaranteed safe. May be a file or a directory.
 
226
    @param revision: pysvn Revision object for the given path, or None.
 
227
    """
211
228
    if revision:
212
229
        req.write(svnclient.cat(path, revision=revision))
213
230
    else:
214
231
        req.sendfile(path)
215
232
 
216
 
def get_dirlisting(req, svnclient, path):
 
233
def get_dirlisting(req, svnclient, path, revision):
217
234
    """Given a local absolute path, creates a directory listing object
218
235
    ready to be JSONized and sent to the client.
219
236
 
220
 
    req: Request object. Will not be mutated; just reads the session.
221
 
    svnclient: Svn client object.
222
 
    path: String. Absolute path on the local file system. Not checked,
 
237
    @param req: Request object. Will not be mutated; just reads the session.
 
238
    @param svnclient: Svn client object.
 
239
    @param path: String. Absolute path on the local file system. Not checked,
223
240
        must already be guaranteed safe. May be a file or a directory.
 
241
    @param revision: pysvn Revision object for the given path, or None.
224
242
    """
225
243
 
226
 
    revision = _get_revision_or_die(req, svnclient, path)
227
 
 
228
244
    # Start by trying to do an SVN status, so we can report file version
229
245
    # status
230
246
    listing = {}