update the dotfile(s) from path(s) or key(s)
(opts)
| 472 | |
| 473 | |
| 474 | def cmd_update(opts): |
| 475 | """update the dotfile(s) from path(s) or key(s)""" |
| 476 | cnt = 0 |
| 477 | paths = opts.update_path |
| 478 | iskey = opts.update_iskey |
| 479 | |
| 480 | if opts.profile not in [p.key for p in opts.profiles]: |
| 481 | LOG.err(f'no such profile \"{opts.profile}\"') |
| 482 | return False |
| 483 | |
| 484 | adapt_workers(opts, LOG) |
| 485 | |
| 486 | if not paths: |
| 487 | # update the entire profile |
| 488 | if iskey: |
| 489 | LOG.dbg(f'update by keys: {paths}') |
| 490 | paths = [d.key for d in opts.dotfiles] |
| 491 | else: |
| 492 | LOG.dbg(f'update by paths: {paths}') |
| 493 | paths = [d.dst for d in opts.dotfiles] |
| 494 | msg = f'Update all dotfiles for profile \"{opts.profile}\"' |
| 495 | if opts.safe and not LOG.ask(msg): |
| 496 | LOG.log(f'\n{cnt} file(s) updated.') |
| 497 | return False |
| 498 | |
| 499 | # check there's something to do |
| 500 | if not paths: |
| 501 | LOG.log('\nno dotfile to update') |
| 502 | return True |
| 503 | |
| 504 | LOG.dbg(f'dotfile to update: {paths}') |
| 505 | |
| 506 | # update each dotfile |
| 507 | if opts.workers > 1: |
| 508 | # in parallel |
| 509 | LOG.dbg(f'run with {opts.workers} workers') |
| 510 | ex = futures.ThreadPoolExecutor(max_workers=opts.workers) |
| 511 | wait_for = [] |
| 512 | for path in paths: |
| 513 | j = ex.submit(_dotfile_update, opts, path, key=iskey) |
| 514 | wait_for.append(j) |
| 515 | # check result |
| 516 | for fut in futures.as_completed(wait_for): |
| 517 | if fut.result(): |
| 518 | cnt += 1 |
| 519 | else: |
| 520 | # sequentially |
| 521 | for path in paths: |
| 522 | if _dotfile_update(opts, path, key=iskey): |
| 523 | cnt += 1 |
| 524 | |
| 525 | LOG.log(f'\n{cnt} file(s) updated.') |
| 526 | return cnt == len(paths) |
| 527 | |
| 528 | |
| 529 | def cmd_importer(opts): |