remove dotfile from dotpath and from config
(opts)
| 667 | |
| 668 | |
| 669 | def cmd_remove(opts): |
| 670 | """remove dotfile from dotpath and from config""" |
| 671 | paths = opts.remove_path |
| 672 | iskey = opts.remove_iskey |
| 673 | |
| 674 | if not paths: |
| 675 | LOG.log('no dotfile to remove') |
| 676 | return False |
| 677 | pathss = ','.join(paths) |
| 678 | LOG.dbg(f'dotfile(s) to remove: {pathss}') |
| 679 | |
| 680 | removed = [] |
| 681 | for key in paths: |
| 682 | if not iskey: |
| 683 | # by path |
| 684 | dotfiles = opts.conf.get_dotfile_by_dst(key) |
| 685 | if not dotfiles: |
| 686 | LOG.warn(f'{key} ignored, does not exist') |
| 687 | continue |
| 688 | else: |
| 689 | # by key |
| 690 | dotfile = opts.conf.get_dotfile(key) |
| 691 | if not dotfile: |
| 692 | LOG.warn(f'{key} ignored, does not exist') |
| 693 | continue |
| 694 | dotfiles = [dotfile] |
| 695 | |
| 696 | for dotfile in dotfiles: |
| 697 | k = dotfile.key |
| 698 | # ignore if uses any type of link |
| 699 | if dotfile.link != LinkTypes.NOLINK: |
| 700 | msg = f'{k} uses symlink, remove manually' |
| 701 | LOG.warn(msg) |
| 702 | continue |
| 703 | |
| 704 | LOG.dbg(f'removing {key}') |
| 705 | |
| 706 | # make sure is part of the profile |
| 707 | if dotfile.key not in [d.key for d in opts.dotfiles]: |
| 708 | msg = f'{key} ignored, not associated to this profile' |
| 709 | LOG.warn(msg) |
| 710 | continue |
| 711 | profiles = opts.conf.get_profiles_by_dotfile_key(k) |
| 712 | pkeys = ','.join([p.key for p in profiles]) |
| 713 | if opts.dry: |
| 714 | LOG.dry(f'would remove {dotfile} from {pkeys}') |
| 715 | continue |
| 716 | msg = f'Remove \"{k}\" from all these profiles: {pkeys}' |
| 717 | if opts.safe and not LOG.ask(msg): |
| 718 | return False |
| 719 | LOG.dbg(f'remove dotfile: {dotfile}') |
| 720 | |
| 721 | for profile in profiles: |
| 722 | if not opts.conf.del_dotfile_from_profile(dotfile, profile): |
| 723 | return False |
| 724 | if not opts.conf.del_dotfile(dotfile): |
| 725 | return False |
| 726 |