From 9e1ffc14c8240be9973c37202b8a18024f6e9eb3 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 21 Sep 2020 19:20:08 +0100 Subject: [PATCH 01/10] setup.py: Reference EDMC.manifest ready for its creation We'll want to do the same "use the UTF-8 codepage" thing here. --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index a3e3d397..4578b3cc 100755 --- a/setup.py +++ b/setup.py @@ -172,6 +172,7 @@ setup( 'version': BASEVERSION, 'product_version': VERSION, 'copyright': COPYRIGHT, + 'other_resources': [(24, 1, open(APPCMDNAME+'.manifest').read())], } ], data_files = DATA_FILES, options = OPTIONS, From 0f3ebd6e23975a73d6c9a655c500685f08018083 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 22 Sep 2020 15:34:35 +0100 Subject: [PATCH 02/10] Add a manifest for EDMC.exe so that it also runs UTF-8 --- EDMC.manifest | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 EDMC.manifest diff --git a/EDMC.manifest b/EDMC.manifest new file mode 100644 index 00000000..9b412178 --- /dev/null +++ b/EDMC.manifest @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + UTF-8 + + + + + + + + + + From c0b01f88acd886889628deec543a46578817eb0c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 22 Sep 2020 15:35:42 +0100 Subject: [PATCH 03/10] Add get_main_logger() method to EDMCLogging.py This is so the decision on appname versus appcmdname is in one place. --- EDMCLogging.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/EDMCLogging.py b/EDMCLogging.py index 62aab91a..514a38f0 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -10,13 +10,14 @@ strings. import inspect import logging import logging.handlers +import os import pathlib import tempfile # So that any warning about accessing a protected member is only in one place. from sys import _getframe as getframe from typing import Tuple -from config import appname, config +from config import appcmdname, appname, config # TODO: Tests: # @@ -327,6 +328,17 @@ class EDMCContextFilter(logging.Filter): return module_name +def get_main_logger() -> logging.Logger: + """Return the correct logger for how the program is being run.""" + + if not os.getenv("EDMC_NO_UI"): + # GUI app being run + return logging.getLogger(appname) + else: + # Must be the CLI + return logging.getLogger(appcmdname) + + # Singleton loglevel = config.get('loglevel') if not loglevel: From edc6ed6596182815e89956e5d8e52bd8baf2908a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 22 Sep 2020 15:37:45 +0100 Subject: [PATCH 04/10] Add locale DEBUG logging to EDMC.py --- EDMC.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/EDMC.py b/EDMC.py index 8ef2e78c..2d2ec3b9 100755 --- a/EDMC.py +++ b/EDMC.py @@ -6,6 +6,7 @@ import argparse import json +import locale import logging import os import re @@ -14,6 +15,9 @@ from os.path import getmtime, join from time import sleep, time from typing import Any, Optional +# workaround for https://github.com/EDCD/EDMarketConnector/issues/568 +os.environ["EDMC_NO_UI"] = "1" + import collate import commodity import companion @@ -36,14 +40,31 @@ sys.path.append(config.internal_plugin_dir) import eddn # noqa: E402 # isort: on -# workaround for https://github.com/EDCD/EDMarketConnector/issues/568 -os.environ["EDMC_NO_UI"] = "1" - -l10n.Translations.install_dummy() - logger = EDMCLogging.Logger(appcmdname).get_logger() logger.setLevel(logging.INFO) +logger.debug(f'Startup v{appversion} : Running on Python v{sys.version}') +logger.debug(f'''Platform: {sys.platform} +argv[0]: {sys.argv[0]} +exec_prefix: {sys.exec_prefix} +executable: {sys.executable} +sys.path: {sys.path}''' + ) + + +def log_locale(prefix: str) -> None: + logger.debug(f'''Locale: {prefix} +Locale LC_COLLATE: {locale.getlocale(locale.LC_COLLATE)} +Locale LC_CTYPE: {locale.getlocale(locale.LC_CTYPE)} +Locale LC_MONETARY: {locale.getlocale(locale.LC_MONETARY)} +Locale LC_NUMERIC: {locale.getlocale(locale.LC_NUMERIC)} +Locale LC_TIME: {locale.getlocale(locale.LC_TIME)}''' + ) + + +log_locale('Initial Locale') + +l10n.Translations.install_dummy() SERVER_RETRY = 5 # retry pause for Companion servers [s] EXIT_SUCCESS, EXIT_SERVER, EXIT_CREDENTIALS, EXIT_VERIFICATION, EXIT_LAGGING, EXIT_SYS_ERR, EXIT_ARGS = range(7) From 22b3362c2076b96ddffffa539c5f3279365e0ac7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 22 Sep 2020 15:37:56 +0100 Subject: [PATCH 05/10] companion.py: Switch to using EDMCLogging.get_main_logger() So that we use the correct one for GUI versus CLI. --- companion.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/companion.py b/companion.py index 3be504f4..ee6369eb 100644 --- a/companion.py +++ b/companion.py @@ -9,7 +9,6 @@ protocol used for the callback. import base64 import csv import hashlib -import logging import numbers import os import random @@ -26,9 +25,10 @@ from typing import TYPE_CHECKING, Any, Dict, List, NewType, Union import requests from config import appname, appversion, config +from EDMCLogging import get_main_logger from protocol import protocolhandler -logger = logging.getLogger(appname) +logger = get_main_logger() if TYPE_CHECKING: _ = lambda x: x # noqa: E731 # to make flake8 stop complaining that the hacked in _ method doesnt exist From a883eb29b277ccf95f8257d7385bec15575ad657 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 22 Sep 2020 15:44:16 +0100 Subject: [PATCH 06/10] plug.py, prefs.py: Use get_main_logger() --- plug.py | 4 ++-- prefs.py | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/plug.py b/plug.py index 51d73531..a13d93b2 100644 --- a/plug.py +++ b/plug.py @@ -9,15 +9,15 @@ import sys import operator import threading # noqa: F401 - We don't use it, but plugins might from typing import Optional -import logging import tkinter as tk import myNotebook as nb # noqa: N813 from config import config, appname +from EDMCLogging import get_main_logger import logging -logger = logging.getLogger(appname) +logger = get_main_logger() # Dashboard Flags constants FlagsDocked = 1 << 0 # on a landing pad diff --git a/prefs.py b/prefs.py index cdc0ab3c..28a7553f 100644 --- a/prefs.py +++ b/prefs.py @@ -9,16 +9,15 @@ from tkinter import colorchooser as tkColorChooser from ttkHyperlinkLabel import HyperlinkLabel import myNotebook as nb -from config import appname, applongname, config, appversion +from config import applongname, config, appversion from hotkey import hotkeymgr from l10n import Translations from monitor import monitor from theme import theme import plug -import logging -logger = logging.getLogger(appname) -from EDMCLogging import edmclogger +from EDMCLogging import edmclogger, get_main_logger +logger = get_main_logger() ########################################################################### # Versioned preferences, so we know whether to set an 'on' default on From 3759f2f0f21c1115ba64d2aa77d98f47f45b3cd4 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 22 Sep 2020 15:48:09 +0100 Subject: [PATCH 07/10] Use appropriate base logger name for plugins. --- plug.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plug.py b/plug.py index a13d93b2..10e8957d 100644 --- a/plug.py +++ b/plug.py @@ -13,7 +13,7 @@ import tkinter as tk import myNotebook as nb # noqa: N813 -from config import config, appname +from config import appcmdname, appname, config from EDMCLogging import get_main_logger import logging @@ -203,7 +203,11 @@ def load_plugins(master): # Create a logger for this 'found' plugin. Must be before the # load.py is loaded. import EDMCLogging - plugin_logger = EDMCLogging.get_plugin_logger(f'{appname}.{name}') + if not os.getenv('EDMC_NO_UI'): + base_logger_name = appname + else: + base_logger_name = appcmdname + plugin_logger = EDMCLogging.get_plugin_logger(f'{base_logger_name}.{name}') found.append(Plugin(name, os.path.join(config.plugin_dir, name, 'load.py'), plugin_logger)) except Exception as e: From 14b8565aff84ba74c1510f650b553c90efb96c2d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 22 Sep 2020 15:50:06 +0100 Subject: [PATCH 08/10] Add 'import logging' (back in?) to prefs.py --- prefs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/prefs.py b/prefs.py index 28a7553f..fb87a639 100644 --- a/prefs.py +++ b/prefs.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import logging from os.path import dirname, expanduser, expandvars, exists, isdir, join, normpath from sys import platform import webbrowser From fa326ad3d373e99d7f4cac32a633d3826f7a18a1 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 22 Sep 2020 15:54:18 +0100 Subject: [PATCH 09/10] EDMC.py: Move DEBUG logging to after level is set. --- EDMC.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/EDMC.py b/EDMC.py index 2d2ec3b9..d1f9411d 100755 --- a/EDMC.py +++ b/EDMC.py @@ -43,14 +43,6 @@ import eddn # noqa: E402 logger = EDMCLogging.Logger(appcmdname).get_logger() logger.setLevel(logging.INFO) -logger.debug(f'Startup v{appversion} : Running on Python v{sys.version}') -logger.debug(f'''Platform: {sys.platform} -argv[0]: {sys.argv[0]} -exec_prefix: {sys.exec_prefix} -executable: {sys.executable} -sys.path: {sys.path}''' - ) - def log_locale(prefix: str) -> None: logger.debug(f'''Locale: {prefix} @@ -62,8 +54,6 @@ Locale LC_TIME: {locale.getlocale(locale.LC_TIME)}''' ) -log_locale('Initial Locale') - l10n.Translations.install_dummy() SERVER_RETRY = 5 # retry pause for Companion servers [s] @@ -133,7 +123,15 @@ def main(): sys.exit(EXIT_ARGS) logger.setLevel(args.loglevel) - logger.debug('Startup') + logger.debug(f'Startup v{appversion} : Running on Python v{sys.version}') + logger.debug(f'''Platform: {sys.platform} +argv[0]: {sys.argv[0]} +exec_prefix: {sys.exec_prefix} +executable: {sys.executable} +sys.path: {sys.path}''' + ) + + log_locale('Initial Locale') if args.j: logger.debug('Import and collate from JSON dump') From 7750bbdf4a4f83e371ab477e983de313acf04464 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 22 Sep 2020 16:09:39 +0100 Subject: [PATCH 10/10] Move GUI/CLI conditional into get_plugin_logger() It's cleaner here than in the calling plug.py code. --- EDMCLogging.py | 9 +++++++-- plug.py | 6 +----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/EDMCLogging.py b/EDMCLogging.py index 514a38f0..f882f924 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -123,7 +123,7 @@ class Logger: return self.logger_channel -def get_plugin_logger(name: str, loglevel: int = _default_loglevel) -> logging.Logger: +def get_plugin_logger(plugin_name: str, loglevel: int = _default_loglevel) -> logging.Logger: """ Return a logger suitable for a plugin. @@ -144,7 +144,12 @@ def get_plugin_logger(name: str, loglevel: int = _default_loglevel) -> logging.L :param loglevel: Optional logLevel for this Logger. :return: logging.Logger instance, all set up. """ - plugin_logger = logging.getLogger(name) + if not os.getenv('EDMC_NO_UI'): + base_logger_name = appname + else: + base_logger_name = appcmdname + + plugin_logger = logging.getLogger(f'{base_logger_name}.{plugin_name}') plugin_logger.setLevel(loglevel) plugin_logger.addFilter(EDMCContextFilter()) diff --git a/plug.py b/plug.py index 10e8957d..f3df95eb 100644 --- a/plug.py +++ b/plug.py @@ -203,12 +203,8 @@ def load_plugins(master): # Create a logger for this 'found' plugin. Must be before the # load.py is loaded. import EDMCLogging - if not os.getenv('EDMC_NO_UI'): - base_logger_name = appname - else: - base_logger_name = appcmdname - plugin_logger = EDMCLogging.get_plugin_logger(f'{base_logger_name}.{name}') + plugin_logger = EDMCLogging.get_plugin_logger(name) found.append(Plugin(name, os.path.join(config.plugin_dir, name, 'load.py'), plugin_logger)) except Exception as e: logger.exception(f'Failure loading found Plugin "{name}"')