mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2025-07-21 10:15:12 +03:00
196 lines
6.8 KiB
Diff
196 lines
6.8 KiB
Diff
From 70b2960b4075e8c04ba3d2236caba95997334187 Mon Sep 17 00:00:00 2001
|
|
From: Noel Kuntze <noel.kuntze@thermi.consulting>
|
|
Date: Mon, 26 Apr 2021 21:26:32 +0200
|
|
Subject: [PATCH] python: Use libmdbx instead of bsddb
|
|
|
|
---
|
|
ECtools/backup/kopano_backup/__init__.py | 18 ++++++++++--------
|
|
ECtools/backup/requirements.txt | 2 +-
|
|
ECtools/search/kopano_search/__init__.py | 10 +++++-----
|
|
ECtools/search/requirements.txt | 2 +-
|
|
ECtools/spamd/kopano_spamd/__init__.py | 6 +++---
|
|
ECtools/spamd/requirements.txt | 2 +-
|
|
ECtools/utils/kopano_utils/autorespond.py | 6 +++---
|
|
7 files changed, 24 insertions(+), 22 deletions(-)
|
|
|
|
diff --git a/ECtools/backup/kopano_backup/__init__.py b/ECtools/backup/kopano_backup/__init__.py
|
|
index 68280e63e..7471b865a 100644
|
|
--- a/ECtools/backup/kopano_backup/__init__.py
|
|
+++ b/ECtools/backup/kopano_backup/__init__.py
|
|
@@ -18,7 +18,7 @@ try:
|
|
import cPickle as pickle
|
|
except ImportError:
|
|
import _pickle as pickle
|
|
-import bsddb3 as bsddb
|
|
+import libmdbx
|
|
|
|
from MAPI import (
|
|
PT_UNICODE, PT_ERROR, KEEP_OPEN_READWRITE,
|
|
@@ -107,7 +107,7 @@ def fatal(s):
|
|
sys.exit(1)
|
|
|
|
def dbopen(path):
|
|
- return bsddb.hashopen(path, 'c')
|
|
+ return libmdbx.Env(path)
|
|
|
|
def _copy_folder_meta(from_dir, to_dir, keep_db=False):
|
|
if not os.path.exists(to_dir):
|
|
@@ -864,11 +864,13 @@ def folder_struct(data_path, options, mapper=None): # XXX deprecate?
|
|
|
|
def folder_deleted(data_path):
|
|
if os.path.exists(data_path+'/index'):
|
|
- with closing(bsddb.hashopen(data_path+'/index')) as db:
|
|
- idx = db.get(b'folder')
|
|
- if idx and pickle_loads(idx).get(b'backup_deleted'):
|
|
- return pickle_loads(idx).get(b'backup_deleted')
|
|
- return None
|
|
+ # implement usage as "with" and use it.
|
|
+ env=libmdbx.Env(data_path+'/index')
|
|
+ idx=env[b'folder']
|
|
+ if idx:
|
|
+ value= pickle_loads(idx).get(b'backup_deleted'):
|
|
+ if value:
|
|
+ return value
|
|
|
|
def show_contents(data_path, options):
|
|
""" summary of contents of backup directory, at the item or folder level, in CSV format """
|
|
@@ -893,7 +895,7 @@ def show_contents(data_path, options):
|
|
|
|
# filter items on date using 'index' database
|
|
if os.path.exists(data_path+'/index'):
|
|
- with closing(bsddb.hashopen(data_path+'/index')) as db:
|
|
+ with closing(libmdbx.Env(data_path+'/index')) as db:
|
|
for key, value in db.items():
|
|
d = pickle_loads(value)
|
|
if ((key == b'folder') or
|
|
diff --git a/ECtools/backup/requirements.txt b/ECtools/backup/requirements.txt
|
|
index 6ee1b7b47..2e968c7f0 100644
|
|
--- a/ECtools/backup/requirements.txt
|
|
+++ b/ECtools/backup/requirements.txt
|
|
@@ -1,3 +1,3 @@
|
|
MAPI
|
|
-bsddb3
|
|
+libmdbx
|
|
kopano
|
|
diff --git a/ECtools/search/kopano_search/__init__.py b/ECtools/search/kopano_search/__init__.py
|
|
index 86b2eb28c..0795d3dcb 100644
|
|
--- a/ECtools/search/kopano_search/__init__.py
|
|
+++ b/ECtools/search/kopano_search/__init__.py
|
|
@@ -11,7 +11,7 @@ from multiprocessing import Queue, Value
|
|
import time
|
|
import sys
|
|
|
|
-import bsddb3 as bsddb
|
|
+import libmdbx
|
|
from queue import Empty
|
|
|
|
from kopano_search import plaintext
|
|
@@ -77,7 +77,7 @@ def db_get(db_path, key):
|
|
""" get value from db file """
|
|
if not isinstance(key, bytes): # python3
|
|
key = key.encode('ascii')
|
|
- with closing(bsddb.hashopen(db_path, 'c')) as db:
|
|
+ with closing(libmdbx.Env(db_path)) as db:
|
|
value = db.get(key)
|
|
if value is not None:
|
|
return db.get(key).decode('ascii')
|
|
@@ -88,7 +88,7 @@ def db_put(db_path, key, value):
|
|
key = key.encode('ascii')
|
|
with open(db_path+'.lock', 'w') as lockfile:
|
|
fcntl.flock(lockfile.fileno(), fcntl.LOCK_EX)
|
|
- with closing(bsddb.hashopen(db_path, 'c')) as db:
|
|
+ with closing(libmdbx.Env(db_path)) as db:
|
|
db[key] = value
|
|
|
|
class SearchWorker(kopano.Worker):
|
|
@@ -308,8 +308,8 @@ class Service(kopano.Service):
|
|
worker.start()
|
|
try:
|
|
self.state = db_get(self.state_db, 'SERVER')
|
|
- except bsddb.db.DBAccessError:
|
|
- self.log.error("Cannot access '%s': permission denied", self.state_db)
|
|
+ except libmdbx.MDBXErrorExc as exc:
|
|
+ self.log.error("Cannot access '%s': %s", self.state_db, exc.message)
|
|
sys.exit(1)
|
|
|
|
if self.state:
|
|
diff --git a/ECtools/search/requirements.txt b/ECtools/search/requirements.txt
|
|
index ba0834df3..04b7c433f 100644
|
|
--- a/ECtools/search/requirements.txt
|
|
+++ b/ECtools/search/requirements.txt
|
|
@@ -1,3 +1,3 @@
|
|
-bsddb3
|
|
+libmdbx
|
|
kopano
|
|
xapian
|
|
diff --git a/ECtools/spamd/kopano_spamd/__init__.py b/ECtools/spamd/kopano_spamd/__init__.py
|
|
index 7fb8f422d..c31afb277 100644
|
|
--- a/ECtools/spamd/kopano_spamd/__init__.py
|
|
+++ b/ECtools/spamd/kopano_spamd/__init__.py
|
|
@@ -8,7 +8,7 @@ import os
|
|
import sys
|
|
import time
|
|
|
|
-import bsddb3 as bsddb
|
|
+import libmdbx
|
|
|
|
import kopano
|
|
from kopano import Config, log_exc
|
|
@@ -53,13 +53,13 @@ class Importer:
|
|
def mark_spam(self, searchkey):
|
|
if not isinstance(searchkey, bytes): # python3
|
|
searchkey = searchkey.encode('ascii')
|
|
- with closing(bsddb.btopen(self.spamdb, 'c')) as db:
|
|
+ with closing(libmdbx.Env(self.spamdb)) as db:
|
|
db[searchkey] = ''
|
|
|
|
def was_spam(self, searchkey):
|
|
if not isinstance(searchkey, bytes): # python3
|
|
searchkey = searchkey.encode('ascii')
|
|
- with closing(bsddb.btopen(self.spamdb, 'c')) as db:
|
|
+ with closing(libmdbx.Env(self.spamdb)) as db:
|
|
return searchkey in db
|
|
|
|
def update(self, item, flags):
|
|
diff --git a/ECtools/spamd/requirements.txt b/ECtools/spamd/requirements.txt
|
|
index 82a553bb6..f0b35cb8a 100644
|
|
--- a/ECtools/spamd/requirements.txt
|
|
+++ b/ECtools/spamd/requirements.txt
|
|
@@ -1,2 +1,2 @@
|
|
kopano
|
|
-bsddb3
|
|
+libmdbx
|
|
diff --git a/ECtools/utils/kopano_utils/autorespond.py b/ECtools/utils/kopano_utils/autorespond.py
|
|
index 1f83a41d2..0664e3390 100644
|
|
--- a/ECtools/utils/kopano_utils/autorespond.py
|
|
+++ b/ECtools/utils/kopano_utils/autorespond.py
|
|
@@ -9,7 +9,7 @@ import time
|
|
import kopano
|
|
from kopano.log import logger
|
|
|
|
-import bsddb3 as bsddb
|
|
+import libmdbx
|
|
|
|
CONFIG = {
|
|
"autorespond_cc": kopano.Config.boolean(default=False),
|
|
@@ -41,7 +41,7 @@ def send_ooo(server, username, msg, copy_to_sentmail):
|
|
|
|
|
|
def check_time(senddb, timelimit, username, to):
|
|
- with closing(bsddb.btopen(senddb, 'c')) as db:
|
|
+ with closing(libmdbx.Env(senddb)) as db:
|
|
key = username + ":" + to
|
|
key = key.encode('utf-8')
|
|
if key in db:
|
|
@@ -52,7 +52,7 @@ def check_time(senddb, timelimit, username, to):
|
|
|
|
|
|
def add_time(senddb, username, to):
|
|
- with closing(bsddb.btopen(senddb, 'c')) as db:
|
|
+ with closing(libmdbx.Env(senddb)) as db:
|
|
key = username + ":" + to
|
|
key = key.encode('utf-8')
|
|
db[key] = str(int(time.time()))
|
|
--
|
|
2.31.1
|
|
|