First tests for main program arguments validation

This commit is contained in:
2024-06-14 00:54:31 -04:00
parent c0a706104f
commit 5d4d459f07
5 changed files with 106 additions and 21 deletions

View File

@@ -1,7 +1,39 @@
import argparse
import os
from pathlib import Path
import sys
def link_fixer(ln_path, tgt_dir_path):
ln_is_dir = False
link = Path(ln_path)
tgt_dir = Path(tgt_dir_path)
if link.is_dir():
ln_is_dir = True
elif not link.is_symlink():
if not link.exists():
sys.exit("Link argument matches no file or directory")
else:
sys.exit("Link argument is not a symbolic link")
elif link.exists():
sys.exit("Link is not broken!")
if not tgt_dir.exists():
sys.exit("Target directory not found.")
if not tgt_dir.is_dir():
sys.exit("Pointed target is not a directory")
print("Starting link fixer")
if ln_is_dir:
print("Links dir: \t", link)
else:
print("Link: \t\t", link)
print("Targets dir: \t", tgt_dir)
if ln_is_dir:
sys.exit("But ln dir version not yet implemented. Sorry!")
if __name__ == "__main__":
parser = argparse.ArgumentParser(
@@ -18,24 +50,4 @@ if __name__ == "__main__":
link = Path(args.link)
tgt_dir = Path(args.tgt_path)
ln_is_dir = False
if not link.is_symlink():
sys.exit("Link not found or not a symbolic link")
if link.is_dir():
ln_is_dir = True
if not tgt_dir.exists():
sys.exit("Target directory not found.")
if not tgt_dir.is_dir():
sys.exit("Pointed target is not a directory")
print("Starting link fixer")
if ln_is_dir:
print("Links dir: \t", link)
else:
print("Link: \t\t", link)
print("Targets dir: \t", tgt_dir)
if ln_is_dir:
sys.exit("But ln dir version not yet implemented. Sorry!")
link_fixer(link, tgt_dir)