diff options
author | mathieui <mathieui@mathieui.net> | 2021-04-11 18:55:26 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2021-04-11 18:57:23 +0200 |
commit | 0541bbb4bcd3144afa682d8041f1235274a1468d (patch) | |
tree | bdbc669ccda186a7fc109569dc6352f4ec7f361d | |
parent | 1640a90a632ebe74a06602adc60fa8f1508fd7e5 (diff) | |
download | poezio-0541bbb4bcd3144afa682d8041f1235274a1468d.tar.gz poezio-0541bbb4bcd3144afa682d8041f1235274a1468d.tar.bz2 poezio-0541bbb4bcd3144afa682d8041f1235274a1468d.tar.xz poezio-0541bbb4bcd3144afa682d8041f1235274a1468d.zip |
internal: remove more global state from config
-rw-r--r-- | poezio/config.py | 29 | ||||
-rw-r--r-- | poezio/core/core.py | 8 | ||||
-rw-r--r-- | poezio/poezio.py | 3 |
3 files changed, 11 insertions, 29 deletions
diff --git a/poezio/config.py b/poezio/config.py index 5ea88a76..3289a8d8 100644 --- a/poezio/config.py +++ b/poezio/config.py @@ -10,16 +10,19 @@ TODO: get http://bugs.python.org/issue1410680 fixed, one day, in order to remove our ugly custom I/O methods. """ +import logging import logging.config import os import sys from configparser import RawConfigParser, NoOptionError, NoSectionError from pathlib import Path -from typing import Callable, Dict, List, Optional, Union, Tuple, cast, Any +from typing import Dict, List, Optional, Union, Tuple, cast, Any from poezio import xdg +from slixmpp import JID +log = logging.getLogger(__name__) # type: logging.Logger ConfigValue = Union[str, int, float, bool] @@ -256,7 +259,6 @@ class Config: in the section, we search for the global option if fallback is True. And we return `default` as a fallback as a last resort. """ - from slixmpp import JID if isinstance(tabname, JID): tabname = tabname.full if self.default and (not default) and fallback: @@ -276,7 +278,7 @@ class Config: """ Try to get the value of an option for a server """ - server = safeJID(jid).server + server = JID(jid).server if server: server = '@' + server if server in self.sections() and option in self.options(server): @@ -665,17 +667,6 @@ def setup_logging(debug_file=''): logging.disable(logging.ERROR) logging.basicConfig(level=logging.CRITICAL) - global log - log = logging.getLogger(__name__) - - -def post_logging_setup(): - # common imports slixmpp, which creates then its loggers, so - # it needs to be after logger configuration - from poezio.common import safeJID as JID - global safeJID - safeJID = JID - LOGGING_CONFIG = { 'version': 1, @@ -693,18 +684,8 @@ LOGGING_CONFIG = { } } -# True if this is the first run, in this case we will display -# some help in the info buffer -firstrun = False - # Global config object. Is setup for real in poezio.py config = Config(Path('/dev/null')) -# The logger object for this module -log = logging.getLogger(__name__) # type: logging.Logger - -# delayed import from common.py -safeJID = None # type: Optional[Callable] - # the global log dir LOG_DIR = Path() diff --git a/poezio/core/core.py b/poezio/core/core.py index 66af7a28..345a3f9a 100644 --- a/poezio/core/core.py +++ b/poezio/core/core.py @@ -46,7 +46,7 @@ from poezio.bookmarks import ( Bookmark, ) from poezio.common import get_error_message -from poezio.config import config, firstrun +from poezio.config import config from poezio.contact import Contact, Resource from poezio.daemon import Executor from poezio.fifo import Fifo @@ -87,11 +87,13 @@ class Core: """ custom_version: str + firstrun: bool - def __init__(self, custom_version: str): + def __init__(self, custom_version: str, firstrun: bool): self.completion = CompletionCore(self) self.command = CommandCore(self) self.handler = HandlerCore(self) + self.firstrun = firstrun # All uncaught exception are given to this callback, instead # of being displayed on the screen and exiting the program. sys.excepthook = self.on_exception @@ -545,7 +547,7 @@ class Core: ' colors will probably be ugly', 'Error', ) - if firstrun: + if self.firstrun: self.information( 'It seems that it is the first time you start poezio.\n' 'The online help is here https://doc.poez.io/\n\n' diff --git a/poezio/poezio.py b/poezio/poezio.py index 28e80496..e987467f 100644 --- a/poezio/poezio.py +++ b/poezio/poezio.py @@ -84,7 +84,6 @@ def main(): from poezio import config config.create_global_config(options.filename) config.setup_logging(options.debug) - config.post_logging_setup() import logging logging.raiseExceptions = False @@ -108,7 +107,7 @@ def main(): from poezio.core.core import Core signal.signal(signal.SIGINT, signal.SIG_IGN) # ignore ctrl-c - cocore = Core(options.custom_version) + cocore = Core(options.custom_version, firstrun) signal.signal(signal.SIGUSR1, cocore.sigusr_handler) # reload the config signal.signal(signal.SIGHUP, cocore.exit_from_signal) signal.signal(signal.SIGTERM, cocore.exit_from_signal) |