-
Notifications
You must be signed in to change notification settings - Fork 5
/
uploadcontests.py
executable file
·81 lines (70 loc) · 2.96 KB
/
uploadcontests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/python3
import argparse
import datetime
import logging
import os
import contests
import omegaup.api
import repository
def _main() -> None:
env = os.environ
parser = argparse.ArgumentParser(description="Upsert contests to OmegaUp")
parser.add_argument('--ci',
action='store_true',
help='Signal that this is being run from the CI.')
parser.add_argument(
'--all',
action='store_true',
help='Upsert all contests, instead of only those that have changed')
parser.add_argument('--verbose',
action='store_true',
help='Verbose logging')
parser.add_argument('--url',
default='https://omegaup.com',
help='URL of the omegaUp host.')
parser.add_argument('--api-token',
type=str,
default=env.get('OMEGAUP_API_TOKEN'))
parser.add_argument('-u',
'--username',
type=str,
default=env.get('OMEGAUPUSER'),
required=('OMEGAUPUSER' not in env
and 'OMEGAUP_API_TOKEN' not in env))
parser.add_argument('-p',
'--password',
type=str,
default=env.get('OMEGAUPPASS'),
required=('OMEGAUPPASS' not in env
and 'OMEGAUP_API_TOKEN' not in env))
parser.add_argument('--can-create',
action='store_true',
help=("Whether it's allowable to create the "
"contest if it does not exist."))
parser.add_argument("--timeout",
type=int,
default=60,
help="Timeout for deploy API call (in seconds)")
parser.add_argument('contest_paths',
metavar='PROBLEM',
type=str,
nargs='*')
args = parser.parse_args()
logging.basicConfig(format='%(asctime)s: %(message)s',
level=logging.DEBUG if args.verbose else logging.INFO)
logging.getLogger('urllib3').setLevel(logging.CRITICAL)
client = omegaup.api.Client(username=args.username,
password=args.password,
api_token=args.api_token,
url=args.url)
rootDirectory = repository.repositoryRoot()
for contest in contests.contests(allContests=args.all,
rootDirectory=rootDirectory,
contestPaths=args.contest_paths):
contests.upsertContest(
client,
os.path.join(rootDirectory, contest.path),
canCreate=args.can_create,
timeout=datetime.timedelta(seconds=args.timeout))
if __name__ == '__main__':
_main()