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

@@ -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):