From ba86502a2712169f7c4d82737ef700bcd6f15cde Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 29 Oct 2021 18:10:45 +1000 Subject: [PATCH] tweaks for Windows package - move audio tools into subfolder - add buildmanifest.py --- qt/aqt/sound.py | 18 ++++++++---------- qt/package/buildmanifest.py | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 qt/package/buildmanifest.py diff --git a/qt/aqt/sound.py b/qt/aqt/sound.py index 213d24c9f..351deeab9 100644 --- a/qt/aqt/sound.py +++ b/qt/aqt/sound.py @@ -234,16 +234,14 @@ def _packagedCmd(cmd: list[str]) -> tuple[Any, dict[str, str]]: env = os.environ.copy() if "LD_LIBRARY_PATH" in env: del env["LD_LIBRARY_PATH"] - if isMac: - path = Path(sys.prefix).joinpath("audio").joinpath(cmd[0]) - if path.exists(): - cmd[0] = str(path) - return cmd, env - adjusted_path = os.path.join(sys.prefix, cmd[0]) - if isWin and not adjusted_path.endswith(".exe"): - adjusted_path += ".exe" - if os.path.exists(adjusted_path): - cmd[0] = adjusted_path + + packaged_path = ( + Path(sys.prefix).joinpath("audio").joinpath(cmd[0] + ".exe" if isWin else "") + ) + if packaged_path.exists(): + cmd[0] = str(packaged_path) + return cmd, env + return cmd, env diff --git a/qt/package/buildmanifest.py b/qt/package/buildmanifest.py new file mode 100644 index 000000000..3057879c9 --- /dev/null +++ b/qt/package/buildmanifest.py @@ -0,0 +1,26 @@ +# Copyright: Ankitects Pty Ltd and contributors +# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + +import os +import sys +from pathlib import Path + + +def build_manifest(top: Path) -> None: + manifest = [] + for root, dirnames, fnames in os.walk(top, topdown=True): + relroot = root[len(str(top)) + 1 :] + # if not top level, add folder + if relroot: + manifest.append(relroot) + # then the files + for fname in fnames: + path = os.path.join(relroot, fname) + manifest.append(path) + + with open(top / "anki.install-manifest", "w") as file: + file.write("\n".join(manifest) + "\n") + + +if __name__ == "__main__": + build_manifest(Path(sys.argv[1]))