From 7d26326223aed9170a7d138cece171146dfc7fab Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 5 Mar 2023 23:03:46 +0200 Subject: [PATCH] Added command clean-data --- ChangeLog.txt | 3 ++- man/slpkg.1 | 8 +++++++- slpkg/main.py | 10 ++++++++++ slpkg/update_repository.py | 9 ++++++++- slpkg/views/cli_menu.py | 3 ++- slpkg/views/help_commands.py | 3 +++ 6 files changed, 32 insertions(+), 4 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index c8cc8a6d..d182d1d6 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -3,7 +3,8 @@ Updated: - Ponce repository - slpkg.toml file for ponce repository Added: -- New option --generate-only for ponce repository +- Option --generate-only for ponce repository +- Command clean-data for all the tables from the database 4.5.5 - 02/03/2023 Fixed: diff --git a/man/slpkg.1 b/man/slpkg.1 index 1aa14d04..af81ab43 100644 --- a/man/slpkg.1 +++ b/man/slpkg.1 @@ -7,7 +7,7 @@ slpkg \- Package manager utility for Slackware. slpkg \c [\fIOPTIONS\fR] [\fICOMMAND\fR] [\fIPACKAGES...\fR] .P -slpkg [-h|-v] [-u, update] [-U, upgrade] [-c, check-updates] [-g, configs] [-L, clean-logs] [-D, clean-tmp] [-b, build] [-i, install] [-d, download] +slpkg [-h|-v] [-u, update] [-U, upgrade] [-c, check-updates] [-g, configs] [-L, clean-logs] [-D, clean-tmp] [-T, clean-data] [-b, build] [-i, install] [-d, download] [-R, remove] [-f, find] [-w, view] [-s, search] [-e, dependees] [-t, tracking] -y, --yes, -j, --jobs, -o, --resolve-off, -r, --reinstall, -k, --skip-installed, -E, --full-reverse, -S, --search, -n, --no-silent, -p, --pkg-version, -z, -G, --generate-only, --directory=[\fIPATH\fR], -F, --file-pattern=[\fIPATTERN\fR] .SH DESCRIPTION @@ -45,6 +45,12 @@ Cleans dependencies log tracking. After that procedure you should remove depende Deletes all the downloaded SlackBuilds scripts and sources. .RE .P +.B -T, clean-data +.RS +Sometimes is necessary to clean all the data from the database. +Run this command to drop all the tables from the database and run `\fIslpkg update\fR` to recreate. +.RE +.P .B -g, configs .RS Edit the configuration /etc/slpkg/slpkg.toml file. diff --git a/slpkg/main.py b/slpkg/main.py index b00a377a..5cb3bd85 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -131,6 +131,7 @@ class Argparse(Configs): 'configs': [], 'clean-logs': [self.flag_yes], 'clean-tmp': [], + 'clean-data': [], 'build': [ self.flag_yes, self.flag_short_yes, @@ -221,6 +222,7 @@ class Argparse(Configs): self.commands['-g'] = self.commands['configs'] self.commands['-L'] = self.commands['clean-logs'] self.commands['-D'] = self.commands['clean-tmp'] + self.commands['-T'] = self.commands['clean-data'] self.commands['-b'] = self.commands['build'] self.commands['-i'] = self.commands['install'] self.commands['-d'] = self.commands['download'] @@ -428,7 +430,13 @@ class Argparse(Configs): self.utils.create_folder(path=self.tmp_slpkg, folder='build') raise SystemExit() + self.usage.help(1) + def clean_data(self) -> None: + if len(self.args) == 1: + update = UpdateRepository(self.flags) + update.drop_the_tables() + raise SystemExit() self.usage.help(1) def build(self) -> None: @@ -616,6 +624,8 @@ def main(): '-L': argparse.clean_logs, 'clean-tmp': argparse.clean_tmp, '-D': argparse.clean_tmp, + 'clean-database': argparse.clean_data, + '-T': argparse.clean_data, 'build': argparse.build, '-b': argparse.build, 'install': argparse.install, diff --git a/slpkg/update_repository.py b/slpkg/update_repository.py index faa32b2f..cbfab947 100644 --- a/slpkg/update_repository.py +++ b/slpkg/update_repository.py @@ -14,7 +14,7 @@ from slpkg.views.views import ViewMessage from slpkg.progress_bar import ProgressBar from slpkg.check_updates import CheckUpdates from slpkg.models.models import session as Session -from slpkg.models.models import SBoTable, PonceTable +from slpkg.models.models import Base, engine, SBoTable, PonceTable, LogsDependencies class UpdateRepository(Configs, Utilities): @@ -118,3 +118,10 @@ class UpdateRepository(Configs, Utilities): else: self.session.query(SBoTable).delete() self.session.commit() + + @staticmethod + def drop_the_tables(): + """ Drop all the tables from the database. """ + Base.metadata.drop_all(bind=engine, tables=[PonceTable.__table__, + SBoTable.__table__, + LogsDependencies.__table__]) diff --git a/slpkg/views/cli_menu.py b/slpkg/views/cli_menu.py index 699e4d27..6217a579 100644 --- a/slpkg/views/cli_menu.py +++ b/slpkg/views/cli_menu.py @@ -22,7 +22,7 @@ class Usage(Configs): args = ( f'Usage: {self.prog_name} [{self.yellow}OPTIONS{self.endc}] [{self.cyan}COMMAND{self.endc}] [PACKAGES...]\n' f'\n slpkg [{self.cyan}COMMAND{self.endc}] [-u, update, -U, upgrade, -c, check-updates]\n' - f' slpkg [{self.cyan}COMMAND{self.endc}] [-L, clean-logs, -D, clean-tmp, -g, configs]\n' + f' slpkg [{self.cyan}COMMAND{self.endc}] [-L, clean-logs, -D, clean-tmp, -T, clean-data, -g, configs]\n' f' slpkg [{self.cyan}COMMAND{self.endc}] [-b, build, -i, install, -d, download] [packages...]\n' f' slpkg [{self.cyan}COMMAND{self.endc}] [-R, remove, -f, find, -w, view, -s, search] [packages...]\n' f' slpkg [{self.cyan}COMMAND{self.endc}] [-e, dependees, -t, tracking] [packages...]\n' @@ -48,6 +48,7 @@ class Usage(Configs): f' {self.cyan}-g, configs{self.endc} Edit the configuration file.\n' f' {self.cyan}-L, clean-logs{self.endc} Clean dependencies log tracking.\n' f' {self.cyan}-D, clean-tmp{self.endc} Delete all the downloaded sources.\n' + f' {self.cyan}-T, clean-data{self.endc} Clean all the data from the database.\n' f' {self.cyan}-b, build{self.endc} [packages...] Build only the packages.\n' f' {self.cyan}-i, install{self.endc} [packages...] Build and install the packages.\n' f' {self.cyan}-d, download{self.endc} [packages...] Download only the scripts and sources.\n' diff --git a/slpkg/views/help_commands.py b/slpkg/views/help_commands.py index c10c0637..86448fe5 100644 --- a/slpkg/views/help_commands.py +++ b/slpkg/views/help_commands.py @@ -30,6 +30,8 @@ class Help(Configs): 'clean-logs': "Cleans dependencies log tracking. After that procedure you should remove dependencies " "by hand.", 'clean-tmp': "Deletes all the downloaded SlackBuilds scripts and sources.", + 'clean-data': "Sometimes is necessary to clean all the data from the database. Run this command to drop " + "all the tables from the database and run 'slpkg update' to recreate.", 'build': "Builds the Slackbuilds scripts and adds them to the /tmp directory.", 'install': "Builds and installs the packages in the correct order, and also logs the packages with the " "dependencies for removal.", @@ -50,6 +52,7 @@ class Help(Configs): help_commands['-g'] = help_commands['configs'] help_commands['-L'] = help_commands['clean-logs'] help_commands['-D'] = help_commands['clean-tmp'] + help_commands['-T'] = help_commands['clean-data'] help_commands['-b'] = help_commands['build'] help_commands['-i'] = help_commands['install'] help_commands['-d'] = help_commands['download']