diff --git a/python/src/deltachat/__init__.py b/python/src/deltachat/__init__.py index 52ca63fc7..0633f8c1f 100644 --- a/python/src/deltachat/__init__.py +++ b/python/src/deltachat/__init__.py @@ -2,7 +2,7 @@ import sys from . import capi, const, hookspec # 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 .contact import Contact # noqa from .chat import Chat # noqa diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index 77962f9dc..f4366aaea 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -22,6 +22,29 @@ class MissingCredentials(ValueError): """ 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): """ Each account is tied to a sqlite database file which is fully managed 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]: """ return dictionary of built config parameters. """ - lines = from_dc_charpointer(lib.dc_get_info(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 + return get_dc_info_as_dict(self._dc_context) def dump_account_info(self, logfile): def log(*args, **kwargs): diff --git a/python/src/deltachat/testplugin.py b/python/src/deltachat/testplugin.py index a7a710f92..417b5c487 100644 --- a/python/src/deltachat/testplugin.py +++ b/python/src/deltachat/testplugin.py @@ -8,14 +8,13 @@ import threading import fnmatch import time import weakref -import tempfile from queue import Queue from typing import List, Callable import pytest import requests -from . import Account, const, account_hookimpl +from . import Account, const, account_hookimpl, get_core_info from .events import FFIEventLogger, FFIEventTracker from _pytest._code import Source @@ -108,20 +107,12 @@ def pytest_configure(config): def pytest_report_header(config, startdir): - summary = [] - - t = tempfile.mktemp() - try: - ac = Account(t) - 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'], - )]) + info = get_core_info() + summary = ['Deltachat core={} sqlite={} journal_mode={}'.format( + info['deltachat_core_version'], + info['sqlite_version'], + info['journal_mode'], + )] cfg = config.option.liveconfig if cfg: