Commit 0541bbb4 authored by mathieui's avatar mathieui

internal: remove more global state from config

parent 1640a90a
......@@ -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()
......@@ -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'
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment