diff --git a/requirements.txt b/requirements.txt index 35ac707..082b7f3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ pypubsub -requests -git+https://github.com/accessibleapps/platform_utils \ No newline at end of file +requests \ No newline at end of file diff --git a/updater/core.py b/updater/core.py index db7a464..2c00253 100644 --- a/updater/core.py +++ b/updater/core.py @@ -11,9 +11,8 @@ import zipfile import logging import requests from pubsub import pub # type: ignore -from platform_utils import paths # type: ignore from typing import Optional, Dict, Tuple, Union, Any - +from . import paths log = logging.getLogger("updater.core") class UpdaterCore(object): diff --git a/updater/paths.py b/updater/paths.py new file mode 100644 index 0000000..e34b4cc --- /dev/null +++ b/updater/paths.py @@ -0,0 +1,60 @@ +""" Provide some system paths for multiple platforms. + +This module has been taken and modified from https://github.com/accessibleapps/platform_utils and has been used to provide some convenient methods to retrieve system paths. +""" +import platform +import os +import sys + +plat: str = platform.system() +is_windows: bool = plat == "Windows" +is_mac: bool = plat == "Darwin" +is_linux: bool = plat == "Linux" + +# ToDo: Return correct values for nuitka build executables, as they do not use sys.frozen. +def is_frozen() -> bool: + """ Checks wheter the updater package is inside a frozen application. + + :rtype: bool +""" + return hasattr(sys, "frozen") + +def get_executable() -> str: + """Returns the full executable path/name if frozen, or the full path/name of the main module if not. + + :rtype: str + """ + if is_frozen(): + if not is_mac: + return sys.executable + # On Mac, sys.executable points to python. We want the full path to the exe we ran. + exedir = os.path.abspath(os.path.dirname(sys.executable)) + items = os.listdir(exedir) + if "python" in items: + items.remove("python") + return os.path.join(exedir, items[0]) + # Not frozen + try: + import __main__ + return os.path.abspath(__main__.__file__) + except AttributeError: + return sys.argv[0] + +def executable_directory() -> str: + """Always determine the directory of the executable, even when run with py2exe or otherwise frozen. + + :rtype: str + """ + executable = get_executable() + path = os.path.abspath(os.path.dirname(executable)) + return path + +def app_path() -> str: + """ Returns application directory. + + :rtype: str + """ + path = executable_directory() + if is_frozen() and is_mac: + path = os.path.abspath(os.path.join(path, "..", "..")) + return path \ No newline at end of file diff --git a/updater/wxupdater.py b/updater/wxupdater.py index c179f66..a7f4378 100644 --- a/updater/wxupdater.py +++ b/updater/wxupdater.py @@ -38,8 +38,7 @@ import logging from typing import Optional, Any, cast from pubsub import pub # type: ignore from pubsub.core.topicexc import TopicNameError # type: ignore -from platform_utils import paths # type: ignore -from . import core, utils +from . import core, utils, paths log = logging.getLogger("updater.WXUpdater") @@ -167,7 +166,7 @@ class WXUpdater(core.UpdaterCore): update_path = os.path.join(base_path, 'update') extraction_path = self.extract_update(downloaded, destination=update_path) bootstrap_exe = self.move_bootstrap(extraction_path) - source_path = os.path.join(paths.app_path(), "sandbox") + source_path = paths.app_path() self.on_update_almost_complete() self.execute_bootstrap(bootstrap_exe, source_path)