Remove dependency on platform_utils and use a minified version of its paths module instead
This commit is contained in:
parent
2e0b8d0f75
commit
64f3acdbb6
@ -1,3 +1,2 @@
|
||||
pypubsub
|
||||
requests
|
||||
git+https://github.com/accessibleapps/platform_utils
|
||||
requests
|
@ -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):
|
||||
|
60
updater/paths.py
Normal file
60
updater/paths.py
Normal file
@ -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
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user