Skip to content

Commit

Permalink
Bump version: 0.8.0 → 0.8.1
Browse files Browse the repository at this point in the history
Added the config option to set the `delete_output_log` flag
  • Loading branch information
arzkar committed Aug 22, 2022
1 parent 10e0687 commit 2594411
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.8.0
current_version = 0.8.1
commit = True
tag = False
parse = ^
Expand Down
2 changes: 1 addition & 1 deletion fichub_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.8.0"
__version__ = "0.8.1"
26 changes: 18 additions & 8 deletions fichub_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import os
import json
from platformdirs import PlatformDirs
import typer
import sys
Expand All @@ -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
Expand All @@ -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__)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
40 changes: 31 additions & 9 deletions fichub_cli/utils/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.*']),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 2594411

Please sign in to comment.