diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 5e1fd86..583f7c5 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.8.0 +current_version = 0.8.1 commit = True tag = False parse = ^ diff --git a/fichub_cli/__init__.py b/fichub_cli/__init__.py index 777f190..8088f75 100644 --- a/fichub_cli/__init__.py +++ b/fichub_cli/__init__.py @@ -1 +1 @@ -__version__ = "0.8.0" +__version__ = "0.8.1" diff --git a/fichub_cli/cli.py b/fichub_cli/cli.py index 231d0db..01a2ca6 100644 --- a/fichub_cli/cli.py +++ b/fichub_cli/cli.py @@ -13,6 +13,7 @@ # limitations under the License. import os +import json from platformdirs import PlatformDirs import typer import sys @@ -25,7 +26,7 @@ from .utils.fetch_data import FetchData from .utils.processing import get_format_type, out_dir_exists_check, \ - appdir_exists_check, appdir_builder, appdir_config_info, check_cli_outdated + appdir_builder, appdir_config_info, check_cli_outdated from fichub_cli import __version__ init(autoreset=True) # colorama init @@ -44,8 +45,8 @@ for plugin in discovered_plugins.values(): app.add_typer(plugin.app) -# check if app directory exists, if not, create it -appdir_exists_check(app_dirs) +# build/update the app directory & the config file +appdir_builder(app_dirs) # check if the cli is outdated check_cli_outdated("fichub-cli", __version__) @@ -112,10 +113,10 @@ def default( if config_init: # initialize/overwrite the config files - appdir_builder(app_dirs) + appdir_builder(app_dirs, True) if config_info: - # overwrite the config files + # show the config files and info appdir_config_info(app_dirs) # Check if the output directory exists if input is given @@ -195,10 +196,19 @@ def default( " in the current directory!" + Style.RESET_ALL) if os.path.exists("output.log"): - rm_output_log = typer.confirm( - Fore.BLUE+"Delete the output.log?", abort=False, show_default=True) - if rm_output_log is True: + with open(os.path.join(app_dirs.user_data_dir, "config.json"), 'r') as f: + config = json.load(f) + + if config["delete_output_log"] == "": + rm_output_log = typer.confirm( + Fore.BLUE+"Delete the output.log?", abort=False, show_default=True) + if rm_output_log is True: + os.remove("output.log") + elif config["delete_output_log"] == "true": os.remove("output.log") + elif config["delete_output_log"] == "false": + pass + sys.exit(fic.exit_status) diff --git a/fichub_cli/utils/processing.py b/fichub_cli/utils/processing.py index b1ff8bb..8d69227 100644 --- a/fichub_cli/utils/processing.py +++ b/fichub_cli/utils/processing.py @@ -154,17 +154,39 @@ def out_dir_exists_check(out_dir): os.makedirs(out_dir) -def appdir_builder(app_dirs): - tqdm.write( - f"Creating App directory: {app_dirs.user_data_dir}") +def appdir_builder(app_dirs, show_output = False): + + if show_output: + tqdm.write( + f"Creating App directory: {app_dirs.user_data_dir}") os.makedirs(app_dirs.user_data_dir, exist_ok=True) - tqdm.write( - f"Building the config file: {os.path.join(app_dirs.user_data_dir, 'config.json')}") - config = {'db_up_time_format': r'%Y-%m-%dT%H:%M:%S%z', - 'fic_up_time_format': r'%Y-%m-%dT%H:%M:%S'} - with open(os.path.join(app_dirs.user_data_dir, "config.json"), 'w') as f: - json.dump(config, f) + config_file = os.path.join(app_dirs.user_data_dir, 'config.json') + base_config= {'db_up_time_format': r'%Y-%m-%dT%H:%M:%S%z', + 'fic_up_time_format': r'%Y-%m-%dT%H:%M:%S', + 'delete_output_log': ''} + + if os.path.exists(config_file): + if show_output: + tqdm.write( + f"Existing config file found: {config_file}. Updating with new config if its outdated!") + with open(os.path.join(app_dirs.user_data_dir, "config.json"), 'r') as f: + existing_config = json.load(f) + for key, value in base_config.items(): + if key not in existing_config: + existing_config[key]=value + + # Update the existing config file + with open(os.path.join(app_dirs.user_data_dir, "config.json"), 'w') as f: + json.dump(existing_config, f) + + else: + if show_output: + tqdm.write( + f"Building the config file: {config_file}") + + with open(os.path.join(app_dirs.user_data_dir, "config.json"), 'w') as f: + json.dump(base_config, f) def appdir_exists_check(app_dirs): diff --git a/setup.py b/setup.py index 0e7062b..0e5c0a9 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ description="A CLI for the fichub.net API", long_description=long_description, long_description_content_type="text/markdown", - version="0.8.0", + version="0.8.1", license='Apache License', url="https://github.com/FicHub/fichub-cli", packages=find_packages(include=['fichub_cli', 'fichub_cli.*']), diff --git a/tests/test_cli.py b/tests/test_cli.py index be315db..3bcc9f8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -61,4 +61,4 @@ def test_cli_version(): assert not result.exception assert result.exit_code == 0 - assert result.output.strip() == 'fichub-cli: v0.8.0' + assert result.output.strip() == 'fichub-cli: v0.8.1'