forked from veluca93/oii-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·376 lines (327 loc) · 14.5 KB
/
setup.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# Contest Management System - http://cms-dev.github.io/
# Copyright © 2010-2013 Giovanni Mascellani <[email protected]>
# Copyright © 2010-2014 Stefano Maggiolo <[email protected]>
# Copyright © 2010-2012 Matteo Boscariol <[email protected]>
# Copyright © 2013 Luca Wehrstedt <[email protected]>
# Copyright © 2014 Artem Iglikov <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Build and installation routines for CMS.
"""
from __future__ import absolute_import
from __future__ import print_function
# setuptools doesn't seem to like this:
# from __future__ import unicode_literals
import sys
import os
import shutil
import re
import pwd
import grp
from glob import glob
from setuptools import setup
# Root directories for the /usr and /var trees.
USR_ROOT = os.path.join("/", "usr", "local")
VAR_ROOT = os.path.join("/", "var", "local")
def do_setup():
"""Execute the setup thanks to setuptools.
"""
old_umask = os.umask(0022)
package_data = {
"cms.io": [
os.path.join("static", "*"),
],
"cms.server": [
os.path.join("static", "jq", "*.*"),
os.path.join("static", "sh", "*.*"),
os.path.join("static", "css", "*.*"),
os.path.join("static", "js", "*.*"),
os.path.join("static", "img", "*.*"),
os.path.join("static", "img", "mimetypes", "*.*"),
os.path.join("static", "*.*"),
os.path.join("templates", "contest", "*.*"),
os.path.join("templates", "admin", "*.*"),
os.path.join("templates", "ranking", "*.*"),
],
"cms.service": [
os.path.join("templates", "printing", "*.*"),
],
"cms.web": [
os.path.join("assets", "css", "*.*"),
os.path.join("assets", "ico", "*.*"),
os.path.join("assets", "js", "*.*"),
os.path.join("assets", "fonts", "*.*"),
os.path.join("assets", "pdfjs", "build", "*.*"),
os.path.join("assets", "pdfjs", "web", "*.*"),
os.path.join("assets", "pdfjs", "web", "images", "*.*"),
os.path.join("assets", "pdfjs", "web", "locale", "*.*"),
os.path.join("assets", "pdfjs", "web", "locale", "en-US", "*.*"),
os.path.join("assets", "pdfjs", "web", "locale", "it", "*.*"),
os.path.join("practice", "*.*"),
os.path.join("practice", "css", "*.*"),
os.path.join("practice", "img", "*.*"),
os.path.join("practice", "js", "*.*"),
os.path.join("practice", "partials", "*.*"),
os.path.join("practice", "views", "*.*"),
os.path.join("admin", "*.*"),
os.path.join("admin", "css", "*.*"),
os.path.join("admin", "img", "*.*"),
os.path.join("admin", "js", "*.*"),
os.path.join("admin", "lib", "jquery", "*.*"),
os.path.join("admin", "lib", "angular", "*.*"),
os.path.join("admin", "lib", "angular-ui", "*.*"),
os.path.join("admin", "lib", "bootstrap", "css", "*.*"),
os.path.join("admin", "lib", "bootstrap", "fonts", "*.*"),
os.path.join("admin", "partials", "*.*"),
os.path.join("admin", "views", "*.*"),
],
"cmsranking": [
os.path.join("static", "img", "*.*"),
os.path.join("static", "lib", "*.*"),
os.path.join("static", "*.*"),
],
"cmstestsuite": [
os.path.join("code", "*.*"),
os.path.join("tasks", "batch_stdio", "data", "*.*"),
os.path.join("tasks", "batch_fileio", "data", "*.*"),
os.path.join("tasks", "batch_fileio_managed", "code", "*"),
os.path.join("tasks", "batch_fileio_managed", "data", "*.*"),
os.path.join("tasks", "communication", "code", "*"),
os.path.join("tasks", "communication", "data", "*.*"),
],
}
# Apparently, pip installs package_data with the permissions they
# have on the source. We fix the source permissions here. (Though,
# pip works on a copy, so no changes happen.)
for package in package_data:
for path in package_data[package]:
for file_ in glob(os.path.join(package.replace(".", "/"), path)):
os.chmod(file_, 0644)
setup(name="cms",
version="1.3.0pre",
author="The CMS development team",
author_email="[email protected]",
url="https://github.com/cms-dev/cms",
download_url="https://github.com/cms-dev/cms/archive/master.tar.gz",
description="A contest management system and grader "
"for IOI-like programming competitions",
packages=["cms",
"cms.db",
"cms.server",
"cms.service",
"cms.io",
"cms.grading",
"cms.grading.scoretypes",
"cms.grading.tasktypes",
"cms.web",
"cmscommon",
"cmsranking",
"cmscontrib",
"cmscontrib.updaters",
"cmstaskenv",
"cmstestsuite",
"cmstestsuite.web",
"cmstestsuite.tasks",
"cmstestsuite.tasks.batch_stdio",
"cmstestsuite.tasks.batch_fileio",
"cmstestsuite.tasks.batch_fileio_managed",
"cmstestsuite.tasks.communication",
"cmscompat"],
package_data=package_data,
scripts=["scripts/cmsLogService",
"scripts/cmsScoringService",
"scripts/cmsEvaluationService",
"scripts/cmsWorker",
"scripts/cmsResourceService",
"scripts/cmsChecker",
"scripts/cmsContestWebServer",
"scripts/cmsAdminWebServer",
"scripts/cmsProxyService",
"scripts/cmsPrintingService",
"scripts/cmsPracticeWebServer",
"scripts/cmsRankingWebServer",
"scripts/cmsInitDB",
"scripts/cmsDropDB"],
entry_points={
"console_scripts": [
"cmsRunTests=cmstestsuite.RunTests:main",
"cmsReplayContest=cmstestsuite.ReplayContest:main",
"cmsAdaptContest=cmstestsuite.AdaptContest:main",
"cmsTestFileCacher=cmstestsuite.TestFileCacher:main",
"cmsAddUser=cmscontrib.AddUser:main",
"cmsRemoveUser=cmscontrib.RemoveUser:main",
"cmsRemoveTask=cmscontrib.RemoveTask:main",
"cmsComputeComplexity=cmscontrib.ComputeComplexity:main",
"cmsTestImporter=cmscontrib.TestImporter:main",
"cmsImporter=cmscontrib.Importer:main",
"cmsReimporter=cmscontrib.Reimporter:main",
"cmsSpoolExporter=cmscontrib.SpoolExporter:main",
"cmsContestExporter=cmscontrib.ContestExporter:main",
"cmsContestImporter=cmscontrib.ContestImporter:main",
"cmsDumpUpdater=cmscontrib.DumpUpdater:main",
"cmsRWSHelper=cmscontrib.RWSHelper:main",
"cmsMake=cmstaskenv.cmsMake:main",
"cmsYamlImporter=cmscompat.YamlImporter:main",
"cmsYamlReimporter=cmscompat.YamlReimporter:main",
]
},
keywords="ioi programming contest grader management system",
license="Affero General Public License v3",
classifiers=[
"Development Status :: 3 - Alpha",
"Natural Language :: English",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 2",
"License :: OSI Approved :: "
"GNU Affero General Public License v3",
])
os.umask(old_umask)
def copyfile(src, dest, owner, perm, group=None):
"""Copy the file src to dest, and assign owner and permissions.
src (string): the complete path of the source file.
dest (string): the complete path of the destination file (i.e.,
not the destination directory).
owner (as given by pwd.getpwnam): the owner we want for dest.
perm (integer): the permission for dest (example: 0660).
group (as given by grp.getgrnam): the group we want for dest; if
not specified, use owner's
group.
"""
shutil.copy(src, dest)
owner_id = owner.pw_uid
if group is not None:
group_id = group.gr_gid
else:
group_id = owner.pw_gid
os.chown(dest, owner_id, group_id)
os.chmod(dest, perm)
def makedir(dir_path, owner=None, perm=None):
"""Create a directory with given owner and permission.
dir_path (string): the new directory to create.
owner (as given by pwd.getpwnam): the owner we want for dest.
perm (integer): the permission for dest (example: 0660).
"""
if not os.path.exists(dir_path):
os.makedirs(dir_path)
if perm is not None:
os.chmod(dir_path, perm)
if owner is not None:
os.chown(dir_path, owner.pw_uid, owner.pw_gid)
def copytree(src_path, dest_path, owner, perm_files, perm_dirs):
"""Copy the *content* of src_path in dest_path, assigning the
given owner and permissions.
src_path (string): the root of the subtree to copy.
dest_path (string): the destination path.
owner (as given by pwd.getpwnam): the owner we want for dest.
perm_files (integer): the permission for copied not-directories.
perm_dirs (integer): the permission for copied directories.
"""
for path in glob(os.path.join(src_path, "*")):
sub_dest = os.path.join(dest_path, os.path.basename(path))
if os.path.isdir(path):
makedir(sub_dest, owner, perm_dirs)
copytree(path, sub_dest, owner, perm_files, perm_dirs)
elif os.path.isfile(path):
copyfile(path, sub_dest, owner, perm_files)
else:
print("Error: unexpected filetype for file %s. Not copied" % path)
def build():
"""This function builds the pieces of CMS that need a compilation
and are not handled by setuptools: isolate, localization files,
pyjamas code for the client of RWS.
"""
print("compiling isolate...")
os.chdir("isolate")
os.system("make")
os.chdir("..")
print("compiling localization files:")
for locale in glob(os.path.join("cms", "server", "po", "*.po")):
country_code = re.search(r"/([^/]*)\.po", locale).groups()[0]
print(" %s" % country_code)
path = os.path.join("cms", "server", "mo", country_code,
"LC_MESSAGES")
makedir(path)
os.system("msgfmt %s -o %s" % (locale, os.path.join(path, "cms.mo")))
print("done.")
def install():
"""Manual installation of files not handled by setuptools: cmsuser
user, isolate, configuration, localization files, static files for
RWS.
"""
# We set permissions for each manually installed files, so we want
# max liberty to change them.
old_umask = os.umask(0000)
print("creating user and group cmsuser.")
os.system("useradd cmsuser -c 'CMS default user' -M -r -s /bin/false -U")
cmsuser = pwd.getpwnam("cmsuser")
root = pwd.getpwnam("root")
cmsuser_grp = grp.getgrnam("cmsuser")
print("copying isolate to /usr/local/bin/.")
makedir(os.path.join(USR_ROOT, "bin"), root, 0755)
copyfile(os.path.join(".", "isolate", "isolate"),
os.path.join(USR_ROOT, "bin", "isolate"),
root, 04750, group=cmsuser_grp)
print("copying configuration to /usr/local/etc/.")
makedir(os.path.join(USR_ROOT, "etc"), root, 0755)
for conf_file_name in ["cms.conf", "cms.ranking.conf"]:
conf_file = os.path.join(USR_ROOT, "etc", conf_file_name)
# Skip if destination is a symlink
if os.path.islink(conf_file):
continue
if os.path.exists(os.path.join(".", "config", conf_file_name)):
copyfile(os.path.join(".", "config", conf_file_name),
conf_file, cmsuser, 0660)
else:
conf_file_name = "%s.sample" % conf_file_name
copyfile(os.path.join(".", "config", conf_file_name),
conf_file, cmsuser, 0660)
print("copying localization files:")
for locale in glob(os.path.join("cms", "server", "po", "*.po")):
country_code = re.search(r"/([^/]*)\.po", locale).groups()[0]
print(" %s" % country_code)
path = os.path.join("cms", "server", "mo", country_code, "LC_MESSAGES")
dest_path = os.path.join(USR_ROOT, "share", "locale",
country_code, "LC_MESSAGES")
makedir(dest_path, root, 0755)
copyfile(os.path.join(path, "cms.mo"),
os.path.join(dest_path, "cms.mo"),
root, 0644)
print("creating directories.")
dirs = [os.path.join(VAR_ROOT, "log"),
os.path.join(VAR_ROOT, "cache"),
os.path.join(VAR_ROOT, "lib"),
os.path.join(VAR_ROOT, "run"),
os.path.join(USR_ROOT, "include"),
os.path.join(USR_ROOT, "share")]
for _dir in dirs:
# Skip if destination is a symlink
if os.path.islink(os.path.join(_dir, "cms")):
continue
makedir(_dir, root, 0755)
_dir = os.path.join(_dir, "cms")
makedir(_dir, cmsuser, 0770)
print("copying Polygon testlib:")
path = os.path.join("cmscontrib", "polygon", "testlib.h")
dest_path = os.path.join(USR_ROOT, "include", "cms", "testlib.h")
copyfile(path, dest_path, root, 0644)
os.umask(old_umask)
print("done.")
if __name__ == "__main__":
do_setup()
if "build" in sys.argv:
build()
if "install" in sys.argv:
install()