@@ -15,7 +15,8 @@ Part of the DOMjudge Programming Contest Jury System and licensed
1515under the GNU GPL. See README and COPYING for details.
1616'''
1717
18- from os import listdir
18+ from argparse import ArgumentParser
19+ from os import chdir , listdir
1920from typing import List
2021import json
2122import os .path
@@ -30,11 +31,15 @@ import dj_utils
3031
3132cid = None
3233
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 ()
3338
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
3843
3944def import_file (entity : str , files : List [str ]) -> bool :
4045 any_matched = False
@@ -133,11 +138,6 @@ def import_contest_problemset_document(cid: str):
133138 else :
134139 print ('Skipping contest problemset import.' )
135140
136- if len (sys .argv ) == 2 :
137- dj_utils .domjudge_api_url = sys .argv [1 ]
138- elif len (sys .argv ) != 1 :
139- usage ()
140-
141141user_data = dj_utils .do_api_request ('user' )
142142if 'admin' not in user_data ['roles' ]:
143143 print ('Your user does not have the \' admin\' role, can not import.' )
0 commit comments