Remove maybe_cleanup util function

It was used in exactly one place, and could be inlined with
minimal loss of clarity
pull/494/head
yuvipanda 2018-12-10 23:12:42 -08:00
rodzic 30e69bccee
commit ee9b150ef8
2 zmienionych plików z 6 dodań i 12 usunięć

Wyświetl plik

@ -35,7 +35,7 @@ from .buildpacks import (
)
from . import contentproviders
from .utils import (
ByteSpecification, maybe_cleanup, is_valid_docker_image_name,
ByteSpecification, is_valid_docker_image_name,
validate_and_generate_port_mapping, chdir
)
@ -703,9 +703,7 @@ class Repo2Docker(Application):
else:
checkout_path = self.git_workdir
# keep as much as possible in the context manager to make sure we
# cleanup if things go wrong
with maybe_cleanup(checkout_path, self.cleanup_checkout):
try:
self.fetch(self.repo, self.ref, checkout_path)
if self.subdir:
@ -751,6 +749,10 @@ class Repo2Docker(Application):
else:
self.log.info(json.dumps(l),
extra=dict(phase='building'))
finally:
# Cheanup checkout if necessary
if self.cleanup_checkout:
shutil.rmtree(checkout_path, ignore_errors=True)
if self.push:
self.push_image()

Wyświetl plik

@ -69,14 +69,6 @@ def chdir(path):
os.chdir(old_dir)
@contextmanager
def maybe_cleanup(path, cleanup=False):
"""Delete the directory at passed path if cleanup flag is True."""
yield
if cleanup:
shutil.rmtree(path, ignore_errors=True)
def validate_and_generate_port_mapping(port_mapping):
"""
Validate the port mapping list and return a list of validated tuples.