logging uses expanded symlink paths
This commit is contained in:
parent
0ab63ff858
commit
38dcd77ba7
1 changed files with 23 additions and 9 deletions
|
@ -1,6 +1,8 @@
|
||||||
import os
|
import os
|
||||||
import glob
|
import glob
|
||||||
import shutil
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import dotbot
|
import dotbot
|
||||||
import dotbot.util
|
import dotbot.util
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -253,8 +255,9 @@ class Link(dotbot.Plugin):
|
||||||
def _link(self, dotfile_source, target_path_to_link_at, relative_path, canonical_path, ignore_missing):
|
def _link(self, dotfile_source, target_path_to_link_at, relative_path, canonical_path, ignore_missing):
|
||||||
'''
|
'''
|
||||||
Links link_name to source.
|
Links link_name to source.
|
||||||
:param target_path_to_link_at is the file path where we are putting a symlink back to
|
:param target_path_to_link_at is the file path where we are putting a symlink
|
||||||
dotfile_source
|
(where the file originally lived)
|
||||||
|
:param dotfile_source - source file in dotfiles directory, which file should symlink to
|
||||||
|
|
||||||
Returns true if successfully linked files.
|
Returns true if successfully linked files.
|
||||||
'''
|
'''
|
||||||
|
@ -276,29 +279,39 @@ class Link(dotbot.Plugin):
|
||||||
|
|
||||||
target_path_exists: bool = self._exists(target_path_to_link_at)
|
target_path_exists: bool = self._exists(target_path_to_link_at)
|
||||||
target_file_is_link: bool = self._is_link(target_path_to_link_at)
|
target_file_is_link: bool = self._is_link(target_path_to_link_at)
|
||||||
|
|
||||||
# get the file/ folder the symlink (located at the target path) is pointed to
|
# get the file/ folder the symlink (located at the target path) is pointed to
|
||||||
symlink_dest_at_target_path: str = self._get_link_destination(target_path_to_link_at)
|
symlink_dest_at_target_path: str = self._get_link_destination(target_path_to_link_at)
|
||||||
|
|
||||||
|
# Expanded, os style paths for reporting/ error checking
|
||||||
|
symlink_loc_clean = os.path.normpath(os.path.expanduser(target_path_to_link_at))
|
||||||
|
dotfile_source_expanded = os.path.expanduser(dotfile_source)
|
||||||
|
|
||||||
# Check case of links are present but incorrect
|
# Check case of links are present but incorrect
|
||||||
if target_file_is_link and (symlink_dest_at_target_path != dotfile_source):
|
if target_file_is_link and (symlink_dest_at_target_path != dotfile_source):
|
||||||
|
symlink_dest_clean = os.path.abspath(symlink_dest_at_target_path)
|
||||||
if target_path_exists:
|
if target_path_exists:
|
||||||
self._log.warning("Incorrect link (link exists but target is incorrect) %s -> %s"
|
self._log.warning("Incorrect link (link exists but target is incorrect):\n\t "
|
||||||
% (target_path_to_link_at, symlink_dest_at_target_path))
|
f"{symlink_loc_clean} -> {symlink_dest_clean},\n\t"
|
||||||
|
f"Expected {symlink_dest_clean}, found "
|
||||||
|
f"{dotfile_source_expanded}"
|
||||||
|
)
|
||||||
print("Link found:", symlink_dest_at_target_path, "expected", dotfile_source)
|
print("Link found:", symlink_dest_at_target_path, "expected", dotfile_source)
|
||||||
else:
|
else:
|
||||||
# Symlink is broken or dangling
|
# Symlink is broken or dangling
|
||||||
self._log.warning("Symlink Invalid %s -> %s" % (target_path_to_link_at, symlink_dest_at_target_path))
|
self._log.warning(f"Symlink Invalid:\n\t {symlink_loc_clean}"
|
||||||
|
f"\n\t -> {symlink_dest_clean}")
|
||||||
return success_flag
|
return success_flag
|
||||||
|
|
||||||
if target_path_exists: # file/ folder we want to put symlink in already exists
|
if target_path_exists: # file/ folder we want to put symlink in already exists
|
||||||
if target_file_is_link: # already checked if link pointed to wrong location,
|
if target_file_is_link: # already checked if link pointed to wrong location,
|
||||||
# so if it's a link we know it's correct
|
# so if it's a link we know it's correct
|
||||||
self._log.lowinfo("Link exists %s -> %s" % (target_path_to_link_at, dotfile_source))
|
self._log.lowinfo("Link exists %s -> %s" % (symlink_loc_clean, dotfile_source_expanded))
|
||||||
success_flag = True
|
success_flag = True
|
||||||
return success_flag
|
return success_flag
|
||||||
else: # Not a link
|
else: # Not a link
|
||||||
self._log.warning(
|
self._log.warning(
|
||||||
"%s already exists but is a regular file or directory" % target_path_to_link_at)
|
"%s already exists but is a regular file or directory" % symlink_loc_clean)
|
||||||
return success_flag
|
return success_flag
|
||||||
else:
|
else:
|
||||||
# target path doesn't exist already, so we try to create the symlink
|
# target path doesn't exist already, so we try to create the symlink
|
||||||
|
@ -307,7 +320,8 @@ class Link(dotbot.Plugin):
|
||||||
os.symlink(dotfile_source, destination)
|
os.symlink(dotfile_source, destination)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
msg = textwrap.fill(
|
msg = textwrap.fill(
|
||||||
f"Linking failed {target_path_to_link_at} -> {dotfile_source}\n ({e})", width=80, subsequent_indent=" ")
|
f"Linking failed {symlink_loc_clean} -> {dotfile_source_expanded}\n ({e})",
|
||||||
|
width=80, subsequent_indent=" ")
|
||||||
|
|
||||||
self._log.warning(msg)
|
self._log.warning(msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -316,7 +330,7 @@ class Link(dotbot.Plugin):
|
||||||
)
|
)
|
||||||
raise e
|
raise e
|
||||||
else:
|
else:
|
||||||
self._log.lowinfo("Creating link %s -> %s" % (target_path_to_link_at, dotfile_source))
|
self._log.lowinfo("Creating link %s -> %s" % (symlink_loc_clean, dotfile_source_expanded))
|
||||||
success_flag = True
|
success_flag = True
|
||||||
|
|
||||||
return success_flag
|
return success_flag
|
||||||
|
|
Loading…
Reference in a new issue