pakjoy: Use more constants

This commit is contained in:
Florian Bruhin 2023-11-22 15:25:19 +01:00
parent 50db87664d
commit 51dace7152
2 changed files with 13 additions and 10 deletions

View File

@ -37,6 +37,9 @@ from qutebrowser.utils import qtutils, standarddir, version, utils, log
HANGOUTS_MARKER = b"// Extension ID: nkeimhogjdpnpccoofpliimaahmaaome"
HANGOUTS_ID = 36197 # as found by toofar
PAK_VERSION = 5
RESOURCES_ENV_VAR = "QTWEBENGINE_RESOURCES_PATH"
CACHE_DIR_NAME = "webengine_resources_pak_quirk"
PAK_FILENAME = "qtwebengine_resources.pak"
TARGET_URL = b"https://*.google.com/*"
REPLACEMENT_URL = b"https://qute.invalid/*"
@ -154,7 +157,7 @@ def copy_webengine_resources() -> Optional[pathlib.Path]:
resources_dir /= pathlib.Path("lib", "QtWebEngineCore.framework", "Resources")
else:
resources_dir /= "resources"
work_dir = pathlib.Path(standarddir.cache()) / "webengine_resources_pak_quirk"
work_dir = pathlib.Path(standarddir.cache()) / CACHE_DIR_NAME
if work_dir.exists():
log.misc.debug(f"Removing existing {work_dir}")
@ -172,7 +175,7 @@ def copy_webengine_resources() -> Optional[pathlib.Path]:
shutil.copytree(resources_dir, work_dir)
os.environ["QTWEBENGINE_RESOURCES_PATH"] = str(work_dir)
os.environ[RESOURCES_ENV_VAR] = str(work_dir)
return work_dir
@ -210,4 +213,4 @@ def patch_webengine() -> None:
if webengine_resources_path is None:
return
_patch(webengine_resources_path / "qtwebengine_resources.pak")
_patch(webengine_resources_path / PAK_FILENAME)

View File

@ -36,8 +36,8 @@ def skipifneeded():
@pytest.fixture(autouse=True)
def clean_env():
yield
if "QTWEBENGINE_RESOURCES_PATH" in os.environ:
del os.environ["QTWEBENGINE_RESOURCES_PATH"]
if pakjoy.RESOURCES_ENV_VAR in os.environ:
del os.environ[pakjoy.RESOURCES_ENV_VAR]
def patch_version(monkeypatch, *args):
@ -64,7 +64,7 @@ def affected_version(monkeypatch):
@pytest.mark.parametrize("workdir_exists", [True, False])
def test_version_gate(cache_tmpdir, unaffected_version, mocker, workdir_exists):
workdir = cache_tmpdir / "webengine_resources_pak_quirk"
workdir = cache_tmpdir / pakjoy.CACHE_DIR_NAME
if workdir_exists:
workdir.mkdir()
(workdir / "some_patched_file.pak").ensure()
@ -104,9 +104,9 @@ class TestWithRealResourcesFile:
# afterwards.
pakjoy.patch_webengine()
patched_resources = pathlib.Path(os.environ["QTWEBENGINE_RESOURCES_PATH"])
patched_resources = pathlib.Path(os.environ[pakjoy.RESOURCES_ENV_VAR])
with open(patched_resources / "qtwebengine_resources.pak", "rb") as fd:
with open(patched_resources / pakjoy.PAK_FILENAME, "rb") as fd:
reparsed = pakjoy.PakParser(fd)
json_manifest = json_without_comments(reparsed.manifest)
@ -120,8 +120,8 @@ class TestWithRealResourcesFile:
work_dir = pakjoy.copy_webengine_resources()
assert work_dir.exists()
assert work_dir == standarddir.cache() / "webengine_resources_pak_quirk"
assert (work_dir / "qtwebengine_resources.pak").exists()
assert work_dir == standarddir.cache() / pakjoy.CACHE_DIR_NAME
assert (work_dir / pakjoy.PAK_FILENAME).exists()
assert len(list(work_dir.glob("*"))) > 1
def test_copying_resources_overwrites(self):