2780
D2
dotfiles-2014 / files
dotfiles-2014 / install.py
2.4 KB
1#!/usr/bin/env python 2""" Instalation script for Sean's dev environment. 3 4 @TODO: 5 6 * Create function that reads from current enviroment and updates 7 the list of plugins, saves a copy of the current vimrc. This will be 8 make managing different setups easier. 9 10 * Change the install command to allow specifying a branch, again 11 this is to cater to multiple setups. 12 13 * Call necessary commands after each install. 14 15""" 16 17import sys 18 19from os import makedirs 20from os import remove 21from os.path import basename 22from os.path import dirname 23from os.path import exists 24from os.path import expanduser 25from os.path import join 26from os.path import splitext 27from shutil import copyfile 28from shutil import rmtree 29from subprocess import call 30 31 32HOME = expanduser("~") 33PWD = dirname(__file__) 34VIMRC = join(HOME, ".vimrc") 35VIM = join(HOME, ".vim") 36VIM_COLORS = join(HOME, ".vim", "colors") 37 38 39def clean(): 40 """ This resets everything """ 41 42 if exists(VIMRC): 43 remove(VIMRC) 44 45 if exists(VIM): 46 rmtree(VIM) 47 48 49def create_vim_bundle(): 50 """ Create necessary folders: .vim/bundle """ 51 52 bundle = join(VIM, "bundle") 53 autoload = join(VIM, "autoload") 54 55 if not exists(bundle): 56 makedirs(bundle) 57 58 if not exists(autoload): 59 makedirs(autoload) 60 61 62def install_pathogen(): 63 """ get and install the latest pathogen """ 64 65 autoload = join(HOME, ".vim", "autoload", "pathogen.vim") 66 67 if not exists(autoload): 68 call(["curl", "-L", "https://tpo.pe/pathogen.vim", "-o", autoload]) 69 70 71def clone_plugins(): 72 """ read from the list and clone each one """ 73 74 plugin_list = join(PWD, "vim_plugins.txt") 75 bundle = join(HOME, ".vim", "bundle") 76 77 with open(plugin_list) as read_file: 78 plugins_list = read_file.readlines() 79 80 for plugin_url in plugins_list: 81 plugin_url = plugin_url.rstrip() 82 foldername = splitext(basename(plugin_url))[0] 83 call(["git", "clone", plugin_url, join(bundle, foldername)]) 84 85 86def setup_vim(): 87 """ copy the vim file and supporting files """ 88 89 if not exists(VIMRC): 90 copyfile(join(PWD, "vimrc"), VIMRC) 91 92 93def main(): 94 """ Install all """ 95 clean() 96 97 # vim 98 create_vim_bundle() 99 install_pathogen() 100 clone_plugins() 101 setup_vim() 102 103 print "Done." 104 print "Don't forget to run `rake make` in the command-T dir" 105 return 0 106 107 108if __name__ == "__main__": 109 sys.exit(main())