23
23
# requests. Performs actions on the student's workspace, and returns directory
24
24
# listings in JSON.
26
# This rather large documentation explains the request and response to the
27
# file service app (it should probably be taken to a separate document).
26
29
# This is not intended to be accessed directly by the user. It is targeted by
27
30
# AJAX calls in applications such as browser and editor.
32
# Application usage: The input to the application is determined by the fields
33
# passed in as HTTP variables (either in the URL or message body). Also, in
34
# keeping with REST, actions only take effect if this is a POST request as
35
# opposed to a GET request (although a GET request is still allowed to just
36
# get a listing or file dump). Also, the "path" (the part of the URL
37
# after "fileservice" and before the GET variables) is taken into account.
39
# Aside from the side-effects to the server (note: side-effects are only
40
# possible for POST requests), the response takes two parts. The response
41
# header contains information about success or failure of the operation. The
42
# response body may contain the requested file.
44
# Fileservice has two separate roles: First, an action is performed. This may
45
# be a copy, write, or svn up operation. Then, a file or directory listing is
46
# returned. This directory listing may be completely separate from the action,
47
# but they are performed together because the client will usually want to
48
# perform some action, then update its display as a result of the action.
50
# GET requests will have all variables ignored, and the only behaviour will be
51
# to generate the directory or file listing. POST requests will result in an
52
# action if one is specified. If the action is UNSUCCESSFUL, returns the
53
# header "X-IVLE-Action-Error: <errormessage>". Successful actions succeed
54
# silently. Note that the action does not affect the HTTP response code (it
55
# may be 200 even upon failure).
57
# The path (req.path) controls which file or directory will be
58
# returned. If it is a file, returns the header "X-IVLE-Return: File" and
59
# status 200 OK. The response body is a verbatim dump of the file specified.
60
# The Content-Type will probably be text/plain but should not be relied upon.
61
# If it is a directory, returns the header "X-IVLE-Return: Dir" and status
62
# 200 OK. The response body is a JSON directory listing (see below). The
63
# Content-Type cannot be relied upon. If the file is not found or there is
64
# some other read error, returns no X-IVLE-Return header, a 400-level
65
# response status. (404 File Not Found, 403 Forbidden, etc), and a header
66
# "X-IVLE-List-Error: <errormessage>".
70
# The most important argument is "action". This determines which action is
71
# taken. Note that action, and all other arguments, are ignored unless the
72
# request is a POST request. The other arguments depend upon the action.
73
# Note that paths are often specified as arguments. Paths that begin with a
74
# slash are taken relative to the user's home directory (the top-level
75
# directory seen when fileservice has no arguments or path). Paths without a
76
# slash are taken relative to the specified path.
78
# action=rm: Delete a file or directory (recursively).
79
# path: The path to the file or directory to delete.
29
82
from common import util
86
DEFAULT_LOGMESSAGE = "No log message supplied."
88
# Make a Subversion client object
89
svnclient = pysvn.Client()
32
"""Handler for the Dummy application."""
92
"""Handler for the File Services application."""
34
94
# Set request attributes
95
# application/json is the "best" content type but is not good for
96
# debugging because Firefox just tries to download it
35
97
req.content_type = "text/plain"
98
#req.content_type = "application/json"
36
99
req.write_html_head_foot = False # No HTML
38
101
# Start writing data