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 /deploy.py | |
| parent | 4178710763ab0b05e690b26be6b8cefd0c86a1c2 (diff) | |
Rewrite deploy script in python
Diffstat (limited to 'deploy.py')
| -rwxr-xr-x | deploy.py | 45 |
1 files changed, 45 insertions, 0 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)) + |
