avoid instatiating a full blown Account object just for showing some core info

This commit is contained in:
holger krekel
2022-05-03 19:08:35 +02:00
parent e44f68db83
commit 0422d751d8
3 changed files with 32 additions and 25 deletions

View File

@@ -2,7 +2,7 @@ import sys
from . import capi, const, hookspec # noqa from . import capi, const, hookspec # noqa
from .capi import ffi # noqa from .capi import ffi # noqa
from .account import Account # noqa from .account import Account, get_core_info # noqa
from .message import Message # noqa from .message import Message # noqa
from .contact import Contact # noqa from .contact import Contact # noqa
from .chat import Chat # noqa from .chat import Chat # noqa

View File

@@ -22,6 +22,29 @@ class MissingCredentials(ValueError):
""" Account is missing `addr` and `mail_pw` config values. """ """ Account is missing `addr` and `mail_pw` config values. """
def get_core_info():
""" get some system info. """
from tempfile import NamedTemporaryFile
with NamedTemporaryFile() as path:
path.close()
return get_dc_info_as_dict(ffi.gc(
lib.dc_context_new(as_dc_charpointer(""), as_dc_charpointer(path.name), ffi.NULL),
lib.dc_context_unref,
))
def get_dc_info_as_dict(dc_context):
lines = from_dc_charpointer(lib.dc_get_info(dc_context))
info_dict = {}
for line in lines.split("\n"):
if not line.strip():
continue
key, value = line.split("=", 1)
info_dict[key.lower()] = value
return info_dict
class Account(object): class Account(object):
""" Each account is tied to a sqlite database file which is fully managed """ Each account is tied to a sqlite database file which is fully managed
by the underlying deltachat core library. All public Account methods are by the underlying deltachat core library. All public Account methods are
@@ -84,14 +107,7 @@ class Account(object):
def get_info(self) -> Dict[str, str]: def get_info(self) -> Dict[str, str]:
""" return dictionary of built config parameters. """ """ return dictionary of built config parameters. """
lines = from_dc_charpointer(lib.dc_get_info(self._dc_context)) return get_dc_info_as_dict(self._dc_context)
d = {}
for line in lines.split("\n"):
if not line.strip():
continue
key, value = line.split("=", 1)
d[key.lower()] = value
return d
def dump_account_info(self, logfile): def dump_account_info(self, logfile):
def log(*args, **kwargs): def log(*args, **kwargs):

View File

@@ -8,14 +8,13 @@ import threading
import fnmatch import fnmatch
import time import time
import weakref import weakref
import tempfile
from queue import Queue from queue import Queue
from typing import List, Callable from typing import List, Callable
import pytest import pytest
import requests import requests
from . import Account, const, account_hookimpl from . import Account, const, account_hookimpl, get_core_info
from .events import FFIEventLogger, FFIEventTracker from .events import FFIEventLogger, FFIEventTracker
from _pytest._code import Source from _pytest._code import Source
@@ -108,20 +107,12 @@ def pytest_configure(config):
def pytest_report_header(config, startdir): def pytest_report_header(config, startdir):
summary = [] info = get_core_info()
summary = ['Deltachat core={} sqlite={} journal_mode={}'.format(
t = tempfile.mktemp() info['deltachat_core_version'],
try: info['sqlite_version'],
ac = Account(t) info['journal_mode'],
info = ac.get_info() )]
ac.shutdown()
finally:
os.remove(t)
summary.extend(['Deltachat core={} sqlite={} journal_mode={}'.format(
info['deltachat_core_version'],
info['sqlite_version'],
info['journal_mode'],
)])
cfg = config.option.liveconfig cfg = config.option.liveconfig
if cfg: if cfg: