~pvsr/qpm

eabbebd3f52e207c4bee9869ee5578352d25f649 — Peter Rice 4 days ago 455cb0f
allow passing session path
3 files changed, 15 insertions(+), 11 deletions(-)

M qpm/main.py
M qpm/operations.py
M tests/test_main.py
M qpm/main.py => qpm/main.py +3 -1
@@ 33,7 33,9 @@ def main(mock_args=None) -> None:
        "from-session", help="create a new profile from a qutebrowser session"
    )
    session.add_argument(
        "session", help="session to create a new profile from",
        "session",
        help="path to session file or name of session. "
        "e.g. ~/.local/share/qutebrowser/sessions/example.yml or example",
    )
    session.add_argument(
        "profile_name",

M qpm/operations.py => qpm/operations.py +10 -5
@@ 12,13 12,18 @@ from qpm.utils import error


def from_session(
    session_name: str,
    session: str,
    profile_name: Optional[str] = None,
    profile_dir: Optional[Path] = None,
) -> Optional[Profile]:
    session = profiles.main_data_dir / "sessions" / (session_name + ".yml")
    if not session.is_file():
        error(f"{session} is not a file")
    if session.endswith(".yml"):
        session_file = Path(session).expanduser()
        session_name = session_file.stem
    else:
        session_name = session
        session_file = profiles.main_data_dir / "sessions" / (session_name + ".yml")
    if not session_file.is_file():
        error(f"{session_file} is not a file")
        return None

    profile = Profile(profile_name or session_name, profile_dir)


@@ 27,7 32,7 @@ def from_session(

    session_dir = profile.root / "data" / "sessions"
    session_dir.mkdir(parents=True)
    shutil.copy(session, session_dir / "_autosave.yml")
    shutil.copy(session_file, session_dir / "_autosave.yml")

    return profile


M tests/test_main.py => tests/test_main.py +2 -5
@@ 1,8 1,6 @@
from os import environ
from pathlib import Path

import pytest  # type: ignore

from qpm.main import main




@@ 17,10 15,9 @@ def test_profile_dir_env(tmp_path: Path):
    assert list(tmp_path.iterdir()) == [tmp_path / "test"]


@pytest.mark.skip(reason="need to allow path of session")
def test_from_session(tmp_path: Path):
    environ["QPM_PROFILE_DIR"] = str(tmp_path)
    session = tmp_path / "test.yml"
    # TODO file contents
    session.touch()
    main(["from-session", str(session)])
    assert list(tmp_path.iterdir()) == [tmp_path / "test"]
    assert set(tmp_path.iterdir()) == {session, tmp_path / "test"}