Skip to content

Commit

Permalink
load_mission, load_mapping: using sys.exit to allow package using
Browse files Browse the repository at this point in the history
pyinstaller.
  • Loading branch information
saitewasreset committed Aug 26, 2024
1 parent cd2c764 commit 46a545e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
19 changes: 10 additions & 9 deletions script/load_mapping/load_mapping.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests
import json
import sys

source_addr = "https://github.com/saitewasreset/DRG_MissionMonitor"

Expand All @@ -22,15 +23,15 @@
except KeyError as e:
print("Invalid config.json: cannot get required key: ", e)
input("Press enter to exit...")
exit(1)
sys.exit(1)
except json.JSONDecodeError as e:
print("Invalid config.json: ", e)
input("Press enter to exit...")
exit(1)
sys.exit(1)
except OSError as e:
print("Cannot open config.json: ", e)
input("Press enter to exit...")
exit(1)
sys.exit(1)

print("admin endpoint: {}".format(admin_endpoint))
print("mapping path: {}".format(mapping_path))
Expand All @@ -56,7 +57,7 @@ def load_mapping(mapping_name: str):
except OSError as e:
print("Cannot open {}.txt: ".format(mapping_name), e)
input("Press enter to exit...")
exit(1)
sys.exit(1)
print("Uploading {}...".format(mapping_name))
r = requests.post("{}/mapping/{}".format(admin_endpoint, mapping_name), json=mapping)
try:
Expand All @@ -65,7 +66,7 @@ def load_mapping(mapping_name: str):
except json.JSONDecodeError as e:
print("Invalid response from server: ", e)
input("Press enter to exit...")
exit(1)
sys.exit(1)
print("Success")


Expand All @@ -83,11 +84,11 @@ def load_mapping(mapping_name: str):
except json.JSONDecodeError as e:
print("Invalid response from server: ", e)
input("Press enter to exit...")
exit(1)
sys.sys.exit(1)
except OSError as e:
print("Cannot open entity_blacklist.txt: ", e)
input("Press enter to exit...")
exit(1)
sys.exit(1)

print("Updating cache...")
r = requests.get("https://rocknstone.top/wearerich/mission_monitor/api/secret20231301_admin/update_essential")
Expand All @@ -96,13 +97,13 @@ def load_mapping(mapping_name: str):
if res["code"] != 200:
print("Server returned an error: ", res)
input("Press enter to exit...")
exit(1)
sys.exit(1)
else:
print("Success")
except json.JSONDecodeError as e:
print("Invalid response from server: ", e)
input("Press enter to exit...")
exit(1)
sys.exit(1)

print("Rock and stone!")
input("Press enter to exit...")
15 changes: 8 additions & 7 deletions script/load_mission/load_mission.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import requests
import os
import re
Expand All @@ -24,15 +25,15 @@
except KeyError as e:
print("Invalid config.json: cannot get required key: ", e)
input("Press enter to exit...")
exit(1)
sys.exit(1)
except json.JSONDecodeError as e:
print("Invalid config.json: ", e)
input("Press enter to exit...")
exit(1)
sys.exit(1)
except OSError as e:
print("Cannot open config.json: ", e)
input("Press enter to exit...")
exit(1)
sys.exit(1)

already_uploaded_endpoint = "{}/mission_list".format(admin_endpoint)
upload_endpoint = "{}/load_mission".format(admin_endpoint)
Expand Down Expand Up @@ -91,13 +92,13 @@
if res["code"] != 200:
print("Server returned an error: ", res)
input("Press enter to exit...")
exit(1)
sys.exit(1)
else:
print("Success!")
except json.JSONDecodeError:
print("Invalid response from server: ", r.text)
input("Press enter to exit...")
exit(1)
sys.exit(1)

print("Updating cache...")
r = requests.get(update_endpoint)
Expand All @@ -106,13 +107,13 @@
if res["code"] != 200:
print("Server returned an error: ", res)
input("Press enter to exit...")
exit(1)
sys.exit(1)
else:
print("Success!")
except json.JSONDecodeError:
print("Invalid response from server: ", r.text)
input("Press enter to exit...")
exit(1)
sys.exit(1)

print("Rock and stone!")
input("Press enter to exit...")

0 comments on commit 46a545e

Please sign in to comment.