-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.py
executable file
·35 lines (30 loc) · 976 Bytes
/
deploy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python
import os
import shutil
home = os.path.expanduser("~")
def mkdir_at_home(path):
"""Creates the directory specified by `path` at $HOME if it does not exist"""
dst = os.path.join(home, path)
if not os.path.exists(dst):
print("making directory {}".format(dst))
os.makedirs(dst)
def deploy_file_home(src):
"""Copy the file specified by `src` to $HOME"""
dst = os.path.join(home, src)
print("deploying {} to {}".format(src, dst))
shutil.copyfile(src, dst)
def deploy_directory_home(src):
for root, dirs, files in os.walk(src):
for d in dirs:
dst = os.path.join(root, d)
mkdir_at_home(dst)
for file in files:
dst = os.path.join(root, file)
deploy_file_home(dst)
dotfiles = "files"
os.chdir(dotfiles)
for file in os.listdir(os.getcwd()):
if os.path.isdir(file):
deploy_directory_home(file)
else:
deploy_file_home(file)