Added option --directory=

This commit is contained in:
Dimitris Zlatanidis 2023-01-16 20:29:33 +02:00
parent 75c16878f9
commit 3bd4644e77
6 changed files with 40 additions and 9 deletions

View file

@ -1,3 +1,7 @@
4.5.1 - 16/01/2023
Added:
- Option --directory= for download command
4.5.0 - 14/01/2023 4.5.0 - 14/01/2023
Updated: Updated:
- Download first all the slackbuilds - Download first all the slackbuilds

View file

@ -57,7 +57,7 @@ Construit les scripts des Slackbuilds et les ajoute au répertoire \fB/tmp\fP.
Construit et installe les paquets dans l'ordre adéquat et enregistre également les paquets avec les dépendances à utiliser pour la suppression. Construit et installe les paquets dans l'ordre adéquat et enregistre également les paquets avec les dépendances à utiliser pour la suppression.
.RE .RE
.P .P
.B -d, download --yes, --search, --no-silent .B -d, download --yes, --search, --no-silent, --directory=
.RS .RS
Télécharger les scripts et les sources des SlackBuilds sans les construire ni les installer. Télécharger les scripts et les sources des SlackBuilds sans les construire ni les installer.
.RE .RE
@ -139,6 +139,11 @@ Essayez par exemple : \fB`slpkg install python3 --search`\fP ou \fB`slpkg downlo
Désactive le mode silencieux s'il est activé dans le fichier de configuration. Désactive le mode silencieux s'il est activé dans le fichier de configuration.
.RE .RE
.P .P
--directory=
.RS
Le répertoire est le chemin où les fichiers seront enregistrés.
.RE
.P
-h | --help -h | --help
.RS .RS
Affiche l'aide. Affiche l'aide.

View file

@ -57,7 +57,7 @@ Builds the Slackbuilds scripts and adds them to the /tmp directory.
Builds and installs the packages in the correct order and also logs the packages with dependencies to use for removal. Builds and installs the packages in the correct order and also logs the packages with dependencies to use for removal.
.RE .RE
.P .P
.B -d, download --yes, --search, --no-silent .B -d, download --yes, --search, --no-silent, --directory=
.RS .RS
Download the SlackBuilds scripts and the sources without building or installing it. Download the SlackBuilds scripts and the sources without building or installing it.
.RE .RE
@ -139,6 +139,11 @@ Example try: `slpkg install python3 --search` or `slpkg download python3 --searc
Disable silent mode if it is enabled in the configuration file. Disable silent mode if it is enabled in the configuration file.
.RE .RE
.P .P
--directory=
.RS
The directory is the path where the files will be saved.
.RE
.P
-h | --help -h | --help
.RS .RS
Show help information and exit. Show help information and exit.

View file

@ -14,8 +14,10 @@ from slpkg.models.models import session as Session
class Download: class Download:
""" Download the slackbuilds with the sources only. """ """ Download the slackbuilds with the sources only. """
def __init__(self, flags: list): def __init__(self, directory: str, flags: list):
self.flags = flags self.flags = flags
self.directory = directory
self.flag_directory = '--directory='
self.configs = Configs self.configs = Configs
self.session = Session self.session = Session
self.utils = Utilities() self.utils = Utilities()
@ -26,18 +28,22 @@ class Download:
view.download_packages(slackbuilds) view.download_packages(slackbuilds)
view.question() view.question()
download_path = self.configs.download_only
if self.flag_directory in self.flags:
download_path = self.directory
start = time.time() start = time.time()
for sbo in slackbuilds: for sbo in slackbuilds:
file = f'{sbo}{self.configs.sbo_tar_suffix}' file = f'{sbo}{self.configs.sbo_tar_suffix}'
location = SBoQueries(sbo).location() location = SBoQueries(sbo).location()
url = f'{self.configs.sbo_repo_url}/{location}/{file}' url = f'{self.configs.sbo_repo_url}/{location}/{file}'
down_sbo = Downloader(self.configs.download_only, url, self.flags) down_sbo = Downloader(download_path, url, self.flags)
down_sbo.download() down_sbo.download()
sources = SBoQueries(sbo).sources() sources = SBoQueries(sbo).sources()
for source in sources: for source in sources:
down_source = Downloader(self.configs.download_only, source, self.flags) down_source = Downloader(download_path, source, self.flags)
down_source.download() down_source.download()
elapsed_time = time.time() - start elapsed_time = time.time() - start

View file

@ -31,6 +31,7 @@ class Argparse:
def __init__(self, args: list): def __init__(self, args: list):
self.args = args self.args = args
self.flags = [] self.flags = []
self.directory = None
self.configs = Configs self.configs = Configs
self.dialog = DialogBox() self.dialog = DialogBox()
self.utils = Utilities() self.utils = Utilities()
@ -51,6 +52,7 @@ class Argparse:
self.flag_full_reverse = '--full-reverse' self.flag_full_reverse = '--full-reverse'
self.flag_search = '--search' self.flag_search = '--search'
self.flag_no_silent = '--no-silent' self.flag_no_silent = '--no-silent'
self.flag_directory = '--directory='
self.is_dialog_enabled() self.is_dialog_enabled()
@ -61,12 +63,18 @@ class Argparse:
self.flag_skip_installed, self.flag_skip_installed,
self.flag_full_reverse, self.flag_full_reverse,
self.flag_search, self.flag_search,
self.flag_no_silent] self.flag_no_silent,
self.flag_directory]
self.remove_flags() self.remove_flags()
def remove_flags(self): def remove_flags(self):
""" Remove flags from args. """ """ Remove flags from args. """
for arg in self.args:
if arg.startswith(self.flag_directory):
self.directory = arg.split('=')[1]
self.args[self.args.index(arg)] = self.flag_directory
for opt in self.options: for opt in self.options:
if opt in self.args: if opt in self.args:
self.args.remove(opt) self.args.remove(opt)
@ -119,7 +127,8 @@ class Argparse:
'download': [ 'download': [
self.flag_yes, self.flag_yes,
self.flag_search, self.flag_search,
self.flag_no_silent self.flag_no_silent,
self.flag_directory
], ],
'remove': [ 'remove': [
self.flag_yes, self.flag_yes,
@ -329,7 +338,7 @@ class Argparse:
self.check.database() self.check.database()
self.check.exists(packages) self.check.exists(packages)
download = Download(self.flags) download = Download(self.directory, self.flags)
download.packages(packages) download.packages(packages)
raise SystemExit() raise SystemExit()
self.usage.help(1) self.usage.help(1)

View file

@ -26,7 +26,8 @@ class Usage:
f' slpkg [{self.cyan}COMMAND{self.endc}] [-f, find, -w, view, -s, search, -e, dependees] <packages>\n' f' slpkg [{self.cyan}COMMAND{self.endc}] [-f, find, -w, view, -s, search, -e, dependees] <packages>\n'
f' slpkg [{self.cyan}COMMAND{self.endc}] [-t, tracking] <packages>\n' f' slpkg [{self.cyan}COMMAND{self.endc}] [-t, tracking] <packages>\n'
f' slpkg [{self.yellow}OPTIONS{self.endc}] [--yes, --jobs, --resolve-off, --reinstall]\n' f' slpkg [{self.yellow}OPTIONS{self.endc}] [--yes, --jobs, --resolve-off, --reinstall]\n'
f' slpkg [{self.yellow}OPTIONS{self.endc}] [--skip-installed, --full-reverse, --search, --no-silent]\n' f' slpkg [{self.yellow}OPTIONS{self.endc}] [--skip-installed, --full-reverse, --search]\n'
f' slpkg [{self.yellow}OPTIONS{self.endc}] [--no-silent, --directory=]\n'
" \nIf you need more information please try 'slpkg --help'.") " \nIf you need more information please try 'slpkg --help'.")
print(args) print(args)
@ -63,6 +64,7 @@ class Usage:
f' {self.yellow}--full-reverse{self.endc} Full reverse dependency.\n' f' {self.yellow}--full-reverse{self.endc} Full reverse dependency.\n'
f' {self.yellow}--search{self.endc} Search packages from the repository.\n' f' {self.yellow}--search{self.endc} Search packages from the repository.\n'
f' {self.yellow}--no-silent{self.endc} Disable silent mode.\n' f' {self.yellow}--no-silent{self.endc} Disable silent mode.\n'
f' {self.yellow}--directory={self.endc} Download files to a specific path.\n'
'\n -h, --help Show this message and exit.\n' '\n -h, --help Show this message and exit.\n'
' -v, --version Print version and exit.\n' ' -v, --version Print version and exit.\n'
'\nEdit the configuration file in the /etc/slpkg/slpkg.toml \n' '\nEdit the configuration file in the /etc/slpkg/slpkg.toml \n'