mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
Always use sys.exit when exiting the application
The `exit()` [1] function is not necessarily present in every Python environment, as it's added by the `site` module. Also, this function is "[...] useful for the interactive interpreter shell and should not be used in programs" For this reason, we replace all such occurrences with `sys.exit()` [2], which is the canonical function to exit Python programs. [1]: https://docs.python.org/3/library/constants.html#exit [2]: https://docs.python.org/3/library/sys.html#sys.exit
This commit is contained in:
parent
d6202cd028
commit
e11aaec3ac
6 changed files with 11 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
|||
import functools
|
||||
import os
|
||||
import sys
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
import click
|
||||
|
@ -86,7 +87,7 @@ def check_suspicious_options(args: List[str]) -> None:
|
|||
f" current working directory: {filenames_str}"
|
||||
)
|
||||
click.echo(msg)
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def override_parser_and_check_suspicious_options(click_main: click.Command) -> None:
|
||||
|
|
|
@ -67,7 +67,7 @@ def cli_main(
|
|||
dangerzone.add_document_from_filename(filenames[0], output_filename, archive)
|
||||
elif len(filenames) > 1 and output_filename:
|
||||
click.echo("--output-filename can only be used with one input file.")
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
else:
|
||||
for filename in filenames:
|
||||
dangerzone.add_document_from_filename(filename, archive=archive)
|
||||
|
@ -83,7 +83,7 @@ def cli_main(
|
|||
click.echo("Invalid OCR language code. Valid language codes:")
|
||||
for lang in dangerzone.ocr_languages:
|
||||
click.echo(f"{dangerzone.ocr_languages[lang]}: {lang}")
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
# Ensure container is installed
|
||||
dangerzone.isolation_provider.install()
|
||||
|
|
|
@ -107,6 +107,6 @@ def handle_document_errors(func: F) -> F:
|
|||
msg = "An exception occured while validating a document"
|
||||
log.exception(msg)
|
||||
click.echo(str(e))
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
return cast(F, wrapper)
|
||||
|
|
|
@ -430,7 +430,7 @@ class Reference:
|
|||
" to date with the respective doc section, and then update the cached"
|
||||
" section in this file."
|
||||
)
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
def find_section_text(self, md_text):
|
||||
"""Find a section's content in a provided Markdown string."""
|
||||
|
@ -978,7 +978,7 @@ def parse_args():
|
|||
|
||||
if not args.check_refs and not args.platform:
|
||||
parser.print_help(sys.stderr)
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
return args
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import itertools
|
|||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(
|
||||
os.path.dirname(
|
||||
|
@ -69,7 +70,7 @@ def sign_app_bundle(build_path, dist_path, app_path):
|
|||
# Detect if create-dmg is installed
|
||||
if not os.path.exists(app_path):
|
||||
print(f"ERROR: Dangerzone.app not found in {app_path}.")
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
dmg_path = os.path.join(dist_path, "Dangerzone.dmg")
|
||||
icon_path = os.path.join(root, "install", "macos", "dangerzone.icns")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
@ -23,7 +24,7 @@ FORMATS_REGEX = (
|
|||
def ensure_test_data_exists() -> None:
|
||||
if len(os.listdir(test_docs_repo_dir)) == 0:
|
||||
print("Test data repository it empty. Skipping large tests.")
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def get_test_docs(min_size: int, max_size: int) -> List[Path]:
|
||||
|
|
Loading…
Reference in a new issue