From 5e7c4a1b060df5e35123b786afda143e950355e3 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Wed, 27 Nov 2019 13:22:01 -0300 Subject: [PATCH] [feature] new parameter --clean to remove configuration and cache files --- CHANGELOG.md | 5 ++++- README.md | 3 +++ bauh/api/constants.py | 1 + bauh/app.py | 5 +++++ bauh/app_args.py | 1 + bauh/view/util/util.py | 11 +++++++++++ 6 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f394ff33..94d6e02e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - i18n: - Catalan contributions by [fitojb](https://github.com/fitojb) - German contributions by [JonasLoos](https://github.com/JonasLoos) - - Italian contributions by [albanobattistella](https://github.com/albanobattistella) + - Italian contributions by [albanobattistella](https://github.com/albanobattistella) + +### Features +- New command line argument to clean the configuration and cache files: `--clean` ### Fixes - Flatpak diff --git a/README.md b/README.md index d2654fb5..3f151152 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,9 @@ Icon=/home/$USER/bauh_env/lib/python3.7/site-packages/bauh/view/resources/img/lo ### Autostart In order to autostart the application, use your Desktop Environment settings to register it as a startup application / script (**bauh --tray=1**). +### Uninstallation +Before uninstalling bauh via your package manager, consider executing `bauh --clean` to remove configuration and cache files stored in your **HOME** folder. + ### Gems ( package technology support ) #### Flatpak ( flatpak ) - The user is able to search, install, uninstall, downgrade, launch and retrieve the applications history diff --git a/bauh/api/constants.py b/bauh/api/constants.py index e216d7f2..2eceab3a 100644 --- a/bauh/api/constants.py +++ b/bauh/api/constants.py @@ -2,3 +2,4 @@ from pathlib import Path HOME_PATH = Path.home() CACHE_PATH = '{}/.cache/bauh'.format(HOME_PATH) +CONFIG_PATH = '{}/.config/bauh'.format(HOME_PATH) diff --git a/bauh/app.py b/bauh/app.py index 89140feb..25a5ce61 100755 --- a/bauh/app.py +++ b/bauh/app.py @@ -25,9 +25,14 @@ def main(): os.environ['PYTHONUNBUFFERED'] = '1' args = app_args.read() + logger = logs.new_logger(__app_name__, bool(args.logs)) app_args.validate(args, logger) + if args.clean: + util.clean_app_files() + exit(0) + i18n_key, current_i18n = translation.get_locale_keys(args.locale) default_i18n = translation.get_locale_keys(DEFAULT_I18N_KEY)[1] if i18n_key != DEFAULT_I18N_KEY else {} i18n = I18n(current_i18n, default_i18n) diff --git a/bauh/app_args.py b/bauh/app_args.py index ee7ab010..8e551f1c 100644 --- a/bauh/app_args.py +++ b/bauh/app_args.py @@ -36,6 +36,7 @@ def read() -> Namespace: parser.add_argument('--logs', action="store", default=int(os.getenv('BAUH_LOGS', 0)), choices=[0, 1], type=int, help='If the application logs should be displayed. Default: %(default)s') parser.add_argument('--show-panel', action="store_true", help='Shows the management panel after the app icon is attached to the tray.') parser.add_argument('-dmt', '--download-mthread', action="store", default=os.getenv('BAUH_DOWNLOAD_MULTITHREAD', 1), choices=[0, 1], type=int, help='If installation files should be downloaded using multi-threads (only possible if aria2c is installed). Not all gems support this feature. Check README.md. Default: %(default)s') + parser.add_argument('--clean', action="store_true", help='Removes all configuration and cache files') return parser.parse_args() diff --git a/bauh/view/util/util.py b/bauh/view/util/util.py index c4ffb795..a6ed4374 100644 --- a/bauh/view/util/util.py +++ b/bauh/view/util/util.py @@ -1,10 +1,12 @@ import os +import shutil import subprocess import sys from PyQt5.QtCore import QCoreApplication from bauh import __app_name__ +from bauh.api.constants import CACHE_PATH, CONFIG_PATH from bauh.commons.system import run_cmd from bauh.view.util import resource @@ -36,3 +38,12 @@ def get_distro(): return 'ubuntu' return 'unknown' + + +def clean_app_files(): + print('[bauh] Cleaning configuration and cache files') + for path in (CACHE_PATH, CONFIG_PATH): + print('[bauh] Deleting directory {}'.format(path)) + if os.path.exists(path): + shutil.rmtree(path) + print('[bauh] Cleaning finished')