11import argparse
22import asyncio
33import logging
4+ import os
45import pathlib
56import subprocess
67import sys
78import uuid
89from contextlib import closing
910from typing import Optional
1011
11- import yaml
1212from clp_py_utils .clp_config import (
1313 CLPConfig ,
1414 Database ,
@@ -229,18 +229,24 @@ def handle_extract_file_cmd(
229229 logs_dir = clp_config .logs_directory
230230 archives_dir = clp_config .archive_output .get_directory ()
231231
232- # Generate database config file for clp
233- db_config_file_path = logs_dir / f".decompress-db-config-{ uuid .uuid4 ()} .yml"
234- with open (db_config_file_path , "w" ) as f :
235- yaml .safe_dump (clp_config .database .get_clp_connection_params_and_type (True ), f )
236-
232+ # Configure CLP metadata DB connection params.
233+ clp_db_connection_params = clp_config .database .get_clp_connection_params_and_type (True )
237234 # fmt: off
238235 extract_cmd = [
239236 str (clp_home / "bin" / "clp" ),
240237 "x" , str (archives_dir ), str (extraction_dir ),
241- "--db-config-file" , str (db_config_file_path ),
238+ "--db-type" , clp_db_connection_params ["type" ],
239+ "--db-host" , clp_db_connection_params ["host" ],
240+ "--db-port" , str (clp_db_connection_params ["port" ]),
241+ "--db-name" , clp_db_connection_params ["name" ],
242+ "--db-table-prefix" , clp_db_connection_params ["table_prefix" ],
242243 ]
243244 # fmt: on
245+ extract_env = {
246+ ** os .environ ,
247+ "CLP_DB_USER" : clp_db_connection_params ["username" ],
248+ "CLP_DB_PASS" : clp_db_connection_params ["password" ],
249+ }
244250
245251 files_to_extract_list_path = None
246252 if list_path is not None :
@@ -256,7 +262,7 @@ def handle_extract_file_cmd(
256262 extract_cmd .append ("-f" )
257263 extract_cmd .append (str (files_to_extract_list_path ))
258264
259- proc = subprocess .Popen (extract_cmd )
265+ proc = subprocess .Popen (extract_cmd , env = extract_env )
260266 return_code = proc .wait ()
261267 if 0 != return_code :
262268 logger .error (f"File extraction failed, return_code={ return_code } " )
@@ -265,7 +271,6 @@ def handle_extract_file_cmd(
265271 # Remove generated files
266272 if files_to_extract_list_path is not None :
267273 files_to_extract_list_path .unlink ()
268- db_config_file_path .unlink ()
269274
270275 return 0
271276
0 commit comments