Téléverser les fichiers vers "/"
Argument parser only First commit
This commit is contained in:
41
link_fixer.py
Normal file
41
link_fixer.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description='''Fix broken symbolic links.
|
||||
Search for file with same name as link in target dir.
|
||||
Replace link to point to found file if any.
|
||||
'''
|
||||
|
||||
)
|
||||
parser.add_argument("link", type=str, help="Broken link, or directory with broken links")
|
||||
parser.add_argument("tgt_path", type=str, help="Directory in which to find target(s)")
|
||||
args = parser.parse_args()
|
||||
|
||||
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!")
|
||||
Reference in New Issue
Block a user