install dotfiles for this profile
(opts)
| 290 | |
| 291 | |
| 292 | def cmd_install(opts): |
| 293 | """install dotfiles for this profile""" |
| 294 | dotfiles = opts.dotfiles |
| 295 | prof = opts.conf.get_profile() |
| 296 | |
| 297 | adapt_workers(opts, LOG) |
| 298 | |
| 299 | pro_pre_actions = prof.get_pre_actions() if prof else [] |
| 300 | pro_post_actions = prof.get_post_actions() if prof else [] |
| 301 | |
| 302 | if opts.install_keys: |
| 303 | # filtered dotfiles to install |
| 304 | uniq = uniq_list(opts.install_keys) |
| 305 | dotfiles = [d for d in dotfiles if d.key in uniq] |
| 306 | |
| 307 | if not dotfiles: |
| 308 | msg = f'no dotfile to install for this profile (\"{opts.profile}\")' |
| 309 | LOG.warn(msg) |
| 310 | return False |
| 311 | |
| 312 | lfs = [k.key for k in dotfiles] |
| 313 | LOG.dbg(f'dotfiles registered for install: {lfs}') |
| 314 | |
| 315 | # the installer |
| 316 | tmpdir = None |
| 317 | if opts.install_temporary: |
| 318 | tmpdir = get_tmpdir() |
| 319 | |
| 320 | installed = [] |
| 321 | |
| 322 | # clear the workdir |
| 323 | if opts.install_clear_workdir and not opts.dry: |
| 324 | LOG.dbg(f'clearing the workdir under {opts.workdir}') |
| 325 | for root, _, files in os.walk(opts.workdir): |
| 326 | for file in files: |
| 327 | fpath = os.path.join(root, file) |
| 328 | # ignore error |
| 329 | removepath(fpath, logger=LOG) |
| 330 | |
| 331 | # execute profile pre-action |
| 332 | LOG.dbg(f'run {len(pro_pre_actions)} profile pre actions') |
| 333 | templ = _get_templater(opts) |
| 334 | ret, _ = action_executor(opts, pro_pre_actions, [], templ, post=False)() |
| 335 | if not ret: |
| 336 | return False |
| 337 | |
| 338 | # install each dotfile |
| 339 | if opts.workers > 1: |
| 340 | # in parallel |
| 341 | LOG.dbg(f'run with {opts.workers} workers') |
| 342 | ex = futures.ThreadPoolExecutor(max_workers=opts.workers) |
| 343 | |
| 344 | wait_for = [] |
| 345 | for dotfile in dotfiles: |
| 346 | j = ex.submit(_dotfile_install, opts, dotfile, tmpdir=tmpdir) |
| 347 | wait_for.append(j) |
| 348 | # check result |
| 349 | for fut in futures.as_completed(wait_for): |