Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/mercurial/loader.py
Show All 28 Lines | |||||
import billiard | import billiard | ||||
import hglib | import hglib | ||||
from hglib.error import CommandError | from hglib.error import CommandError | ||||
from swh.loader.core.loader import DVCSLoader | from swh.loader.core.loader import DVCSLoader | ||||
from swh.loader.core.utils import clean_dangling_folders | from swh.loader.core.utils import clean_dangling_folders | ||||
from swh.loader.exception import NotFound | from swh.loader.exception import NotFound | ||||
from swh.loader.mercurial.utils import get_minimum_env | |||||
from swh.model import identifiers | from swh.model import identifiers | ||||
from swh.model.hashutil import ( | from swh.model.hashutil import ( | ||||
DEFAULT_ALGORITHMS, | DEFAULT_ALGORITHMS, | ||||
MultiHash, | MultiHash, | ||||
hash_to_bytehex, | hash_to_bytehex, | ||||
hash_to_bytes, | hash_to_bytes, | ||||
hash_to_hex, | hash_to_hex, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | ): | ||||
self.cache1_size = cache1_size | self.cache1_size = cache1_size | ||||
self.cache2_size = cache2_size | self.cache2_size = cache2_size | ||||
self.clone_timeout = clone_timeout_seconds | self.clone_timeout = clone_timeout_seconds | ||||
self.working_directory = None | self.working_directory = None | ||||
self.bundle_path = None | self.bundle_path = None | ||||
self.heads: Dict[bytes, Any] = {} | self.heads: Dict[bytes, Any] = {} | ||||
self.releases: Dict[bytes, Any] = {} | self.releases: Dict[bytes, Any] = {} | ||||
self.last_snapshot_id: Optional[bytes] = None | self.last_snapshot_id: Optional[bytes] = None | ||||
self.old_environ = os.environ.copy() | |||||
os.environ.clear() | |||||
os.environ.update(get_minimum_env()) | |||||
def pre_cleanup(self): | def pre_cleanup(self): | ||||
"""Cleanup potential dangling files from prior runs (e.g. OOM killed | """Cleanup potential dangling files from prior runs (e.g. OOM killed | ||||
tasks) | tasks) | ||||
""" | """ | ||||
clean_dangling_folders( | clean_dangling_folders( | ||||
self.temp_directory, | self.temp_directory, | ||||
pattern_check=TEMPORARY_DIR_PREFIX_PATTERN, | pattern_check=TEMPORARY_DIR_PREFIX_PATTERN, | ||||
log=self.log, | log=self.log, | ||||
) | ) | ||||
def cleanup(self): | def cleanup(self): | ||||
"""Clean temporary working directory | """Clean temporary working directory | ||||
""" | """ | ||||
os.environ.clear() | |||||
os.environ.update(self.old_environ) | |||||
if self.bundle_path and os.path.exists(self.bundle_path): | if self.bundle_path and os.path.exists(self.bundle_path): | ||||
self.log.debug("Cleanup up working bundle %s" % self.bundle_path) | self.log.debug("Cleanup up working bundle %s" % self.bundle_path) | ||||
os.unlink(self.bundle_path) | os.unlink(self.bundle_path) | ||||
if self.working_directory and os.path.exists(self.working_directory): | if self.working_directory and os.path.exists(self.working_directory): | ||||
self.log.debug( | self.log.debug( | ||||
"Cleanup up working directory %s" % (self.working_directory,) | "Cleanup up working directory %s" % (self.working_directory,) | ||||
) | ) | ||||
rmtree(self.working_directory) | rmtree(self.working_directory) | ||||
▲ Show 20 Lines • Show All 509 Lines • Show Last 20 Lines |