Files
bitoj_python/utils/bitoj_adduser
2025-10-11 11:23:58 +08:00

56 lines
1.3 KiB
Python
Executable File

#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
这个程序用来向系统中添加帐号。这些帐号会在 bitoj 中使用,用户提交的程序会以
不同的用户帐号执行。
"""
import os, sys, string
rundir = '/var/lib/bitoj'
def usage(message = None):
if message:
print message
print "Usage: bitoj_adduser minnum maxnum"
def adduser(usernum):
global rundir
username = 'ojrun%02d' % usernum
homedir = os.path.join(rundir, username)
cmd = 'adduser --system --group --disabled-login --home %s %s' \
% (homedir, username)
if os.system(cmd) == 0:
os.system('adduser oj %s' % username)
os.system('adduser %s oj' % username)
os.system('chmod g+w %s' % homedir)
os.system('setquota -u %s 25600 25600 1000 1000 /' % username)
def main():
if len(sys.argv) < 3:
usage()
sys.exit(1)
minnum = string.atoi(sys.argv[1])
maxnum = string.atoi(sys.argv[2])
if minnum > maxnum:
usage("minnum should be small than maxnum")
sys.exit(1)
if minnum < 1 or maxnum > 100:
usage("minnum should between 1 and 100")
sys.exit(1)
if maxnum < 1 or maxnum > 100:
usage("maxnum should between 1 and 100")
sys.exit(1)
for i in range(minnum, maxnum + 1):
adduser(i)
main()