mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 04:46:29 +03:00
python: first pass at updates for dc_open/dc_close removal
This commit is contained in:
@@ -42,21 +42,20 @@ class Account(object):
|
|||||||
|
|
||||||
self.add_account_plugin(self)
|
self.add_account_plugin(self)
|
||||||
|
|
||||||
|
self.db_path = db_path
|
||||||
|
if hasattr(db_path, "encode"):
|
||||||
|
db_path = db_path.encode("utf8")
|
||||||
|
|
||||||
self._dc_context = ffi.gc(
|
self._dc_context = ffi.gc(
|
||||||
lib.dc_context_new(ffi.NULL, as_dc_charpointer(os_name)),
|
lib.dc_context_new(as_dc_charpointer(os_name), db_path, ffi.NULL),
|
||||||
_destroy_dc_context,
|
_destroy_dc_context,
|
||||||
)
|
)
|
||||||
|
if self._dc_context == ffi.NULL:
|
||||||
|
raise ValueError("Could not dc_context_new: {} {}".format(os_name, db_path))
|
||||||
|
|
||||||
hook = hookspec.Global._get_plugin_manager().hook
|
hook = hookspec.Global._get_plugin_manager().hook
|
||||||
|
|
||||||
self._shutdown_event = Event()
|
self._shutdown_event = Event()
|
||||||
|
|
||||||
# open database
|
|
||||||
self.db_path = db_path
|
|
||||||
if hasattr(db_path, "encode"):
|
|
||||||
db_path = db_path.encode("utf8")
|
|
||||||
if not lib.dc_open(self._dc_context, db_path, ffi.NULL):
|
|
||||||
raise ValueError("Could not dc_open: {}".format(db_path))
|
|
||||||
self._event_thread = EventThread(self)
|
self._event_thread = EventThread(self)
|
||||||
self._configkeys = self.get_config("sys.config_keys").split()
|
self._configkeys = self.get_config("sys.config_keys").split()
|
||||||
atexit.register(self.shutdown)
|
atexit.register(self.shutdown)
|
||||||
@@ -622,15 +621,14 @@ class Account(object):
|
|||||||
|
|
||||||
self.stop_scheduler()
|
self.stop_scheduler()
|
||||||
|
|
||||||
self.log("dc_close")
|
self.log("remove dc_context")
|
||||||
# the dc_close triggers get_next_event to return ffi.NULL
|
# the dc_context_unref triggers get_next_event to return ffi.NULL
|
||||||
# which in turns makes the event thread finish execution
|
# which in turns makes the event thread finish execution
|
||||||
lib.dc_close(dc_context)
|
self._dc_context = None
|
||||||
|
|
||||||
self.log("wait for event thread to finish")
|
self.log("wait for event thread to finish")
|
||||||
self._event_thread.wait()
|
self._event_thread.wait()
|
||||||
|
|
||||||
self._dc_context = None
|
|
||||||
atexit.unregister(self.shutdown)
|
atexit.unregister(self.shutdown)
|
||||||
self._shutdown_event.set()
|
self._shutdown_event.set()
|
||||||
hook = hookspec.Global._get_plugin_manager().hook
|
hook = hookspec.Global._get_plugin_manager().hook
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ from deltachat.capi import lib
|
|||||||
|
|
||||||
|
|
||||||
def test_empty_context():
|
def test_empty_context():
|
||||||
ctx = capi.lib.dc_context_new(capi.ffi.NULL, capi.ffi.NULL)
|
ctx = capi.lib.dc_context_new(capi.ffi.NULL, capi.ffi.NULL, capi.ffi.NULL)
|
||||||
capi.lib.dc_close(ctx)
|
capi.lib.dc_context_unref(ctx)
|
||||||
|
|
||||||
|
|
||||||
def test_dc_close_events(tmpdir, acfactory):
|
def test_dc_close_events(tmpdir, acfactory):
|
||||||
@@ -32,24 +32,20 @@ def test_dc_close_events(tmpdir, acfactory):
|
|||||||
|
|
||||||
|
|
||||||
def test_wrong_db(tmpdir):
|
def test_wrong_db(tmpdir):
|
||||||
dc_context = ffi.gc(
|
|
||||||
lib.dc_context_new(ffi.NULL, ffi.NULL),
|
|
||||||
lib.dc_context_unref,
|
|
||||||
)
|
|
||||||
p = tmpdir.join("hello.db")
|
p = tmpdir.join("hello.db")
|
||||||
# write an invalid database file
|
# write an invalid database file
|
||||||
p.write("x123" * 10)
|
p.write("x123" * 10)
|
||||||
assert not lib.dc_open(dc_context, p.strpath.encode("ascii"), ffi.NULL)
|
|
||||||
|
|
||||||
|
assert ffi.NULL == lib.dc_context_new(ffi.NULL, ffi.NULL, p.strpath.encode("ascii"), ffi.NULL)
|
||||||
|
|
||||||
def test_empty_blobdir(tmpdir):
|
def test_empty_blobdir(tmpdir):
|
||||||
|
db_fname = tmpdir.join("hello.db")
|
||||||
# Apparently some client code expects this to be the same as passing NULL.
|
# Apparently some client code expects this to be the same as passing NULL.
|
||||||
ctx = ffi.gc(
|
ctx = ffi.gc(
|
||||||
lib.dc_context_new(ffi.NULL, ffi.NULL),
|
lib.dc_context_new(ffi.NULL, ffi.NULL, db_fname.strpath.encode("ascii"), b""),
|
||||||
lib.dc_context_unref,
|
lib.dc_context_unref,
|
||||||
)
|
)
|
||||||
db_fname = tmpdir.join("hello.db")
|
assert ctx != ffi.NULL
|
||||||
assert lib.dc_open(ctx, db_fname.strpath.encode("ascii"), b"")
|
|
||||||
|
|
||||||
|
|
||||||
def test_event_defines():
|
def test_event_defines():
|
||||||
@@ -107,30 +103,11 @@ def test_get_info_closed():
|
|||||||
|
|
||||||
|
|
||||||
def test_get_info_open(tmpdir):
|
def test_get_info_open(tmpdir):
|
||||||
|
db_fname = tmpdir.join("test.db")
|
||||||
ctx = ffi.gc(
|
ctx = ffi.gc(
|
||||||
lib.dc_context_new(ffi.NULL, ffi.NULL),
|
lib.dc_context_new(ffi.NULL, ffi.NULL, db_fname.strpath.encode("ascii"), ffi.NULL),
|
||||||
lib.dc_context_unref,
|
lib.dc_context_unref,
|
||||||
)
|
)
|
||||||
db_fname = tmpdir.join("test.db")
|
|
||||||
lib.dc_open(ctx, db_fname.strpath.encode("ascii"), ffi.NULL)
|
|
||||||
info = cutil.from_dc_charpointer(lib.dc_get_info(ctx))
|
info = cutil.from_dc_charpointer(lib.dc_get_info(ctx))
|
||||||
assert 'deltachat_core_version' in info
|
assert 'deltachat_core_version' in info
|
||||||
assert 'database_dir' in info
|
assert 'database_dir' in info
|
||||||
|
|
||||||
|
|
||||||
def test_is_open_closed():
|
|
||||||
ctx = ffi.gc(
|
|
||||||
lib.dc_context_new(ffi.NULL, ffi.NULL),
|
|
||||||
lib.dc_context_unref,
|
|
||||||
)
|
|
||||||
assert lib.dc_is_open(ctx) == 0
|
|
||||||
|
|
||||||
|
|
||||||
def test_is_open_actually_open(tmpdir):
|
|
||||||
ctx = ffi.gc(
|
|
||||||
lib.dc_context_new(ffi.NULL, ffi.NULL),
|
|
||||||
lib.dc_context_unref,
|
|
||||||
)
|
|
||||||
db_fname = tmpdir.join("test.db")
|
|
||||||
lib.dc_open(ctx, db_fname.strpath.encode("ascii"), ffi.NULL)
|
|
||||||
assert lib.dc_is_open(ctx) == 1
|
|
||||||
|
|||||||
Reference in New Issue
Block a user