Skip to content

Commit

Permalink
fix windows unit test on locked file
Browse files Browse the repository at this point in the history
  • Loading branch information
zackees committed May 10, 2023
1 parent ed10111 commit 44c3dbf
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/video_subtitles/run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Runs the program
"""

import atexit
import os
import shutil

Expand All @@ -21,6 +23,15 @@ def find_srt_files(folder: str) -> list[str]:
return files


def cleanup(file: str):
"""Attempts to remove the file."""
if os.path.exists(file):
try:
os.remove(file)
except Exception as err: # pylint: disable=broad-except
print(f"Error removing {file}: {err}")


def run( # pylint: disable=too-many-locals,too-many-branches,too-many-statements
file: str,
deepl_api_key: str | None,
Expand Down Expand Up @@ -97,7 +108,6 @@ def run( # pylint: disable=too-many-locals,too-many-branches,too-many-statement
os.remove(webvtt_file)
convert_webvtt(srt_file, webvtt_file)
os.remove(srt_file)
if os.path.exists("geckodriver.log"): # appears when generating srt files
os.remove("geckodriver.log")
atexit.register(cleanup, os.path.abspath("geckodriver.log"))
print("Done translating")
return outdir

0 comments on commit 44c3dbf

Please sign in to comment.