Managing relative paths (python 3.14)
This commit is contained in:
@@ -43,6 +43,16 @@ console = Console()
|
|||||||
# FUNCTIONS
|
# 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():
|
def get_credentials():
|
||||||
"""Prompts for credentials, reiterates on login failure."""
|
"""Prompts for credentials, reiterates on login failure."""
|
||||||
while True:
|
while True:
|
||||||
@@ -159,14 +169,14 @@ def main():
|
|||||||
token, user_email = get_credentials()
|
token, user_email = get_credentials()
|
||||||
|
|
||||||
# 2. Configuration (Excel & Output)
|
# 2. Configuration (Excel & Output)
|
||||||
excel_path = questionary.path("Path to Excel file:", default=DEFAULT_EXCEL_PATH).ask()
|
excel_path = questionary.path("Path to Excel file:", default=resolve_path(DEFAULT_EXCEL_PATH)).ask()
|
||||||
if not os.path.exists(excel_path):
|
if not excel_path or not os.path.exists(excel_path):
|
||||||
console.print(f"[bold red]File not found: {excel_path}[/bold red]")
|
console.print(f"[bold red]File not found: {excel_path}[/bold red]")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Output Directory
|
# Output Directory
|
||||||
today_str = datetime.now().strftime("PDFs-%Y%m%d")
|
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()
|
output_dir = questionary.path("Output Directory:", default=default_output_dir).ask()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user