Mercurial > dotfiles
changeset 487:5bbc05a69f4c
Improvements to installation script.
- Support for local scripts and configurations.
- Support for local vim bundle.
- Better error reporting.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 24 Sep 2020 23:14:46 -0700 |
parents | b452486b97c5 |
children | 96b550ef5940 |
files | hgrc/hgrc install.cfg install.py |
diffstat | 3 files changed, 61 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/hgrc/hgrc Thu Sep 24 23:13:07 2020 -0700 +++ b/hgrc/hgrc Thu Sep 24 23:14:46 2020 -0700 @@ -33,8 +33,6 @@ delay = 1 [schemes] -bb+ssh = ssh://hg@bitbucket.org/ -bb+me = ssh://hg@bitbucket.org/ludovicchabant/ gh+ssh = git+ssh://git@github.com:{1}/{2}.git gh+me = git+ssh://git@github.com:ludovicchabant/{1}.git srht+ssh = ssh://hg@hg.sr.ht/
--- a/install.cfg Thu Sep 24 23:13:07 2020 -0700 +++ b/install.cfg Thu Sep 24 23:14:46 2020 -0700 @@ -3,15 +3,14 @@ lib/fzf = [git]https://github.com/junegunn/fzf.git -lib/hg/allpaths = https://bitbucket.org/ludovicchabant/allpaths -lib/hg/fast-hg-prompt = https://bitbucket.org/ludovicchabant/fast-hg-prompt -lib/hg/hg-git = https://bitbucket.org/durin42/hg-git -lib/hg/hg-git-sync = https://bitbucket.org/ludovicchabant/hg-git-sync -lib/hg/hg-prompt = https://bitbucket.org/sjl/hg-prompt -lib/hg/mercurial-cli-templates = https://bitbucket.org/sjl/mercurial-cli-templates +lib/hg/allpaths = https://hg.sr.ht/~ludovicchabant/allpaths +lib/hg/fast-hg-prompt = https://hg.sr.ht/~ludovicchabant/fast-hg-prompt +lib/hg/hg-git = https://foss.heptapod.net/mercurial/hg-git +lib/hg/hg-git-sync = https://hg.sr.ht/~ludovicchabant/hg-git-sync +lib/hg/hg-prompt = https://hg.stevelosh.com/hg-prompt +lib/hg/mercurial-cli-templates = https://hg.stevelosh.com/mercurial-cli-templates lib/hg/evolve = https://www.mercurial-scm.org/repo/evolve -lib/hg/onsub = https://bitbucket.org/ludovicchabant/onsub -lib/hg/path-pattern = https://bitbucket.org/Mekk/mercurial-path_pattern +lib/hg/onsub = https://hg.sr.ht/~ludovicchabant/onsub lib/iterm2/color-schemes = [git]https://github.com/mbadolato/iTerm2-Color-Schemes.git @@ -20,7 +19,7 @@ [vimbundles] ack = [git]https://github.com/mileszs/ack.vim.git -badwolf = https://bitbucket.org/sjl/badwolf +badwolf = https://hg.stevelosh.com/badwolf colorschemes = [git]https://github.com/ludovicchabant/vim-colorschemes.git commentary = [git]https://github.com/tpope/vim-commentary.git easymotion = [git]https://github.com/Lokaltog/vim-easymotion.git @@ -28,18 +27,18 @@ fugitive = [git]https://github.com/tpope/vim-fugitive.git fzf = [git]https://github.com/junegunn/fzf.vim.git goyo = [git]https://github.com/junegunn/goyo.vim.git -gundo = https://bitbucket.org/sjl/gundo.vim -gutentags = https://bitbucket.org/ludovicchabant/vim-gutentags +gundo = https://hg.stevelosh.com/gundo.vim +gutentags = https://hg.sr.ht/~ludovicchabant/vim-gutentags interestingwords = [git]https://github.com/vasconcelloslf/vim-interestingwords.git jinja = [git]https://github.com/mitsuhiko/vim-jinja.git -lawrencium = https://bitbucket.org/ludovicchabant/vim-lawrencium +lawrencium = https://hg.sr.ht/~ludovicchabant/vim-lawrencium less = [git]https://github.com/groenewege/vim-less.git lightline = [git]https://github.com/itchyny/lightline.vim.git linediff = [git]https://github.com/AndrewRadev/linediff.vim.git markdown = [git]https://github.com/tpope/vim-markdown.git nerdtree = [git]https://github.com/scrooloose/nerdtree.git pathogen = [git]https://github.com/tpope/vim-pathogen.git -piecrust = https://bitbucket.org/ludovicchabant/vim-piecrust +piecrust = https://hg.sr.ht/~ludovicchabant/vim-piecrust projectroot = [git]https://github.com/dbakker/vim-projectroot.git python-pep8-indent = [git]https://github.com/hynek/vim-python-pep8-indent.git pythonmode = [git]https://github.com/klen/python-mode.git
--- a/install.py Thu Sep 24 23:13:07 2020 -0700 +++ b/install.py Thu Sep 24 23:14:46 2020 -0700 @@ -5,6 +5,7 @@ import shutil import argparse import functools +import traceback import subprocess import configparser @@ -149,6 +150,36 @@ ['source %s' % _p('fish', 'config.fish')]) +def _install_vim_bundle(cfg, cfg_section_name, bundle_dir, force=False): + if not cfg.has_section(cfg_section_name): + return + + os.makedirs(bundle_dir, exist_ok=True) + + # Keep track of lowercase directory names because the cfg parser stores + # config section names in lowercase. + existing_plugins = dict([(d.lower(), d) for d in os.listdir(bundle_dir)]) + + for name, url in cfg.items(cfg_section_name): + path = os.path.join(bundle_dir, name) + if url.startswith('[local]'): + pass + elif url.startswith('[git]'): + clone_git(url[len('[git]'):], path, force=force) + else: + clone_hg(url, path, force=force) + print() + + existing_plugins.pop(name, None) + + for k, name in existing_plugins.items(): + print("Removing plugin %s" % name) + ok = input("OK? [Y/n]") + if ok.lower() == "y": + path = os.path.join(bundle_dir, name) + rmtree(path) + + @needs_config @supports_forcing def install_vim(cfg, force=False): @@ -160,24 +191,8 @@ 'source %s' % nixslash(_p('vim', 'vimrc')) ]) - if cfg.has_section('vimbundles'): - bundle_dir = _p('vim', 'bundle') - os.makedirs(bundle_dir, exist_ok=True) - existing_plugins = set(os.listdir(bundle_dir)) - - for name, url in cfg.items('vimbundles'): - path = os.path.join(bundle_dir, name) - if url.startswith('[git]'): - clone_git(url[len('[git]'):], path, force=force) - else: - clone_hg(url, path, force=force) - - existing_plugins.discard(name) - - for name in existing_plugins: - print("Removing plugin %s" % name) - path = os.path.join(bundle_dir, name) - rmtree(path) + _install_vim_bundle(cfg, 'vimbundles', _p('vim', 'bundle'), force) + _install_vim_bundle(cfg, 'vimbundles:local', _p('vim', 'local'), force) @run_priority(2) # Needs to run before `fish`. @@ -368,6 +383,7 @@ clone_git(url[len('[git]'):], full_path, force=force) else: clone_hg(url, full_path, force=force) + print() @only_on_mac @@ -447,7 +463,9 @@ print('') cfg = configparser.ConfigParser() - cfg.read(_p('install.cfg')) + cfg.read([ + _p('install.cfg'), + _p('local', 'local_install.cfg')]) # Get all the methods in this module that are named `install_xxx`. mod_names = ['all'] @@ -461,8 +479,7 @@ # See if we have any local install script. local_mod = None - local_install_py = os.path.join(dotfiles_dir, 'local', - 'local_install.py') + local_install_py = _p('local', 'local_install.py') if os.path.isfile(local_install_py): import importlib.util spec = importlib.util.spec_from_file_location('local_install', @@ -526,16 +543,25 @@ try: func(*f_args, **f_kwargs) except Exception as ex: - failed_installs.append(name) + failed_installs.append((name, sys.exc_info())) print("ERROR: %s" % ex) + traceback.print_exc() if isinstance(ex, FatalInstallerError): print("Aborting all remaining installs because '%s' failed!" % name) break else: print("Skipping install of '%s'." % name) + + print() + if failed_installs: - for name in failed_installs: + print() + print("----------------------------------") + print("ERROR: There were failed installs!") + for name, ex_info in failed_installs: print("ERROR: failed to install '%s'." % name) + print("ERROR: %s" % ex_info[1]) + traceback.print_exception(*ex_info) def _get_install_func_priority(func_info):