1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-13 15:57:14 +03:00

Move the 'duplicate' constants into a new constants.py

1. So now they're only defined in one place.
2. config.py does an import of them, and `from config import ...` then
   chains through, so no need to update other users.
3. No need to ' # noqa E402' the killswitch/config imports now.
This commit is contained in:
Athanasius 2021-01-13 15:23:11 +00:00
parent 778668f680
commit c3663d8be8
4 changed files with 30 additions and 7 deletions

View File

@ -15,9 +15,11 @@ from sys import platform
from time import localtime, strftime, time
from typing import TYPE_CHECKING
from config import applongname, appname, appversion, appversion_nobuild, config, copyright
from constants import applongname, appname, protocolhandler_redirect
if __name__ == "__main__":
# config will now cause an appname logger to be set up, so we need the
# console redirect before this
if __name__ == '__main__':
def no_other_instance_running() -> bool: # noqa: CCR001
"""
Ensure only one copy of the app is running under this user account.
@ -70,7 +72,7 @@ if __name__ == "__main__":
and window_title(window_handle) == applongname \
and GetProcessHandleFromHwnd(window_handle):
# If GetProcessHandleFromHwnd succeeds then the app is already running as this user
if len(sys.argv) > 1 and sys.argv[1].startswith(protocolhandler.redirect):
if len(sys.argv) > 1 and sys.argv[1].startswith(protocolhandler_redirect):
CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)
# Wait for it to be responsive to avoid ShellExecute recursing
ShowWindow(window_handle, SW_RESTORE)
@ -140,6 +142,11 @@ if __name__ == "__main__":
# unbuffered not allowed for text in python3, so use `1 for line buffering
sys.stdout = sys.stderr = open(join(tempfile.gettempdir(), f'{appname}.log'), mode='wt', buffering=1)
# TODO: Test: Make *sure* this redirect is working, else py2exe is going to cause an exit popup
# isort: off
from config import appversion, appversion_nobuild, config, copyright
# isort: on
from EDMCLogging import edmclogger, logger, logging

View File

@ -6,9 +6,9 @@ from os.path import expanduser, dirname, exists, isdir, join, normpath
from sys import platform
import semantic_version
from constants import applongname, appname
# Any of these may be imported by plugins
appname = 'EDMarketConnector'
applongname = 'E:D Market Connector'
appcmdname = 'EDMC'
# appversion **MUST** follow Semantic Versioning rules:
# <https://semver.org/#semantic-versioning-specification-semver>

14
constants.py Normal file
View File

@ -0,0 +1,14 @@
"""
All constants for the application.
This file should contain all constants that the application uses, but that
means migrating the existing ones, so for now it's only the ones that we've
found necessary to move out of other files.
"""
# config.py
appname = 'EDMarketConnector'
applongname = 'E:D Market Connector'
# protocol.py
protocolhandler_redirect = 'edmc://auth'

View File

@ -5,7 +5,9 @@ import threading
import urllib.request, urllib.error, urllib.parse
import sys
from config import appname, config
from EDMCLogging import get_main_logger
from config import config
from constants import protocolhandler_redirect
if sys.platform == 'win32':
@ -20,7 +22,7 @@ if sys.platform == 'win32':
class GenericProtocolHandler(object):
def __init__(self):
self.redirect = 'edmc://auth' # Base redirection URL
self.redirect = protocolhandler_redirect # Base redirection URL
self.master = None
self.lastpayload = None