~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/script.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-01-13 18:11:21 UTC
  • mfrom: (4956.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100113181121-50zma6sk6r0bvq1n
(nmb) Implement mv for shell-like scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
402
402
            retcode = 0
403
403
        return retcode, None, err
404
404
 
 
405
    def do_mv(self, test_case, input, args):
 
406
        err = None
 
407
        def error(msg, src, dst):
 
408
            return "mv: cannot move %s to %s: %s\n" % (src, dst, msg)
 
409
 
 
410
        if not args or len(args) != 2:
 
411
            raise SyntaxError("Usage: mv path1 path2")
 
412
        src, dst = args
 
413
        try:
 
414
            real_dst = dst
 
415
            if os.path.isdir(dst):
 
416
                real_dst = os.path.join(dst, os.path.basename(src))
 
417
            os.rename(src, real_dst)
 
418
        except OSError, e:
 
419
            if e.errno == errno.ENOENT:
 
420
                err = error('No such file or directory', src, dst)
 
421
            else:
 
422
                raise
 
423
        if err:
 
424
            retcode = 1
 
425
        else:
 
426
            retcode = 0
 
427
        return retcode, None, err
 
428
 
 
429
 
405
430
 
406
431
class TestCaseWithMemoryTransportAndScript(tests.TestCaseWithMemoryTransport):
407
432
    """Helper class to experiment shell-like test and memory fs.