Exemple #1
0
 def do_repository_request(self, repository, compression):
     tmp_dirname, tmp_repo = self._copy_to_tempdir(repository)
     try:
         controldir_name = tmp_dirname + '/.bzr'
         return self._tarfile_response(controldir_name, compression)
     finally:
         osutils.rmtree(tmp_dirname)
Exemple #2
0
 def test_locations(self):
     """Using and remembering different locations"""
     os.mkdir('a')
     os.chdir('a')
     self.run_bzr('init')
     self.run_bzr('commit -m unchanged --unchanged')
     self.run_bzr('pull', retcode=3)
     self.run_bzr('merge', retcode=3)
     self.run_bzr('branch . ../b')
     os.chdir('../b')
     self.run_bzr('pull')
     self.run_bzr('branch . ../c')
     self.run_bzr('pull ../c')
     self.run_bzr('merge')
     os.chdir('../a')
     self.run_bzr('pull ../b')
     self.run_bzr('pull')
     self.run_bzr('pull ../c')
     self.run_bzr('branch ../c ../d')
     osutils.rmtree('../c')
     self.run_bzr('pull')
     os.chdir('../b')
     self.run_bzr('pull')
     os.chdir('../d')
     self.run_bzr('pull', retcode=3)
     self.run_bzr('pull ../a --remember')
     self.run_bzr('pull')
Exemple #3
0
 def assertTransitionFromBasisToShape(self, basis_shape, basis_revid,
     new_shape, new_revid, extra_parent=None):
     # set the inventory revision ids.
     basis_shape.revision_id = basis_revid
     new_shape.revision_id = new_revid
     delta = self.make_inv_delta(basis_shape, new_shape)
     tree = self.make_branch_and_tree('tree')
     # the shapes need to be in the tree's repository to be able to set them
     # as a parent, but the file content is not needed.
     if basis_revid is not None:
         self.fake_up_revision(tree, basis_revid, basis_shape)
         parents = [basis_revid]
         if extra_parent is not None:
             parents.append(extra_parent)
         tree.set_parent_ids(parents)
     self.fake_up_revision(tree, new_revid, new_shape)
     # give tree an inventory of new_shape
     tree._write_inventory(new_shape)
     self.assertDeltaApplicationResultsInExpectedBasis(tree, new_revid,
         delta, new_shape)
     # The tree should be internally consistent; while this is a moderately
     # large hammer, this is a particularly sensitive area of code, so the
     # extra assurance is well worth it.
     tree._validate()
     osutils.rmtree('tree')
Exemple #4
0
    def test_build_and_install(self):
        """ test cmd `python setup.py build`

        This tests that the build process and man generator run correctly.
        It also can catch new subdirectories that weren't added to setup.py.
        """
        if not os.path.isfile('setup.py'):
            raise TestSkipped('There is no setup.py file in current directory')
        try:
            import distutils.sysconfig
            makefile_path = distutils.sysconfig.get_makefile_filename()
            if not os.path.exists(makefile_path):
                raise TestSkipped('You must have the python Makefile installed to run this test.'
                                  ' Usually this can be found by installing "python-dev"')
        except ImportError:
            raise TestSkipped('You must have distutils installed to run this test.'
                              ' Usually this can be found by installing "python-dev"')
        self.log('test_build running in %s' % os.getcwd())
        install_dir = tempfile.mkdtemp()
        # setup.py must be run from the root source directory, but the tests
        # are not necessarily invoked from there
        self.source_dir = os.path.dirname(os.path.dirname(bzrlib.__file__))
        try:
            self.run_setup(['clean'])
            # build is implied by install
            ## self.run_setup(['build'])
            self.run_setup(['install', '--prefix', install_dir])
            self.run_setup(['clean'])
        finally:
            osutils.rmtree(install_dir)
Exemple #5
0
 def test_locations(self):
     """Using and remembering different locations"""
     os.mkdir('a')
     os.chdir('a')
     self.run_bzr('init')
     self.run_bzr('commit -m unchanged --unchanged')
     self.run_bzr('pull', retcode=3)
     self.run_bzr('merge', retcode=3)
     self.run_bzr('branch . ../b')
     os.chdir('../b')
     self.run_bzr('pull')
     self.run_bzr('branch . ../c')
     self.run_bzr('pull ../c')
     self.run_bzr('merge')
     os.chdir('../a')
     self.run_bzr('pull ../b')
     self.run_bzr('pull')
     self.run_bzr('pull ../c')
     self.run_bzr('branch ../c ../d')
     osutils.rmtree('../c')
     self.run_bzr('pull')
     os.chdir('../b')
     self.run_bzr('pull')
     os.chdir('../d')
     self.run_bzr('pull', retcode=3)
     self.run_bzr('pull ../a --remember')
     self.run_bzr('pull')
Exemple #6
0
 def assertTransitionFromBasisToShape(self,
                                      basis_shape,
                                      basis_revid,
                                      new_shape,
                                      new_revid,
                                      extra_parent=None):
     # set the inventory revision ids.
     basis_shape.revision_id = basis_revid
     new_shape.revision_id = new_revid
     delta = self.make_inv_delta(basis_shape, new_shape)
     tree = self.make_branch_and_tree('tree')
     # the shapes need to be in the tree's repository to be able to set them
     # as a parent, but the file content is not needed.
     if basis_revid is not None:
         self.fake_up_revision(tree, basis_revid, basis_shape)
         parents = [basis_revid]
         if extra_parent is not None:
             parents.append(extra_parent)
         tree.set_parent_ids(parents)
     self.fake_up_revision(tree, new_revid, new_shape)
     # give tree an inventory of new_shape
     tree._write_inventory(new_shape)
     self.assertDeltaApplicationResultsInExpectedBasis(
         tree, new_revid, delta, new_shape)
     # The tree should be internally consistent; while this is a moderately
     # large hammer, this is a particularly sensitive area of code, so the
     # extra assurance is well worth it.
     tree._validate()
     osutils.rmtree('tree')
Exemple #7
0
 def test_boundless_nick(self):
     """Nick defaults to implicit local nick when bound branch is AWOL"""
     base = self.make_branch_and_tree('base')
     child = self.make_branch_and_tree('child')
     self.run_bzr('bind ../base', working_dir='child')
     self.assertNick(base.branch.nick, working_dir='child', explicit=False)
     osutils.rmtree('base')
     self.assertNick('child', working_dir='child', explicit=False)
Exemple #8
0
 def test_boundless_nick(self):
     """Nick defaults to implicit local nick when bound branch is AWOL"""
     base = self.make_branch_and_tree('base')
     child = self.make_branch_and_tree('child')
     self.run_bzr('bind ../base', working_dir='child')
     self.assertNick(base.branch.nick, working_dir='child', explicit=False)
     osutils.rmtree('base')
     self.assertNick('child', working_dir='child', explicit=False)
Exemple #9
0
    def test_no_autodelete_alternate_renamed(self):
        # Test for bug #114615
        tree_a = self.make_branch_and_tree('A')
        self.build_tree(['A/a/', 'A/a/m', 'A/a/n'])
        tree_a.add(['a', 'a/m', 'a/n'], ['a-id', 'm-id', 'n-id'])
        tree_a.commit('init')

        tree_a.lock_read()
        try:
            root_id = tree_a.get_root_id()
        finally:
            tree_a.unlock()

        tree_b = tree_a.bzrdir.sprout('B').open_workingtree()
        self.build_tree(['B/xyz/'])
        tree_b.add(['xyz'], ['xyz-id'])
        tree_b.rename_one('a/m', 'xyz/m')
        osutils.rmtree('B/a')
        tree_b.commit('delete in B')

        paths = [(path, ie.file_id)
                 for path, ie in tree_b.iter_entries_by_dir()]
        self.assertEqual([('', root_id),
                          ('xyz', 'xyz-id'),
                          ('xyz/m', 'm-id'),
                         ], paths)

        self.build_tree_contents([('A/a/n', 'new contents for n\n')])
        tree_a.commit('change n in A')

        # Merging from A should introduce conflicts because 'n' was modified
        # (in A) and removed (in B), so 'a' needs to be restored.
        num_conflicts = tree_b.merge_from_branch(tree_a.branch)
        self.assertEqual(3, num_conflicts)
        paths = [(path, ie.file_id)
                 for path, ie in tree_b.iter_entries_by_dir()]
        self.assertEqual([('', root_id),
                          ('a', 'a-id'),
                          ('xyz', 'xyz-id'),
                          ('a/n.OTHER', 'n-id'),
                          ('xyz/m', 'm-id'),
                         ], paths)
        osutils.rmtree('B/a')
        try:
            # bzr resolve --all
            tree_b.set_conflicts(conflicts.ConflictList())
        except errors.UnsupportedOperation:
            # On WT2, set_conflicts is unsupported, but the rmtree has the same
            # effect.
            pass
        tree_b.commit('autoremove a, without touching xyz/m')
        paths = [(path, ie.file_id)
                 for path, ie in tree_b.iter_entries_by_dir()]
        self.assertEqual([('', root_id),
                          ('xyz', 'xyz-id'),
                          ('xyz/m', 'm-id'),
                         ], paths)
Exemple #10
0
    def test_no_autodelete_alternate_renamed(self):
        # Test for bug #114615
        tree_a = self.make_branch_and_tree('A')
        self.build_tree(['A/a/', 'A/a/m', 'A/a/n'])
        tree_a.add(['a', 'a/m', 'a/n'], ['a-id', 'm-id', 'n-id'])
        tree_a.commit('init')

        tree_a.lock_read()
        try:
            root_id = tree_a.get_root_id()
        finally:
            tree_a.unlock()

        tree_b = tree_a.bzrdir.sprout('B').open_workingtree()
        self.build_tree(['B/xyz/'])
        tree_b.add(['xyz'], ['xyz-id'])
        tree_b.rename_one('a/m', 'xyz/m')
        osutils.rmtree('B/a')
        tree_b.commit('delete in B')

        paths = [(path, ie.file_id)
                 for path, ie in tree_b.iter_entries_by_dir()]
        self.assertEqual([('', root_id),
                          ('xyz', 'xyz-id'),
                          ('xyz/m', 'm-id'),
                         ], paths)

        self.build_tree_contents([('A/a/n', 'new contents for n\n')])
        tree_a.commit('change n in A')

        # Merging from A should introduce conflicts because 'n' was modified
        # and removed, so 'a' needs to be restored.
        num_conflicts = tree_b.merge_from_branch(tree_a.branch)
        self.assertEqual(3, num_conflicts)
        paths = [(path, ie.file_id)
                 for path, ie in tree_b.iter_entries_by_dir()]
        self.assertEqual([('', root_id),
                          ('a', 'a-id'),
                          ('xyz', 'xyz-id'),
                          ('a/n.OTHER', 'n-id'),
                          ('xyz/m', 'm-id'),
                         ], paths)
        osutils.rmtree('B/a')
        try:
            # bzr resolve --all
            tree_b.set_conflicts(conflicts.ConflictList())
        except errors.UnsupportedOperation:
            # On WT2, set_conflicts is unsupported, but the rmtree has the same
            # effect.
            pass
        tree_b.commit('autoremove a, without touching xyz/m')
        paths = [(path, ie.file_id)
                 for path, ie in tree_b.iter_entries_by_dir()]
        self.assertEqual([('', root_id),
                          ('xyz', 'xyz-id'),
                          ('xyz/m', 'm-id'),
                         ], paths)
Exemple #11
0
    def test_relpath(self):
        """test for branch path lookups
    
        bzrlib.osutils._relpath do a simple but subtle
        job: given a path (either relative to cwd or absolute), work out
        if it is inside a branch and return the path relative to the base.
        """
        import tempfile
        
        savedir = os.getcwdu()
        dtmp = tempfile.mkdtemp()
        # On Mac OSX, /tmp actually expands to /private/tmp
        dtmp = realpath(dtmp)

        def rp(p):
            return relpath(dtmp, p)
        
        try:
            # check paths inside dtmp while standing outside it
            self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')

            # root = nothing
            self.assertEqual(rp(dtmp), '')

            self.assertRaises(PathNotChild,
                              rp,
                              '/etc')

            # now some near-miss operations -- note that
            # os.path.commonprefix gets these wrong!
            self.assertRaises(PathNotChild,
                              rp,
                              dtmp.rstrip('\\/') + '2')

            self.assertRaises(PathNotChild,
                              rp,
                              dtmp.rstrip('\\/') + '2/foo')

            # now operations based on relpath of files in current
            # directory, or nearby
            os.chdir(dtmp)

            self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')

            self.assertEqual(rp('foo'), 'foo')

            self.assertEqual(rp('./foo'), 'foo')

            self.assertEqual(rp(abspath('foo')), 'foo')

            self.assertRaises(PathNotChild,
                              rp, '../foo')

        finally:
            os.chdir(savedir)
            osutils.rmtree(dtmp)
Exemple #12
0
    def cleanup(self):
        """
    Clean up a temporary directory and all its contents.
    """

        # As a safety precaution, make sure we didn't get a completely bogus path:
        if not self.path.endswith("_tmp"):
            raise errors.BzrError("attempted to delete a non-tmp directory: %s" % self.path)
        if not self.cleaned:
            self.cleaned = True
            osutils.rmtree(self.path)
        return
Exemple #13
0
    def cleanup(self):
        """
    Clean up a temporary directory and all its contents.
    """

        # As a safety precaution, make sure we didn't get a completely bogus path:
        if (not self.path.endswith('_tmp')):
            raise errors.BzrError(
                "attempted to delete a non-tmp directory: %s" % self.path)
        if (not self.cleaned):
            self.cleaned = True
            osutils.rmtree(self.path)
        return
Exemple #14
0
    def test_relpath(self):
        """test for branch path lookups
    
        bzrlib.osutils._relpath do a simple but subtle
        job: given a path (either relative to cwd or absolute), work out
        if it is inside a branch and return the path relative to the base.
        """
        import tempfile

        savedir = os.getcwdu()
        dtmp = tempfile.mkdtemp()
        # On Mac OSX, /tmp actually expands to /private/tmp
        dtmp = realpath(dtmp)

        def rp(p):
            return relpath(dtmp, p)

        try:
            # check paths inside dtmp while standing outside it
            self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')

            # root = nothing
            self.assertEqual(rp(dtmp), '')

            self.assertRaises(PathNotChild, rp, '/etc')

            # now some near-miss operations -- note that
            # os.path.commonprefix gets these wrong!
            self.assertRaises(PathNotChild, rp, dtmp.rstrip('\\/') + '2')

            self.assertRaises(PathNotChild, rp, dtmp.rstrip('\\/') + '2/foo')

            # now operations based on relpath of files in current
            # directory, or nearby
            os.chdir(dtmp)

            self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')

            self.assertEqual(rp('foo'), 'foo')

            self.assertEqual(rp('./foo'), 'foo')

            self.assertEqual(rp(abspath('foo')), 'foo')

            self.assertRaises(PathNotChild, rp, '../foo')

        finally:
            os.chdir(savedir)
            osutils.rmtree(dtmp)
Exemple #15
0
 def test_diff_outside_tree(self):
     tmp_dir = tempfile.mkdtemp()
     self.addCleanup(lambda: osutils.rmtree(tmp_dir))
     os.chdir(tmp_dir)
     self.run_bzr('init branch1')
     self.run_bzr(['commit', '-m', 'nothing',
                            '--unchanged', 'branch1'])
     self.run_bzr(['commit', '-m', 'nothing',
                            '--unchanged', 'branch1'])
     this_dir = osutils.getcwd()
     branch2 = "%s/branch2" % (this_dir,)
     # -r X..Y
     out, err = self.run_bzr('diff -r revno:2:branch2..revno:1', retcode=3)
     self.assertEquals('', out)
     self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n' % (branch2,),
                      err)
     # -r X
     out, err = self.run_bzr('diff -r revno:2:branch2', retcode=3)
     self.assertEquals('', out)
     self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n' % (branch2,),
                      err)
     # -r X..
     out, err = self.run_bzr('diff -r revno:2:branch2..', retcode=3)
     self.assertEquals('', out)
     self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n' % (branch2,),
                      err)
     # no -r at all.
     out, err = self.run_bzr('diff', retcode=3)
     self.assertEquals('', out)
     self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n' % (this_dir,),
                      err)
Exemple #16
0
 def test_cwd_log(self):
     tmp_dir = tempfile.mkdtemp()
     self.addCleanup(lambda: osutils.rmtree(tmp_dir))
     os.chdir(tmp_dir)
     out, err = self.run_bzr('log', retcode=3)
     self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n'
                      % (osutils.getcwd(),),
                      err)
Exemple #17
0
 def test_dir_changes_to_symlink(self):
     # <https://bugs.launchpad.net/bzr/+bug/192859>:
     # we had some past problems with the workingtree remembering for too
     # long what kind of object was at a particular name; we really
     # shouldn't do that.  Operating on the dirstate through passing
     # inventory deltas rather than mutating the inventory largely avoids
     # that.
     tree = self.make_branch_and_tree('tree')
     self.build_tree_contents([
         ('tree/a/',),
         ('tree/a/file', 'content'),
         ])
     tree.smart_add(['tree/a'])
     tree.commit('add dir')
     osutils.rmtree('tree/a')
     self.build_tree_contents([
         ('tree/a@', 'target'),
         ])
     tree.commit('change to symlink')
Exemple #18
0
 def test_dir_changes_to_symlink(self):
     # <https://bugs.launchpad.net/bzr/+bug/192859>:
     # we had some past problems with the workingtree remembering for too
     # long what kind of object was at a particular name; we really
     # shouldn't do that.  Operating on the dirstate through passing
     # inventory deltas rather than mutating the inventory largely avoids
     # that.
     tree = self.make_branch_and_tree('tree')
     self.build_tree_contents([
         ('tree/a/', ),
         ('tree/a/file', 'content'),
     ])
     tree.smart_add(['tree/a'])
     tree.commit('add dir')
     osutils.rmtree('tree/a')
     self.build_tree_contents([
         ('tree/a@', 'target'),
     ])
     tree.commit('change to symlink')
Exemple #19
0
def complete_revert(wt, newparents):
    """Simple helper that reverts to specified new parents and makes sure none
    of the extra files are left around.

    :param wt: Working tree to use for rebase
    :param newparents: New parents of the working tree
    """
    newtree = wt.branch.repository.revision_tree(newparents[0])
    delta = wt.changes_from(newtree)
    wt.branch.generate_revision_history(newparents[0])
    wt.set_parent_ids([r for r in newparents[:1] if r != NULL_REVISION])
    for (f, _, _) in delta.added:
        abs_path = wt.abspath(f)
        if osutils.lexists(abs_path):
            if osutils.isdir(abs_path):
                osutils.rmtree(abs_path)
            else:
                os.unlink(abs_path)
    wt.revert(None, old_tree=newtree, backups=False)
    assert not wt.changes_from(wt.basis_tree()).has_changed(), "Rev changed"
    wt.set_parent_ids([r for r in newparents if r != NULL_REVISION])
Exemple #20
0
    def test_no_autodelete_renamed_away(self):
        tree_a = self.make_branch_and_tree('a')
        self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2', 'a/dir2/'])
        tree_a.add(['dir', 'dir/f1', 'dir/f2', 'dir2'],
                   ['dir-id', 'f1-id', 'f2-id', 'dir2-id'])
        rev_id1 = tree_a.commit('init')
        # Rename one entry out of this directory
        tree_a.rename_one('dir/f1', 'dir2/a')
        osutils.rmtree('a/dir')
        tree_a.commit('autoremoved')

        tree_a.lock_read()
        try:
            root_id = tree_a.get_root_id()
            paths = [(path, ie.file_id)
                     for path, ie in tree_a.iter_entries_by_dir()]
        finally:
            tree_a.unlock()
        # The only paths left should be the root
        self.assertEqual([('', root_id), ('dir2', 'dir2-id'),
                          ('dir2/a', 'f1-id'),
                         ], paths)
Exemple #21
0
    def test_no_autodelete_renamed_away(self):
        tree_a = self.make_branch_and_tree('a')
        self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2', 'a/dir2/'])
        tree_a.add(['dir', 'dir/f1', 'dir/f2', 'dir2'],
                   ['dir-id', 'f1-id', 'f2-id', 'dir2-id'])
        rev_id1 = tree_a.commit('init')
        # Rename one entry out of this directory
        tree_a.rename_one('dir/f1', 'dir2/a')
        osutils.rmtree('a/dir')
        tree_a.commit('autoremoved')

        tree_a.lock_read()
        try:
            root_id = tree_a.get_root_id()
            paths = [(path, ie.file_id)
                     for path, ie in tree_a.iter_entries_by_dir()]
        finally:
            tree_a.unlock()
        # The only paths left should be the root
        self.assertEqual([('', root_id), ('dir2', 'dir2-id'),
                          ('dir2/a', 'f1-id'),
                         ], paths)
Exemple #22
0
    def test_autodelete_renamed(self):
        tree_a = self.make_branch_and_tree('a')
        self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2'])
        tree_a.add(['dir', 'dir/f1', 'dir/f2'], ['dir-id', 'f1-id', 'f2-id'])
        rev_id1 = tree_a.commit('init')
        # Start off by renaming entries,
        # but then actually auto delete the whole tree
        # https://bugs.launchpad.net/bzr/+bug/114615
        tree_a.rename_one('dir/f1', 'dir/a')
        tree_a.rename_one('dir/f2', 'dir/z')
        osutils.rmtree('a/dir')
        tree_a.commit('autoremoved')

        tree_a.lock_read()
        try:
            root_id = tree_a.get_root_id()
            paths = [(path, ie.file_id)
                     for path, ie in tree_a.iter_entries_by_dir()]
        finally:
            tree_a.unlock()
        # The only paths left should be the root
        self.assertEqual([('', root_id)], paths)
Exemple #23
0
    def test_autodelete_renamed(self):
        tree_a = self.make_branch_and_tree('a')
        self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2'])
        tree_a.add(['dir', 'dir/f1', 'dir/f2'], ['dir-id', 'f1-id', 'f2-id'])
        rev_id1 = tree_a.commit('init')
        # Start off by renaming entries,
        # but then actually auto delete the whole tree
        # https://bugs.launchpad.net/bzr/+bug/114615
        tree_a.rename_one('dir/f1', 'dir/a')
        tree_a.rename_one('dir/f2', 'dir/z')
        osutils.rmtree('a/dir')
        tree_a.commit('autoremoved')

        tree_a.lock_read()
        try:
            root_id = tree_a.get_root_id()
            paths = [(path, ie.file_id)
                     for path, ie in tree_a.iter_entries_by_dir()]
        finally:
            tree_a.unlock()
        # The only paths left should be the root
        self.assertEqual([('', root_id)], paths)
Exemple #24
0
    def do_rm(self, test_case, input, args):
        err = None

        def error(msg, path):
            return  "rm: cannot remove '%s': %s\n" % (path, msg)

        force, recursive = False, False
        opts = None
        if args and args[0][0] == '-':
            opts = args.pop(0)[1:]
            if 'f' in opts:
                force = True
                opts = opts.replace('f', '', 1)
            if 'r' in opts:
                recursive = True
                opts = opts.replace('r', '', 1)
        if not args or opts:
            raise SyntaxError('Usage: rm [-fr] path+')
        for p in args:
            self._ensure_in_jail(test_case, p)
            # FIXME: Should we put that in osutils ?
            try:
                os.remove(p)
            except OSError, e:
                # Various OSes raises different exceptions (linux: EISDIR,
                #   win32: EACCES, OSX: EPERM) when invoked on a directory
                if e.errno in (errno.EISDIR, errno.EPERM, errno.EACCES):
                    if recursive:
                        osutils.rmtree(p)
                    else:
                        err = error('Is a directory', p)
                        break
                elif e.errno == errno.ENOENT:
                    if not force:
                        err =  error('No such file or directory', p)
                        break
                else:
                    raise
Exemple #25
0
    def do_rm(self, test_case, input, args):
        err = None

        def error(msg, path):
            return "rm: cannot remove '%s': %s\n" % (path, msg)

        force, recursive = False, False
        opts = None
        if args and args[0][0] == '-':
            opts = args.pop(0)[1:]
            if 'f' in opts:
                force = True
                opts = opts.replace('f', '', 1)
            if 'r' in opts:
                recursive = True
                opts = opts.replace('r', '', 1)
        if not args or opts:
            raise SyntaxError('Usage: rm [-fr] path+')
        for p in args:
            self._ensure_in_jail(test_case, p)
            # FIXME: Should we put that in osutils ?
            try:
                os.remove(p)
            except OSError, e:
                # Various OSes raises different exceptions (linux: EISDIR,
                #   win32: EACCES, OSX: EPERM) when invoked on a directory
                if e.errno in (errno.EISDIR, errno.EPERM, errno.EACCES):
                    if recursive:
                        osutils.rmtree(p)
                    else:
                        err = error('Is a directory', p)
                        break
                elif e.errno == errno.ENOENT:
                    if not force:
                        err = error('No such file or directory', p)
                        break
                else:
                    raise
Exemple #26
0
 def cleanup():
     # Workaround lazy import random? madness
     osutils.rmtree(dir)
Exemple #27
0
 def cleanup(self):
     self.unlock()
     osutils.rmtree(self.dir)
Exemple #28
0
 def cleanup(self):
     self.unlock()
     osutils.rmtree(self.dir)
 def cleanup():
     # Workaround lazy import random? madness
     osutils.rmtree(dir)