Commit 10eed80b authored by Rémi Duraffort's avatar Rémi Duraffort
Browse files

download: factorize the code and fix logging



The compression is not taken into account when the key is "ramdisk". The
logging was wrong by indicating that the file is decompressed (while it's not).

Also improve _url_to_fname by using self.

Signed-off-by: default avatarRémi Duraffort <remi.duraffort@linaro.org>
parent cfa30f6a
......@@ -149,18 +149,24 @@ class DownloadHandler(Action):
)
super().cleanup(connection)
def _url_to_fname(self, path, compression):
def _compression(self):
if self.key == "ramdisk":
return False
return self.params.get("compression", False)
def _url_to_fname(self):
compression = self._compression()
filename = os.path.basename(self.url.path)
# Don't rename files we don't decompress during download
if not compression or (compression not in self.decompress_command_map):
return os.path.join(path, filename)
return os.path.join(self.path, filename)
parts = filename.split(".")
# Files without suffixes, e.g. kernel images
if len(parts) == 1:
return os.path.join(path, filename)
return os.path.join(path, ".".join(parts[:-1]))
return os.path.join(self.path, filename)
return os.path.join(self.path, ".".join(parts[:-1]))
def validate(self):
super().validate()
......@@ -174,7 +180,7 @@ class DownloadHandler(Action):
overlay = self.params.get("overlay", False)
image_arg = self.params.get("image_arg")
self.fname = self._url_to_fname(self.path, compression)
self.fname = self._url_to_fname()
if self.fname.endswith("/"):
raise JobError("Cannot download a directory for %s" % self.key)
# Save into the namespaced data
......@@ -268,9 +274,8 @@ class DownloadHandler(Action):
"Unable to create %s: %s" % (self.path, str(exc))
)
compression = self.params.get("compression", False)
compression = self._compression()
if self.key == "ramdisk":
compression = False
self.logger.debug("Not decompressing ramdisk as can be used compressed.")
md5sum = self.params.get("md5sum")
......@@ -311,7 +316,7 @@ class DownloadHandler(Action):
"Compression %s specified but not decompressing during download",
compression,
)
else:
elif not self.params.get("compression", False):
self.logger.debug("No compression specified")
def update_progress():
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment