Managing relative paths (python 3.14)

This commit is contained in:
2025-12-29 23:35:06 +01:00
parent 9f726b8f8a
commit 8286774ef8

View File

@@ -43,6 +43,16 @@ console = Console()
# FUNCTIONS
# -----------------------------------------------------------------------------
def resolve_path(path):
"""Returns the absolute path, resolving relative paths against the script directory."""
if not path:
return path
if not os.path.isabs(path):
# Calculate script directory
script_dir = os.path.dirname(os.path.abspath(__file__))
return os.path.normpath(os.path.join(script_dir, path))
return path
def get_credentials():
"""Prompts for credentials, reiterates on login failure."""
while True:
@@ -159,14 +169,14 @@ def main():
token, user_email = get_credentials()
# 2. Configuration (Excel & Output)
excel_path = questionary.path("Path to Excel file:", default=DEFAULT_EXCEL_PATH).ask()
if not os.path.exists(excel_path):
excel_path = questionary.path("Path to Excel file:", default=resolve_path(DEFAULT_EXCEL_PATH)).ask()
if not excel_path or not os.path.exists(excel_path):
console.print(f"[bold red]File not found: {excel_path}[/bold red]")
sys.exit(1)
# Output Directory
today_str = datetime.now().strftime("PDFs-%Y%m%d")
default_output_dir = os.path.join(DEFAULT_OUTPUT_ROOT, today_str)
default_output_dir = os.path.join(resolve_path(DEFAULT_OUTPUT_ROOT), today_str)
output_dir = questionary.path("Output Directory:", default=default_output_dir).ask()