xonecas.io
345
Dt

dotfiles-2020 / files

dotfiles-2020 / install.py

2.0 KB
1#!/usr/bin/env python
2"""
3Instalation script for Sean's dev environment.
4"""
5
6import sys
7
8from os import makedirs
9from os import remove
10from os.path import basename
11from os.path import dirname
12from os.path import exists
13from os.path import expanduser
14from os.path import join
15from os.path import splitext
16from shutil import copyfile
17from shutil import rmtree
18from subprocess import call
19
20
21HOME = expanduser("/home/xonecas")
22PWD = dirname(__file__)
23VIMRC = join(HOME, ".vimrc")
24VIM = join(HOME, ".vim")
25VIM_COLORS = join(HOME, ".vim", "colors")
26
27PATHOGEN_URI = "https://tpo.pe/pathogen.vim"
28
29
30def clean():
31    """ This resets everything """
32
33    if exists(VIMRC):
34        remove(VIMRC)
35
36    if exists(VIM):
37        rmtree(VIM)
38
39
40def create_vim_bundle():
41    """ Create necessary folders: .vim/bundle """
42
43    bundle = join(VIM, "bundle")
44    autoload = join(VIM, "autoload")
45
46    if not exists(bundle):
47        makedirs(bundle)
48
49    if not exists(autoload):
50        makedirs(autoload)
51
52
53def install_pathogen():
54    """ get and install the latest pathogen """
55
56    autoload = join(HOME, ".vim", "autoload", "pathogen.vim")
57
58    print(autoload)
59
60    if not exists(autoload):
61        call(["curl", "-L", PATHOGEN_URI, "-o", autoload])
62
63
64def clone_plugins():
65    """ read from the list and clone each one """
66
67    plugin_list = join(PWD, "vim_plugins.txt")
68    bundle = join(HOME, ".vim", "bundle")
69
70    with open(plugin_list) as read_file:
71        plugins_list = read_file.readlines()
72
73        for plugin_url in plugins_list:
74            plugin_url = plugin_url.rstrip()
75            foldername = splitext(basename(plugin_url))[0]
76            call(["git", "clone", plugin_url, join(bundle, foldername)])
77
78
79def setup_vim():
80    """ copy the vim file and supporting files """
81
82    if not exists(VIMRC):
83        copyfile(join(PWD, "vimrc"), VIMRC)
84
85
86def main():
87    """ Install all """
88    clean()
89
90    # vim
91    create_vim_bundle()
92    install_pathogen()
93    clone_plugins()
94    setup_vim()
95
96    print("Done.")
97    return 0
98
99
100if __name__ == "__main__":
101    sys.exit(main())