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

« back to all changes in this revision

Viewing changes to www/apps/fileservice/__init__.py

  • Committer: mattgiuca
  • Date: 2008-01-10 01:22:39 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:153
fileservice: remove now works on directories too (recurses).

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
# TODO: More actions.
82
82
 
83
83
import os
 
84
import shutil
84
85
import stat
85
86
import time
86
87
import mimetypes
124
125
    # side-effects on the server.
125
126
    action = None
126
127
    fields = None
127
 
    if True or req.method == 'POST':
 
128
    if req.method == 'POST':
128
129
        fields = req.get_fieldstorage()
129
130
        action = fields.getfirst('action')
130
131
 
301
302
 
302
303
def action_remove(req, paths):
303
304
    # TODO: Do an SVN rm if the file is versioned.
 
305
    # TODO: Disallow removal of student's home directory
304
306
    """Removes a list of files or directories."""
305
307
    goterror = False
306
308
    for path in paths:
307
309
        path = actionpath_to_local(req, path)
308
310
        try:
309
 
            os.remove(path)
 
311
            if os.path.isdir(path):
 
312
                shutil.rmtree(path)
 
313
            else:
 
314
                os.remove(path)
310
315
        except OSError:
311
316
            goterror = True
 
317
        except shutil.Error:
 
318
            goterror = True
312
319
    if goterror:
313
320
        if len(paths) == 1:
314
321
            raise ActionError("Could not delete the file specified")