@@ -15,7 +15,8 @@ Part of the DOMjudge Programming Contest Jury System and licensed
15
15
under the GNU GPL. See README and COPYING for details.
16
16
'''
17
17
18
- from os import listdir
18
+ from argparse import ArgumentParser
19
+ from os import chdir , listdir
19
20
from typing import List
20
21
import json
21
22
import os .path
@@ -30,11 +31,15 @@ import dj_utils
30
31
31
32
cid = None
32
33
34
+ parser = ArgumentParser (description = 'Import a contest archive to DOMjudge via the API.' )
35
+ parser .add_argument ('-d' , '--dir' , help = "directory containing the contest archive, defaults to current directory" )
36
+ parser .add_argument ('-u' , '--url' , help = "DOMjudge API URL to use, if not specified use the CLI interface" )
37
+ args = parser .parse_args ()
33
38
34
- def usage () :
35
- print ( f'Usage: { sys . argv [ 0 ] } [<domjudge-api-url>]' )
36
- exit ( 1 )
37
-
39
+ if args . dir :
40
+ chdir ( args . dir )
41
+ if args . url :
42
+ dj_utils . domjudge_api_url = args . url
38
43
39
44
def import_file (entity : str , files : List [str ]) -> bool :
40
45
any_matched = False
@@ -133,11 +138,6 @@ def import_contest_problemset_document(cid: str):
133
138
else :
134
139
print ('Skipping contest problemset import.' )
135
140
136
- if len (sys .argv ) == 2 :
137
- dj_utils .domjudge_api_url = sys .argv [1 ]
138
- elif len (sys .argv ) != 1 :
139
- usage ()
140
-
141
141
user_data = dj_utils .do_api_request ('user' )
142
142
if 'admin' not in user_data ['roles' ]:
143
143
print ('Your user does not have the \' admin\' role, can not import.' )
0 commit comments