Skip to content

Commit

Permalink
More graceful exiting
Browse files Browse the repository at this point in the history
  • Loading branch information
Audionut committed Sep 7, 2024
1 parent 04bd843 commit eb8d2bd
Showing 1 changed file with 45 additions and 11 deletions.
56 changes: 45 additions & 11 deletions upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,16 @@ async def check_mod_q_and_draft(tracker_class, meta, debug):
if tracker in api_trackers:
tracker_class = tracker_class_map[tracker](config=config)

# Confirm upload
if meta['unattended']:
upload_to_tracker = True
else:
upload_to_tracker = cli_ui.ask_yes_no(
f"Upload to {tracker_class.tracker}? {debug}",
default=meta['unattended']
)
try:
upload_to_tracker = cli_ui.ask_yes_no(
f"Upload to {tracker_class.tracker}? {debug}",
default=meta['unattended']
)
except (KeyboardInterrupt, EOFError):
sys.exit(1) # Exit immediately

if upload_to_tracker:
# Get mod_q, draft, or draft/live depending on the tracker
Expand Down Expand Up @@ -337,10 +339,18 @@ async def check_mod_q_and_draft(tracker_class, meta, debug):

if tracker in http_trackers:
tracker_class = tracker_class_map[tracker](config=config)

if meta['unattended']:
upload_to_tracker = True
else:
upload_to_tracker = cli_ui.ask_yes_no(f"Upload to {tracker_class.tracker}? {debug}", default=meta['unattended'])
try:
upload_to_tracker = cli_ui.ask_yes_no(
f"Upload to {tracker_class.tracker}? {debug}",
default=meta['unattended']
)
except (KeyboardInterrupt, EOFError):
sys.exit(1) # Exit immediately

if upload_to_tracker:
console.print(f"Uploading to {tracker}")
if check_banned_group(tracker_class.tracker, tracker_class.banned_groups, meta):
Expand Down Expand Up @@ -378,7 +388,13 @@ async def check_mod_q_and_draft(tracker_class, meta, debug):
if meta['unattended']:
upload_to_thr = True
else:
upload_to_thr = cli_ui.ask_yes_no(f"Upload to THR? {debug}", default=meta['unattended'])
try:
upload_to_ptp = cli_ui.ask_yes_no(
f"Upload to THR? {debug}",
default=meta['unattended']
)
except (KeyboardInterrupt, EOFError):
sys.exit(1) # Exit immediately
if upload_to_thr:
console.print("Uploading to THR")
# nable to get IMDB id/Youtube Link
Expand Down Expand Up @@ -407,8 +423,15 @@ async def check_mod_q_and_draft(tracker_class, meta, debug):
if meta['unattended']:
upload_to_ptp = True
else:
upload_to_ptp = cli_ui.ask_yes_no(f"Upload to {tracker}? {debug}", default=meta['unattended'])
if upload_to_ptp:
try:
upload_to_ptp = cli_ui.ask_yes_no(
f"Upload to {tracker}? {debug}",
default=meta['unattended']
)
except (KeyboardInterrupt, EOFError):
sys.exit(1) # Exit immediately

if upload_to_ptp: # Ensure the variable is defined before this check
console.print(f"Uploading to {tracker}")
if meta.get('imdb_id', '0') == '0':
imdb_id = cli_ui.ask_string("Unable to find IMDB id, please enter e.g.(tt1234567)")
Expand Down Expand Up @@ -445,7 +468,14 @@ async def check_mod_q_and_draft(tracker_class, meta, debug):
if meta['unattended']:
upload_to_tracker = True
else:
upload_to_tracker = cli_ui.ask_yes_no(f"Upload to {tracker_class.tracker}? {debug}", default=meta['unattended'])
try:
upload_to_ptp = cli_ui.ask_yes_no(
f"Upload to {tracker}? {debug}",
default=meta['unattended']
)
except (KeyboardInterrupt, EOFError):
sys.exit(1) # Exit immediately

if upload_to_tracker:
console.print(f"Uploading to {tracker_class.tracker}")
if check_banned_group(tracker_class.tracker, tracker_class.banned_groups, meta):
Expand Down Expand Up @@ -509,7 +539,11 @@ def get_confirmation(meta):

cli_ui.info_section(cli_ui.yellow, "Is this correct?")
cli_ui.info(f"Name: {meta['name']}")
confirm = cli_ui.ask_yes_no("Correct?", default=False)
try:
confirm = cli_ui.ask_yes_no("Correct?", default=False)
except (KeyboardInterrupt, EOFError):
sys.exit(1) # Exit immediately

else:
cli_ui.info(f"Name: {meta['name']}")
confirm = True
Expand Down

0 comments on commit eb8d2bd

Please sign in to comment.