diff options
| author | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2021-12-14 15:14:09 +0000 |
|---|---|---|
| committer | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2021-12-14 15:14:09 +0000 |
| commit | 67bff975167c5e4158a2d1caa0a44175b23571f8 (patch) | |
| tree | 056e6c2a881230fc1a90388c142b7c890f25f6a8 | |
| parent | 4178710763ab0b05e690b26be6b8cefd0c86a1c2 (diff) | |
Rewrite deploy script in python
| -rwxr-xr-x | deploy.py | 45 | ||||
| -rwxr-xr-x | deploy.sh | 8 | ||||
| -rw-r--r-- | directoryinfo | 7 | ||||
| -rw-r--r-- | setup.sh | 0 |
4 files changed, 52 insertions, 8 deletions
diff --git a/deploy.py b/deploy.py new file mode 100755 index 0000000..466587c --- /dev/null +++ b/deploy.py @@ -0,0 +1,45 @@ +#!/usr/bin/python3 +from os import listdir +from os.path import isfile, join, abspath +from shutil import copy2 +from pathlib import Path + +home = str(Path.home()) +contents = dict() +directory = dict() + +with open('directoryinfo') as f: + lines = f.readlines() + for line in lines: + line = line.replace('%HOME', home) + + if (line.isspace()): + continue + + if (line.startswith('#')): + continue + + parts = line.split() + if parts[0] == 'copycontent': + contents[parts[1]] = parts[2] + elif parts[0] == 'copyfulldir': + directory[parts[1]] = parts[2] + else: + print(f'directoryinfo: unknown directive \'{parts[0]}\'') + +# Directive: copycontent +for d, t in contents.items(): + files = [f for f in listdir(d) if isfile(join(d, f))] + for file in files: + print(f'Copying {abspath(join(d, file))} to {abspath(join(t, file))}') + copy2(abspath(join(d, file)), join(t, file)) + +# Directive: copyfulldir +for d, t in directory.items(): + files = [f for f in listdir(d) if isfile(join(d, f))] + print(f'Creating {t}') + Path(t).mkdir(parents=True, exist_ok=True) + for file in files: + print(f'Copying {abspath(join(d, file))} to {join(t, file)}') + copy2(abspath(join(d, file)), join(t, file)) + diff --git a/deploy.sh b/deploy.sh deleted file mode 100755 index 27560e9..0000000 --- a/deploy.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -cp -a zsh/. ~ -cp -a git/. ~ -cp -a vim/. ~ - -cp -a nvim ~/.config/nvim - diff --git a/directoryinfo b/directoryinfo new file mode 100644 index 0000000..cca6945 --- /dev/null +++ b/directoryinfo @@ -0,0 +1,7 @@ +# ~ dotfiles +copycontent zsh %HOME +copycontent vim %HOME +copycontent git %HOME + +# Directories +copyfulldir nvim %HOME/.config/nvim diff --git a/setup.sh b/setup.sh deleted file mode 100644 index e69de29..0000000 --- a/setup.sh +++ /dev/null |
