diff --git a/swh/loader/npm/client.py b/swh/loader/npm/client.py --- a/swh/loader/npm/client.py +++ b/swh/loader/npm/client.py @@ -138,11 +138,11 @@ tarball_request = self._request(tarball_url, throw_error=False) if tarball_request.status_code == 404: - self.log.debug('Tarball url %s returns a 404 error.' % + self.log.debug('Tarball url %s returns a 404 error.', tarball_url) self.log.debug(('Version %s of %s package will be missing and ' - 'the visit will be marked as partial.') % - (version[0], self.package)) + 'the visit will be marked as partial.'), + version[0], self.package) continue version_data = self.package_metadata['versions'][version[0]] yield self._prepare_package_version(package_source_data, @@ -150,14 +150,13 @@ def _prepare_package_version(self, package_source_data, version_data): version = version_data['version'] - self.log.debug('Processing version %s for npm package %s' % - (version, self.package)) + self.log.debug('Processing version %s for npm package %s', + version, self.package) # create temp dir to download and extract package tarball path = os.path.join(self.temp_dir, version) os.makedirs(path, exist_ok=True) filepath = os.path.join(path, package_source_data['filename']) - self.log.debug('Package local path: %s' % filepath) # download tarball url = package_source_data['url'] @@ -181,6 +180,9 @@ # uncompress tarball tarball.uncompress(filepath, path) + # remove tarball + os.remove(filepath) + # do not archive useless tarball root directory package_path = os.path.join(path, 'package') # some old packages use their name as root directory @@ -192,6 +194,8 @@ if not os.path.exists(package_path): package_path = path + self.log.debug('Package local path: %s', package_path) + package_source_data.update(hashes) # parse package.json file to add its content to revision metadata diff --git a/swh/loader/npm/loader.py b/swh/loader/npm/loader.py --- a/swh/loader/npm/loader.py +++ b/swh/loader/npm/loader.py @@ -55,7 +55,7 @@ in mid-air (OOM killed), we try and clean up dangling files. """ if self.debug: - self.log.warning('DEBUG: will not pre-clean up temp dir %s' % + self.log.warning('DEBUG: will not pre-clean up temp dir %s', self.temp_directory) return clean_dangling_folders(self.config['temp_directory'], @@ -68,11 +68,11 @@ npm source package tarballs. """ if self.debug: - self.log.warning('DEBUG: will not clean up temp dir %s' % + self.log.warning('DEBUG: will not clean up temp dir %s', self.temp_directory) return if os.path.exists(self.temp_directory): - self.log.debug('Clean up %s' % self.temp_directory) + self.log.debug('Clean up %s', self.temp_directory) shutil.rmtree(self.temp_directory) def load(self, package_name, package_url=None, @@ -244,6 +244,9 @@ package_source_data['sha1']) self.known_versions[package_key] = revision['id'] + self.log.debug('Removing unpacked package files at %s', dir_path) + shutil.rmtree(dir_path) + return not self.done def _target_from_version(self, version, sha1):