41
41
# to: The path of the target filename. Error if the file already
44
# action=putfile: Upload a file to the student workspace.
44
# action=putfile: Upload a file to the student workspace, and optionally
45
# accept zip files which will be unpacked.
45
46
# path: The path to the file to be written. If it exists, will
46
47
# overwrite. Error if the target file is a directory.
47
48
# data: Bytes to be written to the file verbatim. May either be
48
49
# a string variable or a file upload.
50
# unpack: Optional. If "true", and the data is a valid ZIP file,
51
# will create a directory instead and unpack the ZIP file
54
# action=putfiles: Upload multiple files to the student workspace, and
55
# optionally accept zip files which will be unpacked.
56
# path: The path to the DIRECTORY to place files in. Must not be a
58
# data: A file upload (may not be a simple string). The filename
59
# will be used to determine the target filename within
61
# unpack: Optional. If "true", if any data is a valid ZIP file,
62
# will create a directory instead and unpack the ZIP file
65
# The differences between putfile and putfiles are:
66
# * putfile can only accept a single file.
67
# * putfile can accept string data, doesn't have to be a file upload.
68
# * putfile ignores the upload filename, the entire filename is specified on
69
# path. putfiles calls files after the name on the user's machine.
50
71
# Clipboard-based actions. Cut/copy/paste work in the same way as modern
51
72
# file browsers, by keeping a server-side clipboard of files that have been
92
113
# message if unspecified.
94
115
# TODO: Implement the following actions:
95
# move, copy, cut, paste, svnadd, svnrevert, svnupdate, svncommit
116
# putfiles, svnrevert, svnupdate, svncommit
117
# TODO: Implement ZIP unpacking in putfile and putfiles.
102
124
from common import (util, studpath)
126
# Make a Subversion client object
127
svnclient = pysvn.Client()
104
129
DEFAULT_LOGMESSAGE = "No log message supplied."
123
def handle_action(req, svnclient, action, fields):
148
def handle_action(req, action, fields):
124
149
"""Perform the "action" part of the response.
125
150
This function should only be called if the response is a POST.
126
151
This performs the action's side-effect on the server. If unsuccessful,
356
381
del session['clipboard']
384
def action_svnadd(req, fields):
385
"""Performs a "svn add" to each file specified.
389
paths = fields.getlist('path')
390
paths = map(lambda path: actionpath_to_local(req, path), paths)
393
svnclient.add(paths, recurse=True, force=True)
394
except pysvn.ClientError:
395
raise ActionError("One or more files could not be added")
359
397
# Table of all action functions #
360
398
# Each function has the interface f(req, fields).