link_fixer for single file now works!
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
# link-fixer
|
||||
|
||||
Fix broken symbolic links. Search for file of same name in target directory and link to that target if unique and if exists.
|
||||
Fix broken symbolic links. Search for file of same name as original target in provided directory and link to that target if unique and if exists.
|
||||
@@ -3,6 +3,9 @@ import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
from search_file import search_file
|
||||
from swap_link import swap_link
|
||||
|
||||
def link_fixer(ln_path, tgt_dir_path):
|
||||
ln_is_dir = False
|
||||
|
||||
@@ -32,6 +35,9 @@ def link_fixer(ln_path, tgt_dir_path):
|
||||
print("Targets dir: \t", tgt_dir)
|
||||
if ln_is_dir:
|
||||
sys.exit("But ln dir version not yet implemented. Sorry!")
|
||||
|
||||
tgt = search_file(link.resolve().name, tgt_dir_path)
|
||||
swap_link(ln_path, tgt)
|
||||
|
||||
def fix_link(lnk, tgt_dir_path):
|
||||
return True
|
||||
|
||||
@@ -6,8 +6,8 @@ from pathlib import Path
|
||||
from os.path import relpath # won't be necessary with Python 3.12 thanks to walk_up arg in relative_to()
|
||||
|
||||
def swap_link(lnk, tgt):
|
||||
#lnk: symbolic link to swap
|
||||
#tgt: target for new link
|
||||
#lnk: symbolic link to swap, str
|
||||
#tgt: target for new link, str
|
||||
lnpath = Path(lnk)
|
||||
if not lnpath.is_symlink():
|
||||
raise Exception("First argument is not a symbolic link")
|
||||
|
||||
Reference in New Issue
Block a user