-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
53 lines (37 loc) · 1.62 KB
/
script.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
import sys
import subprocess
from shutil import copyfile
def check_module_exists(module_name):
result = subprocess.run(['pip3','list'], stdout=subprocess.PIPE)
#print(type(result.stdout)) # the return value is byte object
if module_name not in result.stdout.decode('utf-8'): # so we should decode it to extract proper string
subprocess.run(['pip3', 'install', module_name])
def check_file_exist(filepath, action, filename, new_path):
if os.path.isfile(filepath):
print(filepath, 'already exist, please check it')
else:
action(filename, new_path)
def check_dir_exist(dirpath, action, current_path, new_path):
if os.path.isdir(dirpath):
print(dirpath, 'already exist, please check it')
else:
action(current_path, new_path)
def rename(current_path, new_path):
os.rename(current_path, new_path)
if __name__ == '__main__':
# Step1. pip3 install GitPython, if not exist.
check_module_exists('GitPython')
home_dir = os.path.expanduser('~')
current_path = os.getcwd()
# Step2. mv vim_config .vim
dot_vim_path = home_dir + '/.vim'
check_dir_exist(dot_vim_path, os.rename, current_path, dot_vim_path)
# Step3. cp .vim/.vimrc ~
vimrc_path = home_dir + '/.vimrc'
check_file_exist(vimrc_path, copyfile, '.vimrc', vimrc_path)
# Step4. cp copy2.py ~ (for auto_copy .vimrc to .vim whenever change)
copy_py_file = home_dir + '/copy_2.py'
check_file_exist(copy_py_file, copyfile, 'copy_2.py', copy_py_file)
# Step5. download for Vundle
subprocess.run(['python3', 'auto_download.py'])