Skip to content

Commit

Permalink
Using sys.exit() instead of just exit()
Browse files Browse the repository at this point in the history
  • Loading branch information
clausjuhl committed Feb 8, 2023
1 parent 4073709 commit 0589cbf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "smart-client"
version = "0.1.6"
version = "0.1.7"
description = "Klient til Smartarkivering.dk-submissions"
authors = ["Claus Juhl Knudsen <[email protected]>"]
include = ["pyproject.toml"]
Expand Down
15 changes: 8 additions & 7 deletions smart_client/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from http.client import HTTPException
import os
import sys
import locale
import hashlib
import json
Expand Down Expand Up @@ -264,7 +265,7 @@ def main() -> None:
try:
config.load_configuration()
except (FileNotFoundError, ValueError) as e:
exit(e)
sys.exit(e)

# Setup parser
cli: GooeyParser = GooeyParser(description="Smartarkivering")
Expand All @@ -274,35 +275,35 @@ def main() -> None:
try:
uuid.UUID(args.uuid)
except ValueError as e:
exit("FEJL. Det indtastede uuid har ikke det korrekte format.")
sys.exit("FEJL. Det indtastede uuid har ikke det korrekte format.")

if not Path(args.destination).is_dir():
exit("FEJL. Destinationen skal være en eksisterende mappe.")
sys.exit("FEJL. Destinationen skal være en eksisterende mappe.")

out_dir = Path(args.destination, args.uuid)
try:
out_dir.mkdir(parents=True, exist_ok=True)
except Exception as e:
exit(f"FEJl. Kan ikke oprette destinationsmappen: {e}")
sys.exit(f"FEJl. Kan ikke oprette destinationsmappen: {e}")

# Fetch submission info
try:
# get_submission_info prints any errors with http or json-parsing
submission: dict = get_submission_info(args.uuid)
except (Exception) as e:
exit(e)
sys.exit(e)

# extract info on uploaded files
try:
fileinfo: list[dict] = extract_filelist(submission)
except ValueError:
exit("FEJL. Afleveringen indeholder ingen filreferencer")
sys.exit("FEJL. Afleveringen indeholder ingen filreferencer")

# download attached files
try:
download_files(fileinfo, out_dir)
except (Exception) as e:
exit(e)
sys.exit(e)

# update fileinfo
hash = "md5" if args.md5 else "sha256"
Expand Down

0 comments on commit 0589cbf

Please sign in to comment.