From 338d76e01eb757e4eaed3f2fff5ebdf62fa1347e Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 25 Jan 2023 22:23:31 +0200 Subject: [PATCH] Added curl downloader --- ChangeLog.txt | 1 + configs/slpkg.toml | 8 ++++++++ slpkg/configs.py | 12 ++++++++++++ slpkg/downloader.py | 12 ++++++++++-- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index fef625a1..09ba8c58 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -5,6 +5,7 @@ Updated: - manpages for options (Thanks to marav) Added: - Option --file-pattern + - Curl downloader as the second option 4.5.1 - 16/01/2023 Added: diff --git a/configs/slpkg.toml b/configs/slpkg.toml index d398933a..80db039b 100644 --- a/configs/slpkg.toml +++ b/configs/slpkg.toml @@ -51,6 +51,10 @@ # Default is true. [true/false] dialog = true + # You can choose downloader between wget and curl: + # Default is wget. + downloader = "wget" + # Wget downloader options. # -c, --continue: resume getting a partially-downloaded file. # -N, --timestamping: don't re-retrieve files unless newer. @@ -59,6 +63,10 @@ # than local. wget_options = "-c -N -q --show-progress" + # Curl downloader options. + # Pass the options you want here. + curl_options = "" + # If silent mode is true, # do not print the commands as they are executed. # Default is true. [true/false] diff --git a/slpkg/configs.py b/slpkg/configs.py index 67c5e0ec..9d50423e 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -65,9 +65,15 @@ class Configs: # Dialog utility dialog: str = True + # Downloader command. Wget and curl. + downloader = 'wget' + # Wget options wget_options = '-c -N -q --show-progress' + # Curl options + curl_options = '' + # Choose the view mode silent_mode: str = True @@ -107,9 +113,15 @@ class Configs: # Dialog utility dialog: str = config['dialog'] + # Downloader command + downloader: str = config['downloader'] + # Wget options wget_options: str = config['wget_options'] + # Curl options + curl_options: str = config['curl_options'] + # Choose the view mode silent_mode: str = config['silent_mode'] except KeyError as error: diff --git a/slpkg/downloader.py b/slpkg/downloader.py index 5173210b..e8850703 100644 --- a/slpkg/downloader.py +++ b/slpkg/downloader.py @@ -36,8 +36,16 @@ class Downloader(Configs): def wget(self): """ Wget downloader. """ - self.output = subprocess.call(f'wget {self.wget_options} --directory-prefix={self.path} "{self.url}"', - shell=True, stderr=self.stderr, stdout=self.stdout) + if self.downloader == 'wget': + self.output = subprocess.call(f'{self.downloader} {self.wget_options} --directory-prefix={self.path} ' + f'"{self.url}"', shell=True, stderr=self.stderr, stdout=self.stdout) + elif self.downloader == 'curl': + self.output = subprocess.call(f'{self.downloader} {self.curl_options} "{self.url}" --output ' + f'{self.path}/{self.filename}', shell=True, stderr=self.stderr, + stdout=self.stdout) + else: + raise SystemExit(f"{self.red}Error:{self.endc} Downloader '{self.downloader}' not supported.\n") + if self.output != 0: raise SystemExit(self.output)