예제 #1
0
파일: init_cmd.py 프로젝트: tabulon-ext/dfm
def run(args):
    """Create a new Profile with the given name."""
    new_profile_dir = os.path.join(dfm_dir(), "profiles", args["<name>"])

    try:
        os.makedirs(new_profile_dir)
    except OSError as exc:
        print("Failed to create profile directory!")
        print("Error:", exc)
        sys.exit(1)

    Profile.new(new_profile_dir)
예제 #2
0
def test_config_loading(dotdfm):
    """Test that a profile properly loads the config file."""
    _, directory = dotdfm("""
pull_only: true
""", )
    profile = Profile.load(directory)
    assert profile.pull_only
예제 #3
0
def test_xdg_config(dotfile_dir):
    _, d_dir = dotfile_dir([".config/nvim/init.vim"])
    profile = Profile.load(str(d_dir))
    links = list(profile.link_manager.generate_links())
    assert links == [
        {
            "src": os.path.join(d_dir, ".config", "nvim", "init.vim"),
            "dst": os.path.join(xdg_dir(), "nvim", "init.vim"),
        },
    ]
예제 #4
0
def test_module_loading(dotdfm):
    """Test that a profile properly loads the config file modules."""
    _, directory = dotdfm(
        """
modules:
  - repo: https://github.com/robbyrussell/oh-my-zsh
    link: none
    location: ~/.oh-my-zsh
""", )
    profile = Profile.load(directory)
    assert profile.modules
예제 #5
0
def test_mapping_loading(dotdfm):
    """Test that a profile properly loads the config file mappings."""
    _, directory = dotdfm(
        """
mappings:
    - match: emacs
      skip: true
    - match: vimrc
      dest: .config/nvim/init.vim
""", )
    profile = Profile.load(directory)
    assert len(profile.link_manager.mappings) == 8
예제 #6
0
파일: utils.py 프로젝트: tabulon-ext/dfm
def load_profile(name=None):
    """
    Load a profile by name.

    Joins the dfm state directory with 'profiles' and name to
    determine where the profile is.
    """
    if name is not None:
        path = profile_dir(name)
    else:
        path = current_profile()

    return Profile.load(path)
예제 #7
0
def test_linking(dotdfm):
    """Test that the profile properly creates the links."""
    _, directory = dotdfm()
    with TemporaryDirectory() as target:
        profile = Profile.load(str(directory), extras={"target_dir": target})
        links = profile.link_manager.generate_links()
        profile.link()
        # Use a set comprehension since the target would not contain duplicates
        # since they would be overwritten with the last occuring link.
        dest = sorted(list({os.path.basename(x["dst"]) for x in links}))
        created = []
        for root, dirs, files in os.walk(target):
            dirs[:] = [d for d in dirs if d != ".git"]
            created += [
                f for f in files if os.path.islink(os.path.join(root, f))
            ]

        created = sorted(created)
        assert dest == created
예제 #8
0
파일: sync_cmd.py 프로젝트: tabulon-ext/dfm
def run(args):
    """Run profile.sync for the current profile."""
    if args["--name"]:
        possible_dir = profile_dir(args["--name"])
        if not exists(possible_dir):
            curprofile = load_profile()
            profile = find_module(args["--name"], curprofile)
            if profile is None:
                print("no module or profile matched name: {}".format(
                    args["--name"]))
                exit(1)
        else:
            profile = Profile.load(possible_dir)
    else:
        profile = load_profile()

    profile.sync(
        dry_run=args["--dry-run"],
        commit_msg=args["--message"],
    )
예제 #9
0
파일: utils.py 프로젝트: tabulon-ext/dfm
 def wrapper(*args, **kwargs):
     kwargs["profile"] = Profile.load(current_profile())
     return wrapped(*args, **kwargs)
예제 #10
0
def test_translation(dotdfm):
    """Test that the generated links properly translate names."""
    _, directory = dotdfm(
        """
---
mappings:
    - match: .skip_on_os
      target_os:
         - {this_os}
      skip: true
    - match: .map_to_os_name
      dest: .{this_os}
      target_os: {this_os}
    - match: .skip_on_another_os
      skip: True
      target_os: {another_os}
""".format(
            this_os=platform.system(),
            another_os="Windows"
            if platform.system() != "Windows" else "Linux",
        ),
        dotfiles=[
            ".vimrc",
            ".bashrc",
            ".emacs",
            ".gitignore",
            ".ggitignore",
            ".emacs.d/init.el",
            ".skip_on_os",
            ".map_to_os_name",
            ".skip_on_another_os",
        ],
    )
    profile = Profile.load(str(directory))
    links = profile.link_manager.generate_links()
    expected_links = [
        {
            "src": os.path.join(directory, ".vimrc"),
            "dst": os.path.join(os.getenv("HOME"), ".vimrc"),
        },
        {
            "src": os.path.join(directory, ".bashrc"),
            "dst": os.path.join(os.getenv("HOME"), ".bashrc"),
        },
        {
            "src": os.path.join(directory, ".emacs"),
            "dst": os.path.join(os.getenv("HOME"), ".emacs"),
        },
        {
            "src": os.path.join(directory, ".ggitignore"),
            "dst": os.path.join(os.getenv("HOME"), ".gitignore"),
        },
        {
            "src": os.path.join(directory, ".emacs.d", "init.el"),
            "dst": os.path.join(os.getenv("HOME"), ".emacs.d", "init.el"),
        },
        {
            "src":
            os.path.join(directory, ".map_to_os_name"),
            "dst":
            os.path.join(os.getenv("HOME"),
                         ".{name}".format(name=platform.system())),
        },
        {
            "src": os.path.join(directory, ".skip_on_another_os"),
            "dst": os.path.join(os.getenv("HOME"), ".skip_on_another_os"),
        },
    ]

    sorted_links = sorted(links, key=itemgetter("src"))
    sorted_expected_links = sorted(expected_links, key=itemgetter("src"))
    assert len(sorted_links) == len(sorted_expected_links)

    for (link, expected) in zip(sorted_links, sorted_expected_links):
        assert link["src"] == expected["src"]
        assert link["dst"] == expected["dst"]