コード例 #1
0
def install(names: str) -> None:
    with context() as ctx:
        for name in names:
            try:
                ctx.mods[name].install()
                ctx.installed.add(name)
            except KeyError:
                print(f'"{name}" is not a valid mod.')
コード例 #2
0
def uninstall(names: str) -> None:
    with context() as ctx:
        for name in names:
            if name in ctx.installed:
                try:
                    ctx.mods[name].uninstall()
                    ctx.installed.remove(name)
                except KeyError:
                    print(f'"{name}" is not a valid mod.')
            else:
                print(f'"{name}" is not installed.')
コード例 #3
0
def listmods(which: str, name: str = "") -> None:
    with context() as ctx:
        if which == "all":
            mods = ctx.mods.keys()
        elif which == "installed":
            mods = ctx.installed
        else:
            return
        if name:
            mods = [mod for mod in mods if name in mod]
        print(mods)
コード例 #4
0
def test_exit(tmp_path_factory, testmods):
    root = tmp_path_factory.mktemp("ctx_exit")
    installed = set(["Test Mod 1"])

    with context(root=root, mods_dir="mods", install_dir="install") as ctx:
        ctx.mods = testmods
        ctx.installed = installed

    with open(root / "mods.json") as f:
        data = json.load(f, object_hook=decode_mod)
        assert data["mods"] == testmods
        assert set(data["installed"]) == installed
コード例 #5
0
def test_enter(tmp_path_factory, testmods):
    root = tmp_path_factory.mktemp("ctx_enter")

    with open(root / "mods.json", "w") as f:
        json.dump({
            "mods": testmods,
            "installed": ["Test Mod 2"]
        },
                  f,
                  cls=ModEncoder)

    with context(root=root, mods_dir="mods", install_dir="install") as ctx:
        assert ctx.mods == testmods
        assert ctx.installed == set(["Test Mod 2"])
コード例 #6
0
ファイル: conftest.py プロジェクト: desophos/cox-mod-manager
def ctx(testmods, tmp_path_factory, mods_dir, install_dir) -> ModsContext:
    with context(root=tmp_path_factory.getbasetemp(),
                 mods_dir=mods_dir,
                 install_dir=install_dir) as ctx:
        return ctx