1616_myself = os.path.basename(sys.argv[0])
1717_default_user_agent = requests.utils.default_user_agent()
1818headers = {'user-agent': f'dj_utils/{_myself} ({_default_user_agent})'}
19- domjudge_webapp_folder_or_api_url = 'unset'
19+ domjudge_webapp_dir = '@domserver_webappdir@'
20+ domjudge_api_url = None
2021ca_check = True
2122
2223
@@ -50,8 +51,8 @@ def parse_api_response(name: str, response: requests.Response) -> bytes:
5051def do_api_request(name: str, method: str = 'GET', jsonData: dict = {}, decode: bool = True):
5152 '''Perform an API call to the given endpoint and return its data.
5253
53- Based on whether `domjudge_webapp_folder_or_api_url ` is a folder or URL this
54- will use the DOMjudge CLI or HTTP API .
54+ Based on whether `domjudge_api_url ` is set, this will call the DOMjudge
55+ API via HTTP or CLI .
5556
5657 Parameters:
5758 name (str): the endpoint to call
@@ -67,12 +68,12 @@ def do_api_request(name: str, method: str = 'GET', jsonData: dict = {}, decode:
6768 cannot be JSON decoded.
6869 '''
6970
70- if os . path . isdir ( domjudge_webapp_folder_or_api_url ) :
71+ if domjudge_api_url is None :
7172 result = api_via_cli(name, method, {}, {}, jsonData)
7273 else:
7374 global ca_check
74- url = f'{ domjudge_webapp_folder_or_api_url } /{ name } '
75- parsed = urlparse (domjudge_webapp_folder_or_api_url )
75+ url = f'{domjudge_api_url }/{name}'
76+ parsed = urlparse(domjudge_api_url )
7677 auth = None
7778 if parsed.username and parsed.password:
7879 auth = (parsed.username, parsed.password)
@@ -109,8 +110,8 @@ def do_api_request(name: str, method: str = 'GET', jsonData: dict = {}, decode:
109110def upload_file(name: str, apifilename: str, file: str, data: dict = {}):
110111 '''Upload the given file to the API at the given path with the given name.
111112
112- Based on whether `domjudge_webapp_folder_or_api_url ` is a folder or URL this
113- will use the DOMjudge CLI or HTTP API .
113+ Based on whether `domjudge_api_url ` is set, this will call the DOMjudge
114+ API via HTTP or CLI .
114115
115116 Parameters:
116117 name (str): the endpoint to call
@@ -124,13 +125,13 @@ def upload_file(name: str, apifilename: str, file: str, data: dict = {}):
124125 RuntimeError when the HTTP status code is non 2xx.
125126 '''
126127
127- if os . path . isdir ( domjudge_webapp_folder_or_api_url ) :
128+ if domjudge_api_url is None :
128129 response = api_via_cli(name, 'POST', data, {apifilename: file})
129130 else:
130131 global ca_check
131132 files = [(apifilename, open(file, 'rb'))]
132133
133- url = f'{ domjudge_webapp_folder_or_api_url } /{ name } '
134+ url = f'{domjudge_api_url }/{name}'
134135
135136 try:
136137 response = requests.post(
@@ -166,7 +167,7 @@ def api_via_cli(name: str, method: str = 'GET', data: dict = {}, files: dict = {
166167 '''
167168
168169 command = [
169- f'{ domjudge_webapp_folder_or_api_url } /bin/console' ,
170+ f'{domjudge_webapp_dir }/bin/console',
170171 'api:call',
171172 '-m',
172173 method
0 commit comments