annotate install.py @ 471:31079b060068

Update mutt config.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 09 Apr 2019 19:09:04 -0700
parents 3b9394a0a58b
children 97412ea9b3fa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import os
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import os.path
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 import sys
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 import stat
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
5 import shutil
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 import argparse
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 import functools
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 import subprocess
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 import configparser
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 dotfiles_dir = os.path.abspath(os.path.dirname(__file__))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 is_nix = True
431
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
15 is_mac = False
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 is_windows = False
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 if sys.platform == "win32":
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 is_nix = False
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 is_windows = True
431
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
20 if sys.platform == 'darwin':
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
21 is_mac = True
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23
471
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
24 def _is_executable(fpath):
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
25 return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
26
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
27
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
28 def which(exename):
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
29 for path in os.environ.get("PATH", "").split(os.pathsep):
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
30 exepath = os.path.join(path, exename)
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
31 if _is_executable(exepath):
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
32 return exepath
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
33 return None
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
34
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
35
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
36 def _p(*paths, force_unix=False):
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
37 res = os.path.join(dotfiles_dir, *paths)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
38 if force_unix:
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
39 res = res.replace('\\', '/')
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
40 else:
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
41 res = res.replace('/', os.sep)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
42 return res
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 def nixslash(path):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46 return path.replace('\\', '/')
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49 def ensure_dir(path):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50 full_path = os.path.abspath(os.path.expanduser(path))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51 if not os.path.isdir(full_path):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 os.makedirs(full_path, mode=0o700)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55 def mklink(orig_rel_path, link_path, mode=None):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56 orig_full_path = os.path.join(dotfiles_dir, orig_rel_path)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57 link_full_path = os.path.abspath(os.path.expanduser(link_path))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58 if os.path.islink(link_full_path):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59 print("Unlinking %s" % link_full_path)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60 os.unlink(link_full_path)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61 elif os.path.exists(link_full_path):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
62 print("Removing %s" % link_full_path)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 os.remove(link_full_path)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65 print("%s -> %s" % (link_full_path, orig_full_path))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
66 os.symlink(orig_full_path, link_full_path)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
67 if mode is not None:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
68 os.chmod(link_full_path, mode)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
69
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
70
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71 def writelines(path, lines):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
72 full_path = os.path.abspath(os.path.expanduser(path))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 print("%d lines to %s" % (len(lines), full_path))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74 with open(full_path, 'w') as fp:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75 for l in lines:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76 fp.write(l)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77 fp.write('\n')
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
79
432
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
80 def _on_rmtree_err(func, name, excinfo):
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
81 os.chmod(name, stat.S_IWUSR | stat.S_IWGRP)
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
82 os.remove(name)
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
83
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
84
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
85 def rmtree(dirpath):
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
86 shutil.rmtree(dirpath, onerror=_on_rmtree_err)
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
87
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
88
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89 def only_on_nix(f):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90 @functools.wraps(f)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
91 def decorator(*args, **kwargs):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
92 if is_nix:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93 return f(*args, **kwargs)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94 return decorator
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
95
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
96
431
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
97 def only_on_mac(f):
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
98 @functools.wraps(f)
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
99 def decorator(*args, **kwargs):
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
100 if is_mac:
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
101 return f(*args, **kwargs)
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
102 return decorator
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
103
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
104
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
105 def only_on_win(f):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
106 @functools.wraps(f)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
107 def decorator(*args, **kwargs):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
108 if is_windows:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
109 return f(*args, **kwargs)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
110 return decorator
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
111
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
112
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
113 def supports_forcing(f):
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
114 f.__dotfiles_supports_forcing__ = True
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
115 return f
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
116
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
117
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
118 def needs_config(f):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
119 f.__dotfiles_needs_config__ = True
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
120 return f
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
121
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
122
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
123 def run_priority(prio):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
124 def wrapper(f):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
125 f.__dotfiles_priority__ = prio
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
126 return f
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
127 return wrapper
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
128
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
129
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
130 @only_on_nix
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
131 def install_bash():
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
132 mklink('bashrc/bashrc', '.bashrc')
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
133 mklink('bashrc/bash_profile', '.bash_profile')
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
134
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
135
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
136 @only_on_nix
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
137 def install_fish():
425
350f7a55ff33 Improve fish configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 417
diff changeset
138 ensure_dir('~/.config/fish')
350f7a55ff33 Improve fish configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 417
diff changeset
139 writelines('~/.config/fish/config.fish',
350f7a55ff33 Improve fish configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 417
diff changeset
140 ['source %s' % _p('fish', 'config.fish')])
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
141
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
142
432
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
143 @needs_config
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
144 @supports_forcing
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
145 def install_vim(cfg, force=False):
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
146 vimrc_path = '~/.vimrc'
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
147 if is_windows:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
148 vimrc_path = '~/_vimrc'
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
149 writelines(vimrc_path, [
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
150 'set runtimepath+=%s' % nixslash(_p('vim')),
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
151 'source %s' % nixslash(_p('vim', 'vimrc'))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
152 ])
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
153
432
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
154 if cfg.has_section('vimbundles'):
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
155 bundle_dir = _p('vim', 'bundle')
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
156 os.makedirs(bundle_dir, exist_ok=True)
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
157 existing_plugins = set(os.listdir(bundle_dir))
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
158
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
159 for name, url in cfg.items('vimbundles'):
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
160 path = os.path.join(bundle_dir, name)
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
161 if url.startswith('[git]'):
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
162 clone_git(url[len('[git]'):], path, force=force)
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
163 else:
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
164 clone_hg(url, path, force=force)
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
165
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
166 existing_plugins.discard(name)
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
167
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
168 for name in existing_plugins:
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
169 print("Removing plugin %s" % name)
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
170 path = os.path.join(bundle_dir, name)
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
171 rmtree(path)
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
172
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
173
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
174 @run_priority(2) # Needs to run before `fish`.
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
175 def install_mercurial():
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
176 hgrc_path = '~/.hgrc'
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
177 if is_windows:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
178 hgrc_path = '~/mercurial.ini'
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
179 writelines(hgrc_path, [
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
180 '%%include %s' % _p('hgrc/hgrc'),
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
181 '[ui]',
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
182 'ignore = %s' % _p('hgrc/hgignore'),
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
183 '[subrepos]',
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
184 'git:allowed = true',
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
185 '[extensions]',
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
186 'hggit = %s' % _p('lib/hg/hg-git/hggit/'),
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
187 'onsub = %s' % _p('lib/hg/onsub/onsub.py'),
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
188 'allpaths = %s' % _p('lib/hg/allpaths/mercurial_all_paths.py'),
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
189 'prompt = %s' % _p('lib/hg/hg-prompt/prompt.py'),
448
cc00cbbf5460 Rename evolve extension's repo folder to `evolve`.
Ludovic Chabant <ludovic@chabant.com>
parents: 447
diff changeset
190 'evolve = %s' % _p('lib/hg/evolve/hgext3rd/evolve'),
436
8986ec3a9c1c Properly use the Mercurial log templates.
Ludovic Chabant <ludovic@chabant.com>
parents: 432
diff changeset
191 '[alias]',
8986ec3a9c1c Properly use the Mercurial log templates.
Ludovic Chabant <ludovic@chabant.com>
parents: 432
diff changeset
192 ('dlog = log --pager=yes --style=%s' %
446
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
193 _p('lib/hg/mercurial-cli-templates/map-cmdline.dlog',
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
194 force_unix=True)),
436
8986ec3a9c1c Properly use the Mercurial log templates.
Ludovic Chabant <ludovic@chabant.com>
parents: 432
diff changeset
195 ('slog = log --pager=yes --style=%s' %
446
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
196 _p('lib/hg/mercurial-cli-templates/map-cmdline.slog',
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
197 force_unix=True)),
436
8986ec3a9c1c Properly use the Mercurial log templates.
Ludovic Chabant <ludovic@chabant.com>
parents: 432
diff changeset
198 ('nlog = log --pager=yes --style=%s' %
446
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
199 _p('lib/hg/mercurial-cli-templates/map-cmdline.nlog',
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
200 force_unix=True)),
436
8986ec3a9c1c Properly use the Mercurial log templates.
Ludovic Chabant <ludovic@chabant.com>
parents: 432
diff changeset
201 ('sglog = glog --pager=yes --style=%s' %
446
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
202 _p('lib/hg/mercurial-cli-templates/map-cmdline.sglog',
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
203 force_unix=True)),
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
204 ('nglog = glog --pager=yes --style=%s' %
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
205 _p('lib/hg/mercurial-cli-templates/map-cmdline.nlog',
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
206 force_unix=True)),
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
207 ('blog = glog --page=yes --style=%s' %
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
208 _p('hgrc/logstyles')),
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
209 ('wip = glog --pager=yes --style=%s --rev wip' %
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
210 _p('hgrc/wip.style', force_unix=True))
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
211 ])
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
212 if is_nix:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
213 print("Building fast-hg-prompt...")
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
214 compile_ok = True
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
215 try:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
216 subprocess.check_call(['make'], cwd=_p('lib/hg/fast-hg-prompt'))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
217 except subprocess.CalledProcessError:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
218 compile_ok = False
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
219
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
220 for n in ['bookmark', 'remote', 'status']:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
221 link_path = os.path.expanduser('~/.local/bin/fast-hg-%s' % n)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
222 if compile_ok:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
223 mklink('lib/hg/fast-hg-prompt/fast-hg-%s' % n, link_path,
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
224 mode=(stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
225 elif os.path.islink(link_path):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
226 os.unlink(link_path)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
227 elif os.path.exists(link_path):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
228 os.remove(link_path)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
229
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
230
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
231 def install_git():
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
232 writelines('~/.gitconfig', [
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
233 '[include]',
455
1172b8484c68 Add global `gitignore` file.
Ludovic Chabant <ludovic@chabant.com>
parents: 451
diff changeset
234 ' path = %s' % _p('git/gitconfig', force_unix=True),
1172b8484c68 Add global `gitignore` file.
Ludovic Chabant <ludovic@chabant.com>
parents: 451
diff changeset
235 '[core]',
1172b8484c68 Add global `gitignore` file.
Ludovic Chabant <ludovic@chabant.com>
parents: 451
diff changeset
236 ' excludesfile = %s' % _p('git/gitignore', force_unix=True)
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
237 ])
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
238 if is_windows:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
239 subprocess.check_call(
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
240 ['setx', 'GIT_SSH',
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
241 '%USERPROFILE%\\Dropbox\\Utilities\\plink.exe'],
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
242 shell=True)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
243
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
244
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
245 @only_on_nix
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
246 def install_tmux():
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
247 mklink('tmux/tmux.conf', '~/.tmux.conf')
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
248
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
249
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
250 @only_on_nix
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
251 def install_weechat():
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
252 mklink('weechat', '~/.weechat')
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
253
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
254
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
255 @only_on_nix
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
256 def install_mutt():
471
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
257 if which('gpg2'):
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
258 gpgbin = 'gpg2'
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
259 else:
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
260 if not which('gpg'):
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
261 print("WARNING: no GPG tools seem to be installed!")
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
262 gpgbin = 'gpg'
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
263 writelines('~/.muttrc', [
471
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
264 'source "%s -dq %s |"' % (gpgbin, _p('mutt/variables.gpg')),
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
265 'source "%s"' % _p('mutt/muttrc'),
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
266 'source "%s"' % _p('lib/mutt/mutt-colors-solarized/'
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
267 'mutt-colors-solarized-dark-256.muttrc')
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
268 ])
417
6dbef23ca6bd Update subrepos if they're already cloned.
Ludovic Chabant <ludovic@chabant.com>
parents: 416
diff changeset
269
6dbef23ca6bd Update subrepos if they're already cloned.
Ludovic Chabant <ludovic@chabant.com>
parents: 416
diff changeset
270
447
48933cecdf7f Add Tridactyl config.
Ludovic Chabant <ludovic@chabant.com>
parents: 446
diff changeset
271 def install_tridactyl():
48933cecdf7f Add Tridactyl config.
Ludovic Chabant <ludovic@chabant.com>
parents: 446
diff changeset
272 cfgname = '~/_tridactylrc' if is_windows else '~/.tridactylrc'
48933cecdf7f Add Tridactyl config.
Ludovic Chabant <ludovic@chabant.com>
parents: 446
diff changeset
273 writelines(cfgname, [
48933cecdf7f Add Tridactyl config.
Ludovic Chabant <ludovic@chabant.com>
parents: 446
diff changeset
274 'source %s' % _p('tridactyl/tridactylrc')
48933cecdf7f Add Tridactyl config.
Ludovic Chabant <ludovic@chabant.com>
parents: 446
diff changeset
275 ])
48933cecdf7f Add Tridactyl config.
Ludovic Chabant <ludovic@chabant.com>
parents: 446
diff changeset
276
48933cecdf7f Add Tridactyl config.
Ludovic Chabant <ludovic@chabant.com>
parents: 446
diff changeset
277
470
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
278 def install_qutebrowser():
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
279 if is_mac:
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
280 config_dir = '~/.qutebrowser'
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
281 elif is_windows:
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
282 config_dir = '%s/qutebrowser/' % os.getenv('APPDATA')
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
283 else:
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
284 config_dir = '~/.config/qutebrowser'
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
285
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
286 mklink('qutebrowser', config_dir)
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
287
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
288
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
289 def _on_error_try_make_readable(func, path, exc_info):
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
290 if not os.access(path, os.W_OK):
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
291 os.chmod(path, stat.S_IWUSR)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
292 func(path)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
293 else:
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
294 raise
446
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
295
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
296
438
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
297 def _is_non_empty_dir_with(path, contains=None):
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
298 if not os.path.isdir(path):
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
299 return False
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
300 if isinstance(contains, str):
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
301 contains = [contains]
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
302 for cnt in contains:
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
303 if not os.path.exists(os.path.join(path, cnt)):
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
304 return False
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
305 return True
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
306
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
307
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
308 def clone_git(url, path, force=False):
438
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
309 if _is_non_empty_dir_with(path, '.git'):
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
310 if not force:
417
6dbef23ca6bd Update subrepos if they're already cloned.
Ludovic Chabant <ludovic@chabant.com>
parents: 416
diff changeset
311 print("git pull origin master %s" % path)
6dbef23ca6bd Update subrepos if they're already cloned.
Ludovic Chabant <ludovic@chabant.com>
parents: 416
diff changeset
312 subprocess.check_call(['git', 'pull', 'origin', 'master'],
6dbef23ca6bd Update subrepos if they're already cloned.
Ludovic Chabant <ludovic@chabant.com>
parents: 416
diff changeset
313 cwd=path)
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
314 return
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
315 else:
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
316 print("Deleting existing: %s" % path)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
317 shutil.rmtree(path, onerror=_on_error_try_make_readable)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
318
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
319 print("git clone %s %s" % (url, path))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
320 ensure_dir(os.path.dirname(path))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
321 subprocess.check_call(['git', 'clone', url, path])
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
322
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
323
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
324 def clone_hg(url, path, force=False):
438
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
325 if _is_non_empty_dir_with(path, '.hg'):
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
326 if not force:
417
6dbef23ca6bd Update subrepos if they're already cloned.
Ludovic Chabant <ludovic@chabant.com>
parents: 416
diff changeset
327 print("hg pull -u %s" % path)
6dbef23ca6bd Update subrepos if they're already cloned.
Ludovic Chabant <ludovic@chabant.com>
parents: 416
diff changeset
328 subprocess.check_call(['hg', 'pull', '-u'], cwd=path)
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
329 return
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
330 else:
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
331 print("Deleting existing: %s" % path)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
332 shutil.rmtree(path, onerror=_on_error_try_make_readable)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
333
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
334 print("hg clone %s %s" % (url, path))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
335 ensure_dir(os.path.dirname(path))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
336 env = dict(os.environ)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
337 env.update({'HGPLAIN': '1'})
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
338 subprocess.check_call(['hg', 'clone', url, path], env=env)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
339
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
340
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
341 @needs_config
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
342 @supports_forcing
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
343 @run_priority(100)
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
344 def install_subrepos(cfg, force=False):
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
345 if not cfg.has_section('subrepos'):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
346 return
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
347
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
348 for path, url in cfg.items('subrepos'):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
349 full_path = _p(path)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
350 if url.startswith('[git]'):
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
351 clone_git(url[len('[git]'):], full_path, force=force)
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
352 else:
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
353 clone_hg(url, full_path, force=force)
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
354
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
355
431
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
356 @only_on_mac
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
357 @run_priority(210)
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
358 def install_xcode():
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
359 if shutil.which('xcodebuild') is None:
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
360 print("Installing XCode")
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
361 subprocess.check_call(['xcode-select', '--install'])
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
362 subprocess.check_call(['sudo', 'xcodebuild', '-license', 'accept'])
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
363
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
364
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
365 @only_on_mac
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
366 @run_priority(209)
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
367 def install_homebrew():
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
368 if shutil.which('brew') is None:
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
369 print("Installing Homebrew and Homebrew Cask")
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
370 subprocess.check_call([
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
371 '/usr/bin/ruby', '-e',
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
372 "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"]) # NOQA
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
373 subprocess.check_call(['brew', 'tap', 'caskroom/fonts'])
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
374
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
375
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
376 @only_on_mac
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
377 @needs_config
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
378 @supports_forcing
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
379 @run_priority(208)
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
380 def install_mactools(cfg, force=False):
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
381 if not cfg.has_section('mactools'):
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
382 return
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
383
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
384 for name, _ in cfg.items('mactools'):
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
385 args = ['brew', 'install', name]
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
386 if force:
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
387 args.append('--force')
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
388 subprocess.check_call(args)
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
389
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
390
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
391 def main():
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
392 print("dotfiles installer")
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
393 print("python %s" % sys.version)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
394 print("on %s" % sys.platform)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
395 print('')
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
396
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
397 cfg = configparser.ConfigParser()
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
398 cfg.read(_p('install.cfg'))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
399
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
400 # Get all the methods in this module that are named `install_xxx`.
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
401 mod_names = ['all']
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
402 this_mod = sys.modules[__name__]
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
403 for an in dir(this_mod):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
404 if not an.startswith('install_'):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
405 continue
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
406
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
407 name = an[len('install_'):]
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
408 mod_names.append(name)
417
6dbef23ca6bd Update subrepos if they're already cloned.
Ludovic Chabant <ludovic@chabant.com>
parents: 416
diff changeset
409
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
410 # See if we have any local install script.
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
411 local_mod = None
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
412 local_install_py = os.path.join(dotfiles_dir, 'local',
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
413 'local_install.py')
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
414 if os.path.isfile(local_install_py):
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
415 import importlib.util
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
416 spec = importlib.util.spec_from_file_location('local_install',
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
417 local_install_py)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
418 local_mod = importlib.util.module_from_spec(spec)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
419 spec.loader.exec_module(local_mod)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
420 sys.modules['local_install'] = local_mod
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
421
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
422 # Create the parser, where you can specify one or more install target.
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
423 parser = argparse.ArgumentParser()
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
424 parser.add_argument(
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
425 'module', nargs='*',
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
426 choices=mod_names,
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
427 help="Which module(s) to install. Defaults to all modules.")
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
428 parser.add_argument(
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
429 '-f', '--force', action='store_true',
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
430 help="Force installation by overwriting things.")
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
431 args = parser.parse_args()
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
432
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
433 # Get the list of methods to run.
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
434 funcs = []
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
435 selected_mods = set(args.module)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
436 if 'all' in selected_mods:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
437 selected_mods = set(mod_names)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
438 selected_mods.remove('all')
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
439 for mn in selected_mods:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
440 func = getattr(this_mod, 'install_%s' % mn)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
441 funcs.append((mn, func))
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
442 # See if there's a local method too for this.
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
443 if local_mod is not None:
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
444 local_func = getattr(local_mod, 'install_%s' % mn, None)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
445 if local_func is not None:
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
446 lmn = '%s (local)' % mn
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
447 funcs.append((lmn, local_func))
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
448
438
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
449 failed_installs = []
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
450 funcs = sorted(funcs, key=_get_install_func_priority, reverse=True)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
451 for name, func in funcs:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
452 print("Installing %s" % name)
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
453
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
454 f_args = []
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
455 f_kwargs = {}
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
456 if getattr(func, '__dotfiles_needs_config__', False):
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
457 f_args.append(cfg)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
458 if getattr(func, '__dotfiles_supports_forcing__', False):
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
459 f_kwargs['force'] = args.force
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
460
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
461 try:
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
462 func(*f_args, **f_kwargs)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
463 except Exception as ex:
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
464 print("ERROR: %s" % ex)
438
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
465 print("Skipping install of '%s'." % name)
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
466 failed_installs.append(name)
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
467 if failed_installs:
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
468 for name in failed_installs:
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
469 print("ERROR: failed to install '%s'." % name)
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
470
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
471
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
472 def _get_install_func_priority(func_info):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
473 func = func_info[1]
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
474 return getattr(func, '__dotfiles_priority__', 0)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
475
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
476
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
477 if __name__ == '__main__':
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
478 main()