annotate install.py @ 492:b4d2eca00197

Ensure ctags config directory before writing config.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 19 Oct 2021 18:02:50 -0700
parents 5bbc05a69f4c
children 76defcf6bf02
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
487
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
8 import traceback
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 import subprocess
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 import configparser
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
472
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
13 # Utility stuff.
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
14
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 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
16
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 is_nix = True
431
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
18 is_mac = False
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 is_windows = False
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 if sys.platform == "win32":
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 is_nix = False
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 is_windows = True
431
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
23 if sys.platform == 'darwin':
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
24 is_mac = True
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26
471
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
27 def _is_executable(fpath):
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
28 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
29
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
30
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
31 def which(exename):
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
32 for path in os.environ.get("PATH", "").split(os.pathsep):
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
33 exepath = os.path.join(path, exename)
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
34 if _is_executable(exepath):
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
35 return exepath
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
36 return None
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
37
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
38
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
39 def _p(*paths, force_unix=False):
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
40 res = os.path.join(dotfiles_dir, *paths)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
41 if force_unix:
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
42 res = res.replace('\\', '/')
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
43 else:
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
44 res = res.replace('/', os.sep)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
45 return res
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46
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 def nixslash(path):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49 return path.replace('\\', '/')
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 def ensure_dir(path):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 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
54 if not os.path.isdir(full_path):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55 os.makedirs(full_path, mode=0o700)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58 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
59 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
60 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
61 if os.path.islink(link_full_path):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
62 print("Unlinking %s" % link_full_path)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 os.unlink(link_full_path)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64 elif os.path.exists(link_full_path):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65 print("Removing %s" % link_full_path)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
66 os.remove(link_full_path)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
67
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
68 print("%s -> %s" % (link_full_path, orig_full_path))
472
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
69 if not is_windows or os.path.isfile(orig_full_path):
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
70 os.symlink(orig_full_path, link_full_path)
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
71 else:
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
72 subprocess.check_call(['mklink', '/J', link_full_path, orig_full_path], shell=True)
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 if mode is not None:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74 os.chmod(link_full_path, mode)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77 def writelines(path, lines):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78 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
79 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
80 with open(full_path, 'w') as fp:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
81 for l in lines:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 fp.write(l)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
83 fp.write('\n')
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
84
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85
432
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
86 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
87 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
88 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
89
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
90
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
91 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
92 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
93
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
94
472
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
95 # Installer method decorators.
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
96
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
97 def only_on_nix(f):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
98 @functools.wraps(f)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
99 def decorator(*args, **kwargs):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
100 if is_nix:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
101 return f(*args, **kwargs)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
102 return decorator
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
103
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
104
431
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
105 def only_on_mac(f):
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
106 @functools.wraps(f)
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
107 def decorator(*args, **kwargs):
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
108 if is_mac:
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
109 return f(*args, **kwargs)
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
110 return decorator
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
111
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
112
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
113 def only_on_win(f):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
114 @functools.wraps(f)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
115 def decorator(*args, **kwargs):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
116 if is_windows:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
117 return f(*args, **kwargs)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
118 return decorator
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
119
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
120
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
121 def supports_forcing(f):
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
122 f.__dotfiles_supports_forcing__ = True
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
123 return f
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
124
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
125
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
126 def needs_config(f):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
127 f.__dotfiles_needs_config__ = True
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
128 return f
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
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
131 def run_priority(prio):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
132 def wrapper(f):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
133 f.__dotfiles_priority__ = prio
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
134 return f
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
135 return wrapper
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
136
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
137
472
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
138 # Installer methods.
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
139
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
140 @only_on_nix
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
141 def install_bash():
479
91652f4b9752 Fix bash config install.
Ludovic Chabant <ludovic@chabant.com>
parents: 473
diff changeset
142 mklink('bashrc/bashrc', '~/.bashrc')
91652f4b9752 Fix bash config install.
Ludovic Chabant <ludovic@chabant.com>
parents: 473
diff changeset
143 mklink('bashrc/bash_profile', '~/.bash_profile')
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
144
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
145
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
146 @only_on_nix
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
147 def install_fish():
425
350f7a55ff33 Improve fish configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 417
diff changeset
148 ensure_dir('~/.config/fish')
350f7a55ff33 Improve fish configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 417
diff changeset
149 writelines('~/.config/fish/config.fish',
350f7a55ff33 Improve fish configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 417
diff changeset
150 ['source %s' % _p('fish', 'config.fish')])
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
151
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
152
487
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
153 def _install_vim_bundle(cfg, cfg_section_name, bundle_dir, force=False):
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
154 if not cfg.has_section(cfg_section_name):
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
155 return
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
156
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
157 os.makedirs(bundle_dir, exist_ok=True)
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
158
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
159 # Keep track of lowercase directory names because the cfg parser stores
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
160 # config section names in lowercase.
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
161 existing_plugins = dict([(d.lower(), d) for d in os.listdir(bundle_dir)])
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
162
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
163 for name, url in cfg.items(cfg_section_name):
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
164 path = os.path.join(bundle_dir, name)
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
165 if url.startswith('[local]'):
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
166 pass
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
167 elif url.startswith('[git]'):
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
168 clone_git(url[len('[git]'):], path, force=force)
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
169 else:
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
170 clone_hg(url, path, force=force)
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
171 print()
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
172
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
173 existing_plugins.pop(name, None)
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
174
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
175 for k, name in existing_plugins.items():
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
176 print("Removing plugin %s" % name)
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
177 ok = input("OK? [Y/n]")
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
178 if ok.lower() == "y":
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
179 path = os.path.join(bundle_dir, name)
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
180 rmtree(path)
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
181
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
182
432
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
183 @needs_config
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
184 @supports_forcing
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
185 def install_vim(cfg, force=False):
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
186 vimrc_path = '~/.vimrc'
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
187 if is_windows:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
188 vimrc_path = '~/_vimrc'
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
189 writelines(vimrc_path, [
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
190 'set runtimepath+=%s' % nixslash(_p('vim')),
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
191 'source %s' % nixslash(_p('vim', 'vimrc'))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
192 ])
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
193
487
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
194 _install_vim_bundle(cfg, 'vimbundles', _p('vim', 'bundle'), force)
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
195 _install_vim_bundle(cfg, 'vimbundles:local', _p('vim', 'local'), force)
432
06a551d3fbb2 Move vim plugin subrepos to a separate config section, support cleaning up.
Ludovic Chabant <ludovic@chabant.com>
parents: 431
diff changeset
196
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
197
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
198 @run_priority(2) # Needs to run before `fish`.
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
199 def install_mercurial():
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
200 hgrc_path = '~/.hgrc'
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
201 if is_windows:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
202 hgrc_path = '~/mercurial.ini'
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
203 writelines(hgrc_path, [
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
204 '%%include %s' % _p('hgrc/hgrc'),
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
205 '[ui]',
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
206 'ignore = %s' % _p('hgrc/hgignore'),
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
207 '[subrepos]',
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
208 'git:allowed = true',
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
209 '[extensions]',
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
210 'hggit = %s' % _p('lib/hg/hg-git/hggit/'),
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
211 'onsub = %s' % _p('lib/hg/onsub/onsub.py'),
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
212 '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
213 '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
214 '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
215 '[alias]',
8986ec3a9c1c Properly use the Mercurial log templates.
Ludovic Chabant <ludovic@chabant.com>
parents: 432
diff changeset
216 ('dlog = log --pager=yes --style=%s' %
446
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
217 _p('lib/hg/mercurial-cli-templates/map-cmdline.dlog',
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
218 force_unix=True)),
436
8986ec3a9c1c Properly use the Mercurial log templates.
Ludovic Chabant <ludovic@chabant.com>
parents: 432
diff changeset
219 ('slog = log --pager=yes --style=%s' %
446
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
220 _p('lib/hg/mercurial-cli-templates/map-cmdline.slog',
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
221 force_unix=True)),
436
8986ec3a9c1c Properly use the Mercurial log templates.
Ludovic Chabant <ludovic@chabant.com>
parents: 432
diff changeset
222 ('nlog = log --pager=yes --style=%s' %
446
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
223 _p('lib/hg/mercurial-cli-templates/map-cmdline.nlog',
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
224 force_unix=True)),
436
8986ec3a9c1c Properly use the Mercurial log templates.
Ludovic Chabant <ludovic@chabant.com>
parents: 432
diff changeset
225 ('sglog = glog --pager=yes --style=%s' %
446
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
226 _p('lib/hg/mercurial-cli-templates/map-cmdline.sglog',
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
227 force_unix=True)),
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
228 ('nglog = glog --pager=yes --style=%s' %
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
229 _p('lib/hg/mercurial-cli-templates/map-cmdline.nlog',
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
230 force_unix=True)),
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
231 ('blog = glog --page=yes --style=%s' %
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
232 _p('hgrc/logstyles')),
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
233 ('wip = glog --pager=yes --style=%s --rev wip' %
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
234 _p('hgrc/wip.style', force_unix=True))
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
235 ])
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
236 if is_nix:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
237 print("Building fast-hg-prompt...")
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
238 compile_ok = True
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
239 try:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
240 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
241 except subprocess.CalledProcessError:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
242 compile_ok = False
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 for n in ['bookmark', 'remote', 'status']:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
245 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
246 if compile_ok:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
247 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
248 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
249 elif os.path.islink(link_path):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
250 os.unlink(link_path)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
251 elif os.path.exists(link_path):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
252 os.remove(link_path)
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 def install_git():
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
256 writelines('~/.gitconfig', [
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
257 '[include]',
455
1172b8484c68 Add global `gitignore` file.
Ludovic Chabant <ludovic@chabant.com>
parents: 451
diff changeset
258 ' path = %s' % _p('git/gitconfig', force_unix=True),
1172b8484c68 Add global `gitignore` file.
Ludovic Chabant <ludovic@chabant.com>
parents: 451
diff changeset
259 '[core]',
1172b8484c68 Add global `gitignore` file.
Ludovic Chabant <ludovic@chabant.com>
parents: 451
diff changeset
260 ' 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
261 ])
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
262 if is_windows:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
263 subprocess.check_call(
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
264 ['setx', 'GIT_SSH',
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
265 '%USERPROFILE%\\Dropbox\\Utilities\\plink.exe'],
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
266 shell=True)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
267
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
268
473
e368c8ae2a4b Fix universal ctags config on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 472
diff changeset
269 def install_universal_ctags():
e368c8ae2a4b Fix universal ctags config on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 472
diff changeset
270 # On Windows, u-ctags has a bug where it outputs double-backslashes.
e368c8ae2a4b Fix universal ctags config on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 472
diff changeset
271 if is_windows:
492
b4d2eca00197 Ensure ctags config directory before writing config.
Ludovic Chabant <ludovic@chabant.com>
parents: 487
diff changeset
272 ensure_dir('~/ctags.d')
473
e368c8ae2a4b Fix universal ctags config on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 472
diff changeset
273 writelines('~/ctags.d/global.ctags', [
e368c8ae2a4b Fix universal ctags config on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 472
diff changeset
274 '--output-format=e-ctags'
e368c8ae2a4b Fix universal ctags config on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 472
diff changeset
275 ])
e368c8ae2a4b Fix universal ctags config on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 472
diff changeset
276
e368c8ae2a4b Fix universal ctags config on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 472
diff changeset
277
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
278 @only_on_nix
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
279 def install_tmux():
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
280 mklink('tmux/tmux.conf', '~/.tmux.conf')
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
281
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
282
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
283 @only_on_nix
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
284 def install_weechat():
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
285 mklink('weechat', '~/.weechat')
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
286
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
287
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
288 @only_on_nix
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
289 def install_mutt():
471
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
290 if which('gpg2'):
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
291 gpgbin = 'gpg2'
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
292 else:
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
293 if not which('gpg'):
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
294 print("WARNING: no GPG tools seem to be installed!")
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
295 gpgbin = 'gpg'
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
296 writelines('~/.muttrc', [
471
31079b060068 Update mutt config.
Ludovic Chabant <ludovic@chabant.com>
parents: 470
diff changeset
297 '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
298 'source "%s"' % _p('mutt/muttrc'),
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
299 'source "%s"' % _p('lib/mutt/mutt-colors-solarized/'
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
300 'mutt-colors-solarized-dark-256.muttrc')
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
301 ])
417
6dbef23ca6bd Update subrepos if they're already cloned.
Ludovic Chabant <ludovic@chabant.com>
parents: 416
diff changeset
302
6dbef23ca6bd Update subrepos if they're already cloned.
Ludovic Chabant <ludovic@chabant.com>
parents: 416
diff changeset
303
447
48933cecdf7f Add Tridactyl config.
Ludovic Chabant <ludovic@chabant.com>
parents: 446
diff changeset
304 def install_tridactyl():
48933cecdf7f Add Tridactyl config.
Ludovic Chabant <ludovic@chabant.com>
parents: 446
diff changeset
305 cfgname = '~/_tridactylrc' if is_windows else '~/.tridactylrc'
48933cecdf7f Add Tridactyl config.
Ludovic Chabant <ludovic@chabant.com>
parents: 446
diff changeset
306 writelines(cfgname, [
48933cecdf7f Add Tridactyl config.
Ludovic Chabant <ludovic@chabant.com>
parents: 446
diff changeset
307 'source %s' % _p('tridactyl/tridactylrc')
48933cecdf7f Add Tridactyl config.
Ludovic Chabant <ludovic@chabant.com>
parents: 446
diff changeset
308 ])
48933cecdf7f Add Tridactyl config.
Ludovic Chabant <ludovic@chabant.com>
parents: 446
diff changeset
309
48933cecdf7f Add Tridactyl config.
Ludovic Chabant <ludovic@chabant.com>
parents: 446
diff changeset
310
470
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
311 def install_qutebrowser():
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
312 if is_mac:
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
313 config_dir = '~/.qutebrowser'
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
314 elif is_windows:
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
315 config_dir = '%s/qutebrowser/' % os.getenv('APPDATA')
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
316 else:
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
317 config_dir = '~/.config/qutebrowser'
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
318
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
319 mklink('qutebrowser', config_dir)
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
320
3b9394a0a58b Add qutebrowser config.
Ludovic Chabant <ludovic@chabant.com>
parents: 455
diff changeset
321
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
322 def _on_error_try_make_readable(func, path, exc_info):
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
323 if not os.access(path, os.W_OK):
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
324 os.chmod(path, stat.S_IWUSR)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
325 func(path)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
326 else:
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
327 raise
446
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
328
edefbb8ea16a Mercurial tweaks.
Ludovic Chabant <ludovic@chabant.com>
parents: 438
diff changeset
329
438
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
330 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
331 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
332 return False
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
333 if isinstance(contains, str):
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
334 contains = [contains]
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
335 for cnt in contains:
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
336 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
337 return False
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
338 return True
407
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
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
341 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
342 if _is_non_empty_dir_with(path, '.git'):
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
343 if not force:
417
6dbef23ca6bd Update subrepos if they're already cloned.
Ludovic Chabant <ludovic@chabant.com>
parents: 416
diff changeset
344 print("git pull origin master %s" % path)
6dbef23ca6bd Update subrepos if they're already cloned.
Ludovic Chabant <ludovic@chabant.com>
parents: 416
diff changeset
345 subprocess.check_call(['git', 'pull', 'origin', 'master'],
6dbef23ca6bd Update subrepos if they're already cloned.
Ludovic Chabant <ludovic@chabant.com>
parents: 416
diff changeset
346 cwd=path)
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
347 return
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
348 else:
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
349 print("Deleting existing: %s" % path)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
350 shutil.rmtree(path, onerror=_on_error_try_make_readable)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
351
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
352 print("git clone %s %s" % (url, path))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
353 ensure_dir(os.path.dirname(path))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
354 subprocess.check_call(['git', 'clone', url, path])
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
355
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
356
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
357 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
358 if _is_non_empty_dir_with(path, '.hg'):
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
359 if not force:
417
6dbef23ca6bd Update subrepos if they're already cloned.
Ludovic Chabant <ludovic@chabant.com>
parents: 416
diff changeset
360 print("hg pull -u %s" % path)
6dbef23ca6bd Update subrepos if they're already cloned.
Ludovic Chabant <ludovic@chabant.com>
parents: 416
diff changeset
361 subprocess.check_call(['hg', 'pull', '-u'], cwd=path)
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
362 return
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
363 else:
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
364 print("Deleting existing: %s" % path)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
365 shutil.rmtree(path, onerror=_on_error_try_make_readable)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
366
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
367 print("hg clone %s %s" % (url, path))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
368 ensure_dir(os.path.dirname(path))
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
369 env = dict(os.environ)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
370 env.update({'HGPLAIN': '1'})
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
371 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
372
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
373
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
374 @needs_config
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
375 @supports_forcing
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
376 @run_priority(100)
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
377 def install_subrepos(cfg, force=False):
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
378 if not cfg.has_section('subrepos'):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
379 return
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
380
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
381 for path, url in cfg.items('subrepos'):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
382 full_path = _p(path)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
383 if url.startswith('[git]'):
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
384 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
385 else:
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
386 clone_hg(url, full_path, force=force)
487
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
387 print()
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
388
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
389
431
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
390 @only_on_mac
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
391 @run_priority(210)
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
392 def install_xcode():
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
393 if shutil.which('xcodebuild') is None:
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
394 print("Installing XCode")
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
395 subprocess.check_call(['xcode-select', '--install'])
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
396 subprocess.check_call(['sudo', 'xcodebuild', '-license', 'accept'])
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
397
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
398
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
399 @only_on_mac
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
400 @run_priority(209)
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
401 def install_homebrew():
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
402 if shutil.which('brew') is None:
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
403 print("Installing Homebrew and Homebrew Cask")
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
404 subprocess.check_call([
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
405 '/usr/bin/ruby', '-e',
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
406 "$(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
407 subprocess.check_call(['brew', 'tap', 'caskroom/fonts'])
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
408
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
409
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
410 @only_on_mac
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
411 @needs_config
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
412 @supports_forcing
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
413 @run_priority(208)
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
414 def install_mactools(cfg, force=False):
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
415 if not cfg.has_section('mactools'):
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
416 return
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
417
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
418 for name, _ in cfg.items('mactools'):
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
419 args = ['brew', 'install', name]
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
420 if force:
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
421 args.append('--force')
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
422 subprocess.check_call(args)
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
423
e0bb52007402 Add installation of homebrew stuff on Mac.
Ludovic Chabant <ludovic@chabant.com>
parents: 425
diff changeset
424
472
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
425 @only_on_win
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
426 @run_priority(209)
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
427 def install_scoop():
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
428 if shutil.which('scoop') is None:
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
429 print("Installing Scoop")
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
430 subprocess.check_call(
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
431 '@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" '
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
432 '-NoProfile -InputFormat None -ExecutionPolicy Bypass '
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
433 '-Command "iex (new-object net.webclient).downloadstring(\'https://get.scoop.sh\')"')
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
434 subprocess.check_call(
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
435 ['scoop.cmd', 'bucket', 'add', 'extras'])
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
436 else:
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
437 print("Scoop is already installed")
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
438
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
439 @only_on_win
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
440 @needs_config
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
441 @supports_forcing
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
442 @run_priority(208)
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
443 def install_wintools(cfg, force=False):
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
444 if not cfg.has_section('wintools'):
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
445 return
473
e368c8ae2a4b Fix universal ctags config on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 472
diff changeset
446
472
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
447 for name, arch in cfg.items('wintools'):
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
448 args = ['scoop.cmd', 'install', name]
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
449 if arch:
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
450 args += ['-a', arch]
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
451 subprocess.check_call(args)
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
452
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
453
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
454 # Main stuff!
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
455
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
456 class FatalInstallerError(Exception):
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
457 pass
473
e368c8ae2a4b Fix universal ctags config on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 472
diff changeset
458
472
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
459
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
460 def main():
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
461 print("dotfiles installer")
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
462 print("python %s" % sys.version)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
463 print("on %s" % sys.platform)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
464 print('')
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
465
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
466 cfg = configparser.ConfigParser()
487
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
467 cfg.read([
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
468 _p('install.cfg'),
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
469 _p('local', 'local_install.cfg')])
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
470
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
471 # 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
472 mod_names = ['all']
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
473 this_mod = sys.modules[__name__]
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
474 for an in dir(this_mod):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
475 if not an.startswith('install_'):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
476 continue
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
477
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
478 name = an[len('install_'):]
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
479 mod_names.append(name)
417
6dbef23ca6bd Update subrepos if they're already cloned.
Ludovic Chabant <ludovic@chabant.com>
parents: 416
diff changeset
480
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
481 # See if we have any local install script.
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
482 local_mod = None
487
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
483 local_install_py = _p('local', 'local_install.py')
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
484 if os.path.isfile(local_install_py):
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
485 import importlib.util
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
486 spec = importlib.util.spec_from_file_location('local_install',
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
487 local_install_py)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
488 local_mod = importlib.util.module_from_spec(spec)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
489 spec.loader.exec_module(local_mod)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
490 sys.modules['local_install'] = local_mod
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
491
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
492 # 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
493 parser = argparse.ArgumentParser()
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
494 parser.add_argument(
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
495 'module', nargs='*',
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
496 help="Which module(s) to install. Defaults to all modules.")
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
497 parser.add_argument(
472
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
498 '-l', '--list', action='store_true',
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
499 help="List available modules to install.")
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
500 parser.add_argument(
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
501 '-f', '--force', action='store_true',
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
502 help="Force installation by overwriting things.")
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
503 args = parser.parse_args()
473
e368c8ae2a4b Fix universal ctags config on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 472
diff changeset
504
472
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
505 # Print list and exit if needed.
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
506 if args.list:
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
507 print("Available modules to install:")
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
508 for nm in mod_names:
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
509 print(nm)
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
510 print()
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
511 print("Specify 'all' to install all modules.")
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
512 return
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
513
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
514 # Get the list of methods to run.
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
515 funcs = []
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
516 selected_mods = set(args.module)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
517 if 'all' in selected_mods:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
518 selected_mods = set(mod_names)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
519 selected_mods.remove('all')
472
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
520 selected_mods.difference_update([neg[3:] for neg in args.module if neg.startswith('no-')])
473
e368c8ae2a4b Fix universal ctags config on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 472
diff changeset
521
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
522 for mn in selected_mods:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
523 func = getattr(this_mod, 'install_%s' % mn)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
524 funcs.append((mn, func))
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
525 # See if there's a local method too for this.
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
526 if local_mod is not None:
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
527 local_func = getattr(local_mod, 'install_%s' % mn, None)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
528 if local_func is not None:
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
529 lmn = '%s (local)' % mn
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
530 funcs.append((lmn, local_func))
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
531
438
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
532 failed_installs = []
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
533 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
534 for name, func in funcs:
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
535 print("Installing %s" % name)
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
536
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
537 f_args = []
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
538 f_kwargs = {}
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
539 if getattr(func, '__dotfiles_needs_config__', False):
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
540 f_args.append(cfg)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
541 if getattr(func, '__dotfiles_supports_forcing__', False):
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
542 f_kwargs['force'] = args.force
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
543
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
544 try:
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
545 func(*f_args, **f_kwargs)
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
546 except Exception as ex:
487
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
547 failed_installs.append((name, sys.exc_info()))
416
222b477ad678 Install script improvements.
Ludovic Chabant <ludovic@chabant.com>
parents: 407
diff changeset
548 print("ERROR: %s" % ex)
487
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
549 traceback.print_exc()
472
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
550 if isinstance(ex, FatalInstallerError):
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
551 print("Aborting all remaining installs because '%s' failed!" % name)
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
552 break
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
553 else:
97412ea9b3fa Improve install script, add scoop apps on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents: 471
diff changeset
554 print("Skipping install of '%s'." % name)
487
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
555
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
556 print()
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
557
438
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
558 if failed_installs:
487
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
559 print()
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
560 print("----------------------------------")
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
561 print("ERROR: There were failed installs!")
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
562 for name, ex_info in failed_installs:
438
3d999fcf62c6 Check for subrepo directories with no repos in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 437
diff changeset
563 print("ERROR: failed to install '%s'." % name)
487
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
564 print("ERROR: %s" % ex_info[1])
5bbc05a69f4c Improvements to installation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 479
diff changeset
565 traceback.print_exception(*ex_info)
407
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
566
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
567
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
568 def _get_install_func_priority(func_info):
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
569 func = func_info[1]
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
570 return getattr(func, '__dotfiles_priority__', 0)
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
571
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
572
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
573 if __name__ == '__main__':
c6da0c9f40ae Replace subrepos with an install script. Finally.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
574 main()