Update supporting script

- Update README to properly reflect py3.9 requirement
- Add support for `--force` that's been advertised forever
This commit is contained in:
Trysdyn Black 2024-10-10 15:38:25 -07:00
parent 3033ba4380
commit 508fad2e2c
2 changed files with 12 additions and 5 deletions

View file

@ -6,7 +6,7 @@ In essence this repo will mimic the layout of my homedir with a bunch of dotfile
The setup_dotfiles.py script takes the contents of this path and creates symlinks in my actual homedir, matching the directory structure.
## Requirements
* Python 3.4
* Python 3.9
* A home directory
## Setup

View file

@ -8,6 +8,7 @@ removing old symlinks as necessary as well as optionally files.
import inspect
import os # Needed for os.walk til Py3.12
import sys
from pathlib import Path
FORCE = False
@ -31,6 +32,7 @@ def check_and_remove(source: Path, destination: Path, *, force: bool = False) ->
# Destination exists as a symlink
if Path(destination).is_symlink():
# Symlink is correct, return
# This is the only function that bumps our requirement to py3.9, lol
if Path(destination).readlink() == source:
return False
# Symlink is incorrect, remove it
@ -40,10 +42,10 @@ def check_and_remove(source: Path, destination: Path, *, force: bool = False) ->
# Force mode enabled, remove it (Data loss risk!!)
if force:
Path(destination).unlink()
# Force mode disabled, error out
# Force mode disabled, skip this file
else:
msg = f"{destination!s} exists as a file and --force not provided"
raise OSError(msg)
print(f"{destination!s} exists as a file and --force not provided")
return False
# File doesn't exist or undefined "thing" happened, return True to try to
# write, and if something goes wrong, we'll see the OSError
@ -81,4 +83,9 @@ def install_dotfiles(source_dir: Path, dest_dir: Path, exclusions: list, *, forc
if __name__ == "__main__":
install_dotfiles(SOURCEDIR, HOMEDIR, EXCLUSIONS, force=False)
force = "--force" in sys.argv
if force:
print("--force enabled, will remove files to create symlinks")
install_dotfiles(SOURCEDIR, HOMEDIR, EXCLUSIONS, force=force)