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

« back to all changes in this revision

Viewing changes to lib/fileservice_lib/action.py

  • Committer: drtomc
  • Date: 2008-02-08 04:30:55 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:436
fileservice: Make things less broken than they were. No claims of perfection yet! Unpacking form data with cgi.py is AWFUL.

Show diffs side-by-side

added added

removed removed

Lines of Context:
130
130
#   update if the path is not a directory).
131
131
 
132
132
import os
 
133
import cStringIO
133
134
import shutil
134
135
 
135
136
import pysvn
208
209
 
209
210
    Does not mutate req.
210
211
    """
211
 
    _, r = studpath.url_to_local(actionpath_to_urlpath(req, path))
 
212
    (_, _, r) = studpath.url_to_jailpaths(actionpath_to_urlpath(req, path))
212
213
    if r is None:
213
214
        raise ActionError("Invalid path")
214
215
    return r
296
297
    # Important: Data is "None" if the file submitted is empty.
297
298
    path = fields.getfirst('path')
298
299
    data = fields.getfirst('data')
299
 
    if path is None:
 
300
    if path is None or data is None:
300
301
        raise ActionError("Required field missing")
301
302
    path = actionpath_to_local(req, path)
 
303
 
302
304
    if data is not None:
303
 
        data = data.file
 
305
        data = cStringIO.StringIO(data)
304
306
 
305
307
    # Copy the contents of file object 'data' to the path 'path'
306
308
    try:
316
318
 
317
319
    Reads fields: 'path', 'data' (file upload, multiple), 'unpack'
318
320
    """
 
321
 
319
322
    # Important: Data is "None" if the file submitted is empty.
320
323
    path = fields.getfirst('path')
321
 
    data = fields.getlist('data')
 
324
    data = fields['data']
 
325
    if type(data) != type([]):
 
326
        data = [data]
322
327
    unpack = fields.getfirst('unpack')
323
328
    if unpack is None:
324
329
        unpack = False
329
334
    path = actionpath_to_urlpath(req, path)
330
335
    goterror = False
331
336
 
 
337
 
332
338
    for datum in data:
333
339
        # Each of the uploaded files
334
340
        filepath = os.path.join(path, datum.filename)
335
 
        filedata = datum.file
 
341
        filedata = datum.value
336
342
 
337
343
        if unpack and datum.filename.lower().endswith(".zip"):
338
344
            # A zip file - unpack it instead of just copying
345
351
                goterror = True
346
352
        else:
347
353
            # Not a zip file
348
 
            _, filepath_local = studpath.url_to_local(filepath)
 
354
            (_, _, filepath_local) = studpath.url_to_jailpaths(filepath)
349
355
            if filepath_local is None:
350
356
                raise ActionError("Invalid path")
351
357
 
353
359
            try:
354
360
                dest = open(filepath_local, 'wb')
355
361
                if data is not None:
356
 
                    shutil.copyfileobj(filedata, dest)
 
362
                    shutil.copyfileobj(cStringIO.StringIO(filedata), dest)
357
363
            except OSError:
358
364
                goterror = True
359
365