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

« back to all changes in this revision

Viewing changes to ivle/fileservice_lib/action.py

  • Committer: William Grant
  • Date: 2009-01-22 02:25:07 UTC
  • mfrom: (1088)
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: grantw@unimelb.edu.au-20090122022507-l327esou6raztvum
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
264
264
    except shutil.Error:
265
265
        raise ActionError("Could not move the file specified")
266
266
 
 
267
def svn_movefile(req, frompath, topath, copy=False):
 
268
    """Performs an svn move, resolving filenames, checking for any errors,
 
269
    and throwing ActionErrors if necessary. Can also be used to do a copy
 
270
    operation instead.
 
271
 
 
272
    frompath and topath are straight paths from the client. Will be checked.
 
273
    """
 
274
    if frompath is None or topath is None:
 
275
        raise ActionError("Required field missing")
 
276
    frompath = actionpath_to_local(req, frompath)
 
277
    topath = actionpath_to_local(req, topath)
 
278
    if not os.path.exists(frompath):
 
279
        raise ActionError("The source file does not exist")
 
280
    if os.path.exists(topath):
 
281
        if frompath == topath:
 
282
            raise ActionError("Source and destination are the same")
 
283
        raise ActionError("A file already exists with that name")
 
284
 
 
285
    try:
 
286
        if copy:
 
287
            svnclient.copy(frompath, topath)
 
288
        else:
 
289
            svnclient.move(frompath, topath)
 
290
    except OSError:
 
291
        raise ActionError("Could not move the file specified")
 
292
    except pysvn.ClientError:
 
293
        raise ActionError("Could not move the file specified")  
 
294
 
 
295
 
267
296
### ACTIONS ###
268
297
 
269
298
def action_delete(req, fields):
445
474
    files = fields.getlist('file')
446
475
    if dst is None or src is None or mode is None:
447
476
        raise ActionError("Required field missing")
448
 
    if mode == "copy":
449
 
        copy = True
450
 
    elif mode == "move":
451
 
        copy = False
452
 
    else:
453
 
        raise ActionError("Invalid mode (must be 'copy' or 'move')")
 
477
 
454
478
    dst_local = actionpath_to_local(req, dst)
455
479
    if not os.path.isdir(dst_local):
456
480
        raise ActionError("dst is not a directory")
465
489
        # The destination is found by taking just the basename of the file
466
490
        topath = os.path.join(dst, os.path.basename(file))
467
491
        try:
468
 
            movefile(req, frompath, topath, copy)
 
492
            if mode == "copy":
 
493
                movefile(req, frompath, topath, True)
 
494
            elif mode == "move":
 
495
                movefile(req, frompath, topath, False)
 
496
            elif mode == "svncopy":
 
497
                svn_movefile(req, frompath, topath, True)
 
498
            elif mode == "svnmove":
 
499
                svn_movefile(req, frompath, topath, False)
 
500
            else:
 
501
                raise ActionError("Invalid mode (must be '(svn)copy' or '(svn)move')")
469
502
        except ActionError, message:
470
503
            # Store the error for later; we want to copy as many as possible
471
504
            if errormsg is None:
710
743
            raise util.IVLEError(404, 'The specified repository path does not exist')
711
744
        else:
712
745
            raise ActionError(str(e[0]))
 
746
            
713
747
 
714
748
# Table of all action functions #
715
749
# Each function has the interface f(req, fields).