200
200
raise ActionError(
201
201
"Could not delete one or more of the files specified")
203
def action_move(req, fields):
204
# TODO: Do an SVN mv if the file is versioned.
205
# TODO: Disallow tampering with student's home directory
206
"""Removes a list of files or directories.
208
Reads fields: 'from', 'to'
210
frompath = fields.getfirst('from')
211
topath = fields.getfirst('to')
212
if frompath is None or topath is None:
213
raise ActionError("Required field missing")
214
frompath = actionpath_to_local(req, frompath)
215
topath = actionpath_to_local(req, topath)
216
if not os.path.exists(frompath):
217
raise ActionError("The source file does not exist")
218
if os.path.exists(topath):
219
raise ActionError("Another file already exists with that name")
222
shutil.move(frompath, topath)
224
raise ActionError("Could not move the file specified")
226
raise ActionError("Could not move the file specified")
203
228
def action_putfile(req, fields):
204
229
"""Writes data to a file, overwriting it if it exists and creating it if
209
234
path = fields.getfirst('path')
210
235
data = fields.getfirst('data')
211
if path is None: raise ActionError("No path specified")
212
if data is None: raise ActionError("No data specified")
236
if path is None or data is None:
237
raise ActionError("Required field missing")
213
238
path = actionpath_to_local(req, path)
221
246
raise ActionError("Could not write to target file")
223
248
# Table of all action functions #
249
# Each function has the interface f(req, fields).
225
251
actions_table = {
226
252
"remove" : action_remove,
253
"move" : action_move,
227
254
"putfile" : action_putfile,