From a5d477036a7650ce5cbbc58d77fb72e2cdc260a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilhem=20Faur=C3=A9?= Date: Mon, 5 Jun 2023 14:51:51 +0200 Subject: [PATCH] writing is now done within a database connection context --- spip2md/lib.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/spip2md/lib.py b/spip2md/lib.py index 410a802..af8f797 100644 --- a/spip2md/lib.py +++ b/spip2md/lib.py @@ -14,6 +14,8 @@ ROOTID = 0 # Define loggers for this file ROOTLOG = logging.getLogger(CFG.logname + ".root") LIBLOG = logging.getLogger(CFG.logname + ".lib") +# Initialize the database with settings from CFG +DB.init(CFG.db, host=CFG.db_host, user=CFG.db_user, password=CFG.db_pass) # Write the level 0 sections and their subtrees @@ -117,11 +119,6 @@ def cli(): init_logging() # Initialize logging and logfile clear_output() # Eventually remove already existing output dir - # Connect to the MySQL database with Peewee ORM - DB.init(CFG.db, host=CFG.db_host, user=CFG.db_user, password=CFG.db_pass) - DB.connect() - - # Write everything while printing the output human-readably - summarize(write_root(CFG.output_dir)) - - DB.close() # Close the connection with the database + with DB: # Connect to the database where SPIP site is stored in this block + # Write everything while printing the output human-readably + summarize(write_root(CFG.output_dir))