The personal URL shortener
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

39 lines
1.1 KiB

import os
import logging
# Setup logging
logger = logging.getLogger(__name__)
def normalize_path(path: str) -> str:
"""
Method to expand and return an absolute
path from a normal path.
:param path: The path to normalize.
:returns: The absolute path.
"""
logger.debug("Normalizing path: %s", path)
exp_path = os.path.expanduser(path)
abs_path = os.path.abspath(exp_path)
logger.debug("Normalized path: %s", abs_path)
return abs_path
def check_file(path: str) -> str:
"""
Method to normalize the path of a file and
check if the file exists and is a file.
:param path: The file path to check.
:returns: The absolute path of a file.
:raises: FileNotFoundError
"""
logger.debug("Checking file: %s", path)
file_path = normalize_path(path)
if not os.path.exists(file_path) or not os.path.isfile(file_path):
logger.error("File '%s' not found, raising exception", file_path)
raise FileNotFoundError
logger.debug("File '%s' found, returning path", file_path)
return file_path