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

« back to all changes in this revision

Viewing changes to ivle/fileservice_lib/action.py

  • Committer: chadnickbok
  • Date: 2009-01-19 22:56:46 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1170
This commit fixes issue #10 and part of issue #9

There are now two options for moving files with their
svn history intact; svn move and svn copy. These
use the svn commands to move the files, allowing students
to move and rename files without their histories being
lost.

This commit also shows the svn status of a dir, if it is
the 'head' of an svn repository.

Show diffs side-by-side

added added

removed removed

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