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:
parent
3033ba4380
commit
508fad2e2c
2 changed files with 12 additions and 5 deletions
|
@ -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.
|
The setup_dotfiles.py script takes the contents of this path and creates symlinks in my actual homedir, matching the directory structure.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
* Python 3.4
|
* Python 3.9
|
||||||
* A home directory
|
* A home directory
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
|
@ -8,6 +8,7 @@ removing old symlinks as necessary as well as optionally files.
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
import os # Needed for os.walk til Py3.12
|
import os # Needed for os.walk til Py3.12
|
||||||
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
FORCE = False
|
FORCE = False
|
||||||
|
@ -31,6 +32,7 @@ def check_and_remove(source: Path, destination: Path, *, force: bool = False) ->
|
||||||
# Destination exists as a symlink
|
# Destination exists as a symlink
|
||||||
if Path(destination).is_symlink():
|
if Path(destination).is_symlink():
|
||||||
# Symlink is correct, return
|
# Symlink is correct, return
|
||||||
|
# This is the only function that bumps our requirement to py3.9, lol
|
||||||
if Path(destination).readlink() == source:
|
if Path(destination).readlink() == source:
|
||||||
return False
|
return False
|
||||||
# Symlink is incorrect, remove it
|
# 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!!)
|
# Force mode enabled, remove it (Data loss risk!!)
|
||||||
if force:
|
if force:
|
||||||
Path(destination).unlink()
|
Path(destination).unlink()
|
||||||
# Force mode disabled, error out
|
# Force mode disabled, skip this file
|
||||||
else:
|
else:
|
||||||
msg = f"{destination!s} exists as a file and --force not provided"
|
print(f"{destination!s} exists as a file and --force not provided")
|
||||||
raise OSError(msg)
|
return False
|
||||||
|
|
||||||
# File doesn't exist or undefined "thing" happened, return True to try to
|
# File doesn't exist or undefined "thing" happened, return True to try to
|
||||||
# write, and if something goes wrong, we'll see the OSError
|
# 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__":
|
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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue