comparison install.py @ 504:015e94f44cc0

Merged changes.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 30 Sep 2020 21:17:47 -0700
parents 5bbc05a69f4c
children b4d2eca00197
comparison
equal deleted inserted replaced
503:35094cf31de4 504:015e94f44cc0
3 import sys 3 import sys
4 import stat 4 import stat
5 import shutil 5 import shutil
6 import argparse 6 import argparse
7 import functools 7 import functools
8 import traceback
8 import subprocess 9 import subprocess
9 import configparser 10 import configparser
10 11
11 12
12 # Utility stuff. 13 # Utility stuff.
145 @only_on_nix 146 @only_on_nix
146 def install_fish(): 147 def install_fish():
147 ensure_dir('~/.config/fish') 148 ensure_dir('~/.config/fish')
148 writelines('~/.config/fish/config.fish', 149 writelines('~/.config/fish/config.fish',
149 ['source %s' % _p('fish', 'config.fish')]) 150 ['source %s' % _p('fish', 'config.fish')])
151
152
153 def _install_vim_bundle(cfg, cfg_section_name, bundle_dir, force=False):
154 if not cfg.has_section(cfg_section_name):
155 return
156
157 os.makedirs(bundle_dir, exist_ok=True)
158
159 # Keep track of lowercase directory names because the cfg parser stores
160 # config section names in lowercase.
161 existing_plugins = dict([(d.lower(), d) for d in os.listdir(bundle_dir)])
162
163 for name, url in cfg.items(cfg_section_name):
164 path = os.path.join(bundle_dir, name)
165 if url.startswith('[local]'):
166 pass
167 elif url.startswith('[git]'):
168 clone_git(url[len('[git]'):], path, force=force)
169 else:
170 clone_hg(url, path, force=force)
171 print()
172
173 existing_plugins.pop(name, None)
174
175 for k, name in existing_plugins.items():
176 print("Removing plugin %s" % name)
177 ok = input("OK? [Y/n]")
178 if ok.lower() == "y":
179 path = os.path.join(bundle_dir, name)
180 rmtree(path)
150 181
151 182
152 @needs_config 183 @needs_config
153 @supports_forcing 184 @supports_forcing
154 def install_vim(cfg, force=False): 185 def install_vim(cfg, force=False):
158 writelines(vimrc_path, [ 189 writelines(vimrc_path, [
159 'set runtimepath+=%s' % nixslash(_p('vim')), 190 'set runtimepath+=%s' % nixslash(_p('vim')),
160 'source %s' % nixslash(_p('vim', 'vimrc')) 191 'source %s' % nixslash(_p('vim', 'vimrc'))
161 ]) 192 ])
162 193
163 if cfg.has_section('vimbundles'): 194 _install_vim_bundle(cfg, 'vimbundles', _p('vim', 'bundle'), force)
164 bundle_dir = _p('vim', 'bundle') 195 _install_vim_bundle(cfg, 'vimbundles:local', _p('vim', 'local'), force)
165 os.makedirs(bundle_dir, exist_ok=True)
166 existing_plugins = set(os.listdir(bundle_dir))
167
168 for name, url in cfg.items('vimbundles'):
169 path = os.path.join(bundle_dir, name)
170 if url.startswith('[git]'):
171 clone_git(url[len('[git]'):], path, force=force)
172 else:
173 clone_hg(url, path, force=force)
174
175 existing_plugins.discard(name)
176
177 for name in existing_plugins:
178 print("Removing plugin %s" % name)
179 path = os.path.join(bundle_dir, name)
180 rmtree(path)
181 196
182 197
183 @run_priority(2) # Needs to run before `fish`. 198 @run_priority(2) # Needs to run before `fish`.
184 def install_mercurial(): 199 def install_mercurial():
185 hgrc_path = '~/.hgrc' 200 hgrc_path = '~/.hgrc'
366 full_path = _p(path) 381 full_path = _p(path)
367 if url.startswith('[git]'): 382 if url.startswith('[git]'):
368 clone_git(url[len('[git]'):], full_path, force=force) 383 clone_git(url[len('[git]'):], full_path, force=force)
369 else: 384 else:
370 clone_hg(url, full_path, force=force) 385 clone_hg(url, full_path, force=force)
386 print()
371 387
372 388
373 @only_on_mac 389 @only_on_mac
374 @run_priority(210) 390 @run_priority(210)
375 def install_xcode(): 391 def install_xcode():
445 print("python %s" % sys.version) 461 print("python %s" % sys.version)
446 print("on %s" % sys.platform) 462 print("on %s" % sys.platform)
447 print('') 463 print('')
448 464
449 cfg = configparser.ConfigParser() 465 cfg = configparser.ConfigParser()
450 cfg.read(_p('install.cfg')) 466 cfg.read([
467 _p('install.cfg'),
468 _p('local', 'local_install.cfg')])
451 469
452 # Get all the methods in this module that are named `install_xxx`. 470 # Get all the methods in this module that are named `install_xxx`.
453 mod_names = ['all'] 471 mod_names = ['all']
454 this_mod = sys.modules[__name__] 472 this_mod = sys.modules[__name__]
455 for an in dir(this_mod): 473 for an in dir(this_mod):
459 name = an[len('install_'):] 477 name = an[len('install_'):]
460 mod_names.append(name) 478 mod_names.append(name)
461 479
462 # See if we have any local install script. 480 # See if we have any local install script.
463 local_mod = None 481 local_mod = None
464 local_install_py = os.path.join(dotfiles_dir, 'local', 482 local_install_py = _p('local', 'local_install.py')
465 'local_install.py')
466 if os.path.isfile(local_install_py): 483 if os.path.isfile(local_install_py):
467 import importlib.util 484 import importlib.util
468 spec = importlib.util.spec_from_file_location('local_install', 485 spec = importlib.util.spec_from_file_location('local_install',
469 local_install_py) 486 local_install_py)
470 local_mod = importlib.util.module_from_spec(spec) 487 local_mod = importlib.util.module_from_spec(spec)
524 f_kwargs['force'] = args.force 541 f_kwargs['force'] = args.force
525 542
526 try: 543 try:
527 func(*f_args, **f_kwargs) 544 func(*f_args, **f_kwargs)
528 except Exception as ex: 545 except Exception as ex:
529 failed_installs.append(name) 546 failed_installs.append((name, sys.exc_info()))
530 print("ERROR: %s" % ex) 547 print("ERROR: %s" % ex)
548 traceback.print_exc()
531 if isinstance(ex, FatalInstallerError): 549 if isinstance(ex, FatalInstallerError):
532 print("Aborting all remaining installs because '%s' failed!" % name) 550 print("Aborting all remaining installs because '%s' failed!" % name)
533 break 551 break
534 else: 552 else:
535 print("Skipping install of '%s'." % name) 553 print("Skipping install of '%s'." % name)
554
555 print()
556
536 if failed_installs: 557 if failed_installs:
537 for name in failed_installs: 558 print()
559 print("----------------------------------")
560 print("ERROR: There were failed installs!")
561 for name, ex_info in failed_installs:
538 print("ERROR: failed to install '%s'." % name) 562 print("ERROR: failed to install '%s'." % name)
563 print("ERROR: %s" % ex_info[1])
564 traceback.print_exception(*ex_info)
539 565
540 566
541 def _get_install_func_priority(func_info): 567 def _get_install_func_priority(func_info):
542 func = func_info[1] 568 func = func_info[1]
543 return getattr(func, '__dotfiles_priority__', 0) 569 return getattr(func, '__dotfiles_priority__', 0)