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

« back to all changes in this revision

Viewing changes to lib/fileservice_lib/action.py

  • Committer: mattgiuca
  • Date: 2008-02-06 03:07:09 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:429
makeuser and common.db now allow StudentID to be unsupplied / None.
This will insert a NULL into the DB (allowed by the schema).

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
134
133
import shutil
135
134
 
136
135
import pysvn
209
208
 
210
209
    Does not mutate req.
211
210
    """
212
 
    (_, _, r) = studpath.url_to_jailpaths(actionpath_to_urlpath(req, path))
 
211
    _, r = studpath.url_to_local(actionpath_to_urlpath(req, path))
213
212
    if r is None:
214
213
        raise ActionError("Invalid path")
215
214
    return r
297
296
    # Important: Data is "None" if the file submitted is empty.
298
297
    path = fields.getfirst('path')
299
298
    data = fields.getfirst('data')
300
 
    if path is None or data is None:
 
299
    if path is None:
301
300
        raise ActionError("Required field missing")
302
301
    path = actionpath_to_local(req, path)
303
 
 
304
302
    if data is not None:
305
 
        data = cStringIO.StringIO(data)
 
303
        data = data.file
306
304
 
307
305
    # Copy the contents of file object 'data' to the path 'path'
308
306
    try:
318
316
 
319
317
    Reads fields: 'path', 'data' (file upload, multiple), 'unpack'
320
318
    """
321
 
 
322
319
    # Important: Data is "None" if the file submitted is empty.
323
320
    path = fields.getfirst('path')
324
 
    data = fields['data']
325
 
    if type(data) != type([]):
326
 
        data = [data]
 
321
    data = fields.getlist('data')
327
322
    unpack = fields.getfirst('unpack')
328
323
    if unpack is None:
329
324
        unpack = False
334
329
    path = actionpath_to_urlpath(req, path)
335
330
    goterror = False
336
331
 
337
 
 
338
332
    for datum in data:
339
333
        # Each of the uploaded files
340
334
        filepath = os.path.join(path, datum.filename)
341
 
        filedata = datum.value
 
335
        filedata = datum.file
342
336
 
343
337
        if unpack and datum.filename.lower().endswith(".zip"):
344
338
            # A zip file - unpack it instead of just copying
351
345
                goterror = True
352
346
        else:
353
347
            # Not a zip file
354
 
            (_, _, filepath_local) = studpath.url_to_jailpaths(filepath)
 
348
            _, filepath_local = studpath.url_to_local(filepath)
355
349
            if filepath_local is None:
356
350
                raise ActionError("Invalid path")
357
351
 
359
353
            try:
360
354
                dest = open(filepath_local, 'wb')
361
355
                if data is not None:
362
 
                    shutil.copyfileobj(cStringIO.StringIO(filedata), dest)
 
356
                    shutil.copyfileobj(filedata, dest)
363
357
            except OSError:
364
358
                goterror = True
365
359
 
517
511
        for path in paths:
518
512
            # Note: Property value doesn't matter
519
513
            svnclient.propset("ivle:published", "", path, recurse=False)
520
 
    except pysvn.ClientError, e:
521
 
        raise ActionError("Directory could not be published")
 
514
    except pysvn.ClientError:
 
515
        raise ActionError("One or more files could not be updated")
522
516
 
523
517
def action_svnunpublish(req, fields):
524
518
    """Deletes svn property "ivle:published" on each file specified.
532
526
        for path in paths:
533
527
            svnclient.propdel("ivle:published", path, recurse=False)
534
528
    except pysvn.ClientError:
535
 
        raise ActionError("Directory could not be unpublished)
 
529
        raise ActionError("One or more files could not be updated")
536
530
 
537
531
def action_svncommit(req, fields):
538
532
    """Performs a "svn commit" to each file specified.