From b7af72edd23718971d922afedf69fa813a23c747 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 19 May 2019 16:19:18 +0200 Subject: [PATCH] Moved function to utils.py Signed-off-by: Dimitris Zlatanidis --- slpkg/downloader.py | 13 ++----------- slpkg/utils.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/slpkg/downloader.py b/slpkg/downloader.py index c7795a88..593eac60 100644 --- a/slpkg/downloader.py +++ b/slpkg/downloader.py @@ -27,6 +27,7 @@ import tarfile import subprocess from slpkg.messages import Msg +from slpkg.utils import Utils from slpkg.slack.slack_version import slack_ver from slpkg.__metadata__ import MetaData as _meta_ @@ -53,7 +54,7 @@ class Download(object): dwn_count = 1 self._directory_prefix() for dwn in self.url: - self._fix_file_name(dwn.split("/")[-1]) + self.file_name = Utils().fix_file_name(dwn.split("/")[-1]) if dwn.startswith("file:///"): source_dir = dwn[7:-7].replace(slack_ver(), "") @@ -81,16 +82,6 @@ class Download(object): self._check_if_downloaded() dwn_count += 1 - def _fix_file_name(self, file_name): - """Get file name from url and fix passing char '+' - """ - if "%2b" in file_name: - self.file_name = file_name.replace("%2b", "+", 5) - elif "%2B" in file_name: - self.file_name = file_name.replace("%2B", "+", 5) - else: - self.file_name = file_name - def _make_tarfile(self, output_filename, source_dir): """Create .tar.gz file """ diff --git a/slpkg/utils.py b/slpkg/utils.py index 03cdeb10..e762bff2 100644 --- a/slpkg/utils.py +++ b/slpkg/utils.py @@ -92,6 +92,16 @@ class Utils(object): if line and not line.startswith("#"): return line + def fix_file_name(self, file_name): + """Get file name from url and fix passing char '+' + """ + if "%2b" in file_name: + return file_name.replace("%2b", "+", 5) + elif "%2B" in file_name: + return file_name.replace("%2B", "+", 5) + else: + return file_name + def debug(self, test): """Function used for print some stuff for debugging """