Skip to content

Commit cea2765

Browse files
Brutus5000Sheikah45
authored andcommitted
Remove docker-based run_sql
1 parent dec67a6 commit cea2765

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

apps/faf-legacy-deployment/scripts/deploy-coop-maps.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,15 @@ def new_file_is_different(old_file_name: str, new_file_name: str) -> bool:
195195
return old_file_md5 != new_file_md5
196196

197197

198-
def update_database(coop_map: CoopMap, new_version: int) -> None:
198+
def update_database(conn, coop_map: CoopMap, new_version: int) -> None:
199199
logger.debug(f"Updating coop map {coop_map} in database to version {new_version}")
200200

201201
query = f"""
202202
UPDATE coop_map
203203
SET version = {new_version}, filename = "maps/{coop_map.build_zip_filename(new_version)}"
204204
WHERE id = {coop_map.map_id}
205205
"""
206-
run_sql(query)
206+
run_sql(conn, query)
207207

208208

209209
def copytree(src, dst, symlinks=False, ignore=None):
@@ -229,7 +229,7 @@ def create_zip_package(coop_map: CoopMap, version: int, files: List[str], tmp_fo
229229
zip_file.write(path, arcname=f"/{coop_map.build_folder_name(version)}/{os.path.relpath(path, tmp_folder_path)}")
230230

231231

232-
def process_coop_map(coop_map: CoopMap, simulate: bool, git_directory:str, coop_maps_path: str):
232+
def process_coop_map(conn, coop_map: CoopMap, simulate: bool, git_directory:str, coop_maps_path: str):
233233
logger.info(f"Processing: {coop_map}")
234234

235235
temp_dir = TemporaryDirectory()
@@ -260,7 +260,7 @@ def process_coop_map(coop_map: CoopMap, simulate: bool, git_directory:str, coop_
260260
zip_file_path = os.path.join(coop_maps_path, coop_map.build_zip_filename(new_version))
261261
create_zip_package(coop_map, new_version, processing_files, temp_dir.name, zip_file_path)
262262

263-
update_database(coop_map, new_version)
263+
update_database(conn, coop_map, new_version)
264264
else:
265265
logger.info(f"Updating database skipped due to simulation")
266266
else:
@@ -290,26 +290,6 @@ def run_checked_shell(cmd: List[str]) -> subprocess.CompletedProcess:
290290
return subprocess.run(cmd, check=True, stdout=subprocess.PIPE)
291291

292292

293-
def run_sql(sql: str, container: str = "faf-db", database: str = "faf_lobby") -> str:
294-
295-
"""
296-
Run a sql-query against the faf-db in the docker container
297-
:param database: name of the database where to run the query
298-
:param container: name of the docker container where to run the query
299-
:param sql: the sql-query to run
300-
:return: the query output as string
301-
"""
302-
try:
303-
sql_text_result = run_checked_shell(
304-
["docker", "exec", "-u", "root", container, "mysql", database, "-e", sql]
305-
).stdout.decode() # type: str
306-
logger.debug(f"SQL output >>> \n{sql_text_result}<<<")
307-
return sql_text_result
308-
except subprocess.CalledProcessError as e:
309-
logger.error(f"""Executing sql query failed: {sql}\n\t\tError message: {str(e)}""")
310-
exit(1)
311-
312-
313293
def git_checkout(path: str, tag: str) -> None:
314294
"""
315295
Checkout a git tag of the git repository. This requires the repo to be checked out in the path folder!
@@ -373,9 +353,10 @@ def create_zip(content: List[str], relative_to: str, output_file: str) -> None:
373353
args = parser.parse_args()
374354

375355
git_checkout(args.git_directory, args.version)
356+
conn = get_db_connection()
376357

377358
for coop_map in coop_maps:
378359
try:
379-
process_coop_map(coop_map, args.simulate, args.git_directory, args.coop_maps_path)
360+
process_coop_map(conn, coop_map, args.simulate, args.git_directory, args.coop_maps_path)
380361
except Exception as error:
381362
logger.warning(f"Unable to parse {coop_map}", exc_info=True)

0 commit comments

Comments
 (0)