mirror of
http://git.k-space.ee/arti/doors.git
synced 2024-12-12 15:40:58 +02:00
Add support for db export
This commit is contained in:
parent
472c762de2
commit
a9abf1eba0
@ -21,6 +21,10 @@ if __name__ == "__main__":
|
||||
from .db import import_ookean
|
||||
import_ookean()
|
||||
sys.exit(1)
|
||||
elif cmd == "export_db":
|
||||
from .db import export_db
|
||||
export_db()
|
||||
sys.exit(1)
|
||||
else:
|
||||
try:
|
||||
port = int(sys.argv[1])
|
||||
|
@ -193,11 +193,18 @@ class DB:
|
||||
for user in unmatched:
|
||||
print(f"User {user}")
|
||||
|
||||
|
||||
|
||||
def export_db(self, json_file):
|
||||
for user in self.list_users():
|
||||
pass
|
||||
def export_db(self):
|
||||
users = {}
|
||||
cur = self.db.execute("select id, distinguished_name, user, full_name, email, disabled, admin from users")
|
||||
for user in cur.fetchall():
|
||||
users[user["full_name"]] = dict(user)
|
||||
del users[user["full_name"]]["id"]
|
||||
cards_cur = self.db.execute(
|
||||
"select card_uid, name, created, disabled from keycards where user_id = ?",
|
||||
(user["id"],)
|
||||
)
|
||||
users[user["full_name"]]["keycards"] = [dict(keycard) for keycard in cards_cur.fetchall()]
|
||||
return users
|
||||
|
||||
|
||||
def initdb():
|
||||
@ -222,5 +229,15 @@ def import_ookean():
|
||||
db.import_ookean("../contrib/ookean_cards.json")
|
||||
|
||||
|
||||
def export_db():
|
||||
dbfile = "kdoorweb.sqlite"
|
||||
db = DB(dbfile)
|
||||
import sys
|
||||
exports = db.export_db()
|
||||
json.dump(exports, sys.stdout, indent=2)
|
||||
sys.stdout.write("\n")
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
initdb()
|
||||
|
Loading…
Reference in New Issue
Block a user