def _remove_installed_paths(self, installed_paths, root_dir): # This method never raise an error removed_paths = [] try: # this rely on the fact that remove_paths is a generator for removed_path in remove_paths(installed_paths, root_dir): removed_paths.append(removed_path) except Exception, e: # error while removing files we were succesfull at installating non_removed_paths = list(set(installed_paths).difference(removed_paths)) logger.warning('Error while removing already installed files: %s' % e, exc_info=True) logger.warning('The following files have been left in %s: %s' % (root_dir, non_removed_paths))
def _uninstall_pkg(self, installed_pkg, root_dir): # uninstall the installed pkg and update the installed pkg sto pkg_id = installed_pkg.pkg_info['id'] installed_paths = installed_pkg.pkg_info['files'] removed_paths = [] try: for removed_path in remove_paths(installed_paths, root_dir): removed_paths.append(removed_path) except Exception, e: logger.error("Error while removing files of pkg %s: %s" % (pkg_id, e)) if removed_paths: logger.error("These files have been removed from %s although the" "package will still be shown as installed: %s" % (root_dir, removed_path)) raise
def test_remove_non_empty_dir_doesnt_raise_nor_remove(self): self._create_dir('dir1') self._create_file('dir1/file1') result = sorted(util.remove_paths(['dir1/'], self._tmp_dir)) self.assertEqual(['dir1/', 'dir1/file1'], sorted(util.list_paths(self._tmp_dir))) self.assertEqual(['dir1/'], result)
def test_remove_inexistant_dir_doesnt_raise(self): result = sorted(util.remove_paths(['dir1/'], self._tmp_dir)) self.assertEqual([], sorted(util.list_paths(self._tmp_dir))) self.assertEqual(['dir1/'], result)
def test_remove_dir_as_file_fail(self): self._create_dir('dir1') self.assertRaises(OSError, sorted, util.remove_paths(['dir1'], self._tmp_dir))
def test_remove_file_as_dir_fail(self): self._create_file('file1') # Note the a little bit weird syntax since util.remove_paths returns # an iterator that does nothing until we iterate over it self.assertRaises(OSError, sorted, util.remove_paths(['file1/'], self._tmp_dir))
def test_remove_one_dir_remove_dir_only(self): self._create_dir('dir1') self._create_file('file2') result = sorted(util.remove_paths(['dir1/'], self._tmp_dir)) self.assertEqual(['file2'], sorted(util.list_paths(self._tmp_dir))) self.assertEqual(['dir1/'], result)
def test_remove_one_file(self): self._create_file('file1') result = sorted(util.remove_paths(['file1'], self._tmp_dir)) self.assertEqual([], sorted(util.list_paths(self._tmp_dir))) self.assertEqual(['file1'], result)
def test_remove_nothing(self): result = sorted(util.remove_paths([], self._tmp_dir)) self.assertEqual([], result)