Skip to content

Commit

Permalink
refactor: update modules to use new core-helpers functionalities
Browse files Browse the repository at this point in the history
  • Loading branch information
YisusChrist committed Nov 16, 2024
1 parent c2176d5 commit c8edea8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 38 deletions.
18 changes: 14 additions & 4 deletions iltransfer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@
"""

from argparse import Namespace

from core_helpers.updates import check_updates
from core_helpers.utils import exit_session
from rich import print
from rich.traceback import install

from .cli import exit_session, get_parsed_args
from .cli import get_parsed_args
from .config import configure_paths
from .consts import DEBUG, EXIT_FAILURE, EXIT_SUCCESS, GITHUB, PROFILE, VERSION
from .consts import (
DEBUG,
EXIT_FAILURE,
EXIT_SUCCESS,
GITHUB,
LOG_PATH,
PROFILE,
VERSION,
)
from .file_processing import find_and_move_folders
from .logs import logger

Expand All @@ -38,11 +48,11 @@ def main() -> None:
src_path, dest_path = configure_paths(args)
if not src_path.exists():
logger.error("Source path %s does not exist", src_path)
exit_session(EXIT_FAILURE)
exit_session(EXIT_FAILURE, LOG_PATH)

find_and_move_folders(src_path, dest_path)

exit_session(EXIT_SUCCESS)
exit_session(EXIT_SUCCESS, LOG_PATH)


if __name__ == "__main__":
Expand Down
27 changes: 1 addition & 26 deletions iltransfer/cli.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
"""Command-line interface for the project."""

import sys
from argparse import Namespace

from core_helpers.cli import ArgparseColorThemes, setup_parser
from rich import print

from .consts import DESC, EXIT_FAILURE, LOG_PATH, PACKAGE, VERSION
from .logs import logger
from .consts import DESC, PACKAGE, VERSION


def get_parsed_args() -> Namespace:
Expand Down Expand Up @@ -59,25 +56,3 @@ def get_parsed_args() -> Namespace:
)

return parser.parse_args()


def exit_session(exit_value: int) -> None:
"""
Exit the program with the given exit value.
Args:
exit_value (int): The POSIX exit value to exit with.
"""
logger.info("End of session")
# Check if the exit_value is a valid POSIX exit value
if not 0 <= exit_value <= 255:
exit_value = EXIT_FAILURE

if exit_value == EXIT_FAILURE:
print(
"\n[red]There were errors during the execution of the script. "
f"Check the logs at '{LOG_PATH}' for more information.[/]"
)

# Exit the program with the given exit value
sys.exit(exit_value)
12 changes: 9 additions & 3 deletions iltransfer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
from tkinter import filedialog
from typing import Tuple

from core_helpers.utils import exit_session
from rich import print

from .cli import exit_session
from .consts import CONFIG_FILE, DEFAULT_DEST_PATH, DEFAULT_SRC_PATH, EXIT_FAILURE
from .consts import (
CONFIG_FILE,
DEFAULT_DEST_PATH,
DEFAULT_SRC_PATH,
EXIT_FAILURE,
LOG_PATH,
)
from .logs import logger


Expand Down Expand Up @@ -127,7 +133,7 @@ def configure_paths(args: Namespace) -> Tuple[Path, Path]:

if not config_file.is_file():
logger.error("Configuration file '%s' does not exist", config_file)
exit_session(EXIT_FAILURE)
exit_session(EXIT_FAILURE, LOG_PATH)

# Read both configuration file and command-line arguments
config = ConfigParser()
Expand Down
8 changes: 4 additions & 4 deletions iltransfer/consts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Constants for the project."""

from core_helpers.xdg_paths import get_user_path
from core_helpers.xdg_paths import PathType, get_user_path

try:
from importlib import metadata
Expand All @@ -12,10 +12,10 @@
GITHUB: str = metadata.metadata(__package__ or __name__)["Home-page"]
PACKAGE = metadata.metadata(__package__ or __name__)["Name"]

CONFIG_PATH = get_user_path(PACKAGE, "config")
CONFIG_PATH = get_user_path(PACKAGE, PathType.CONFIG)
CONFIG_FILE = CONFIG_PATH / f"{PACKAGE}.ini"
DATA_PATH = get_user_path(PACKAGE, "data")
LOG_PATH = get_user_path(PACKAGE, "log")
DATA_PATH = get_user_path(PACKAGE, PathType.DATA)
LOG_PATH = get_user_path(PACKAGE, PathType.LOG)
LOG_FILE = LOG_PATH / f"{PACKAGE}.log"

VERSION = __version__
Expand Down
2 changes: 1 addition & 1 deletion iltransfer/file_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path

from rich import print
from tqdm import tqdm
from tqdm import tqdm # type: ignore

from .consts import DEBUG
from .logs import logger
Expand Down

0 comments on commit c8edea8

Please sign in to comment.