Skip to content

Commit

Permalink
fix: close log file in all cases
Browse files Browse the repository at this point in the history
  • Loading branch information
elkaboussi committed Mar 3, 2024
1 parent d5b7709 commit 5bc5db4
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import sys

from analyzer.file_processing import process_directory
from analyzer.utils.logger import setup_logging
from analyzer.utils.parser import parse_args


def main():
arguments = parse_args()
if arguments.target_dir is None:
exit(1)
if not arguments or not arguments.target_dir:
sys.exit(1)

setup_logging(
log_file=arguments.log_file,
Expand All @@ -15,12 +17,23 @@ def main():
delete_files=arguments.delete_files,
)

process_directory(
dir_path=arguments.target_dir,
size_threshold=str(arguments.size_threshold),
delete_files=arguments.delete_files,
log_file=arguments.log_file,
)
try:
process_directory(
dir_path=arguments.target_dir,
size_threshold=str(arguments.size_threshold),
delete_files=arguments.delete_files,
log_file=arguments.log_file,
)
finally:
if arguments.log_file is not None:

# Close log file
sys.stdout.close()
sys.stderr.close()

# Reset back to stanrds
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__


if __name__ == "__main__":
Expand Down

0 comments on commit 5bc5db4

Please sign in to comment.