def _cleanup_common_directories(config): _remove_directory_if_empty(common.get_partsdir()) _remove_directory_if_empty(common.get_stagedir()) _remove_directory_if_empty(common.get_snapdir()) max_index = -1 for part in config.all_parts: step = part.last_step() if step: index = common.COMMAND_ORDER.index(step) if index > max_index: max_index = index # If no parts have been pulled, remove the parts directory. In most cases # this directory should have already been cleaned, but this handles the # case of a failed pull. Note however that the presence of local plugins # should prevent this removal. if (max_index < common.COMMAND_ORDER.index('pull') and os.path.exists(common.get_partsdir()) and not os.path.exists(common.get_local_plugindir())): logger.info('Cleaning up parts directory') shutil.rmtree(common.get_partsdir()) # If no parts have been staged, remove staging area. should_remove_stagedir = max_index < common.COMMAND_ORDER.index('stage') if should_remove_stagedir and os.path.exists(common.get_stagedir()): logger.info('Cleaning up staging area') shutil.rmtree(common.get_stagedir()) # If no parts have been stripped, remove snapping area. should_remove_snapdir = max_index < common.COMMAND_ORDER.index('strip') if should_remove_snapdir and os.path.exists(common.get_snapdir()): logger.info('Cleaning up snapping area') shutil.rmtree(common.get_snapdir())
def test_local_plugin_not_removed(self): self.make_snapcraft_yaml(n=3) local_plugin = os.path.join(common.get_local_plugindir(), "foo.py") os.makedirs(os.path.dirname(local_plugin)) open(local_plugin, "w").close() main(["clean"]) self.assertFalse(os.path.exists(common.get_stagedir())) self.assertFalse(os.path.exists(common.get_snapdir())) self.assertTrue(os.path.exists(common.get_partsdir())) self.assertTrue(os.path.isfile(local_plugin))
def _load_local(module_name): sys.path = [common.get_local_plugindir()] + sys.path module = importlib.import_module(module_name) sys.path.pop(0) return module