Example #1
0
 def test_destinsrc_false_positive(self):
     os.mkdir(TESTFN)
     try:
         for src, dst in [('srcdir', 'src/dest'), ('srcdir', 'srcdir.new')]:
             src = os.path.join(TESTFN, src)
             dst = os.path.join(TESTFN, dst)
             self.failIf(shutil.destinsrc(src, dst),
                         msg='destinsrc() wrongly concluded that '
                         'dst (%s) is in src (%s)' % (dst, src))
     finally:
         shutil.rmtree(TESTFN, ignore_errors=True)
Example #2
0
 def test_destinsrc_false_positive(self):
     os.mkdir(TESTFN)
     try:
         for src, dst in [('srcdir', 'src/dest'), ('srcdir', 'srcdir.new')]:
             src = os.path.join(TESTFN, src)
             dst = os.path.join(TESTFN, dst)
             self.failIf(shutil.destinsrc(src, dst),
                         msg='destinsrc() wrongly concluded that '
                         'dst (%s) is in src (%s)' % (dst, src))
     finally:
         shutil.rmtree(TESTFN, ignore_errors=True)
Example #3
0
    def move(src, dst):
        """Recursively move a file or directory to another location.

        If the destination is on our current filesystem, then simply use
        rename.  Otherwise, copy src to the dst and then remove src.
        A lot more could be done here...  A look at a mv.c shows a lot of
        the issues this implementation glosses over.

        """
        try:
            os.rename(src, dst)
        except OSError:
            if os.path.isdir(src):
                if shutil.destinsrc(src, dst):
                    raise Error, "Cannot move a directory '%s' into itself '%s'." % (src, dst)
                shutil.copytree(src, dst, symlinks=True)
                shutil.rmtree(src)
            else:
                shutil.copy2(src,dst)
                os.unlink(src)
Example #4
0
    def move(src, dst):
        """Recursively move a file or directory to another location.

        If the destination is on our current filesystem, then simply use
        rename.  Otherwise, copy src to the dst and then remove src.
        A lot more could be done here...  A look at a mv.c shows a lot of
        the issues this implementation glosses over.

        """
        try:
            os.rename(src, dst)
        except OSError:
            if os.path.isdir(src):
                if shutil.destinsrc(src, dst):
                    raise Error, "Cannot move a directory '%s' into itself '%s'." % (src, dst)
                shutil.copytree(src, dst, symlinks=True)
                shutil.rmtree(src)
            else:
                shutil.copy2(src,dst)
                os.unlink(src)
Example #5
0
 def destinsrc(self, src, dst):
     return shutil.destinsrc(src, dst)
Example #6
0
 def destinsrc(self, src, dst):
     return shutil.destinsrc(src, dst)