def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser(description="Add a participation to CMS.") parser.add_argument("username", action="store", type=utf8_decoder, help="username to add to the contest") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of the contest the users will be attached to") parser.add_argument("-i", "--ip", action="store", type=utf8_decoder, help="ip address of this user") parser.add_argument("-d", "--delay_time", action="store", type=int, help="how much the contest is shifted, in seconds") parser.add_argument("-e", "--extra_time", action="store", type=int, help="how much additional time, in seconds") parser.add_argument("-p", "--password", action="store", type=utf8_decoder, help="how much additional time, in seconds") parser.add_argument("-t", "--team", action="store", type=utf8_decoder, help="code of the team for this participation") parser.add_argument("-n", "--hidden", action="store_true", help="if the participation is hidden") parser.add_argument("-u", "--unrestricted", action="store_true", help="if the participation is unrestricted") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() success = add_participation(args.username, args.contest_id, args.ip, args.delay_time, args.extra_time, args.password, args.team, args.hidden, args.unrestricted) return 0 if success is True else 1
def main(): """Parse arguments and launch process.""" parser = argparse.ArgumentParser(description="Exporter of CMS contests.") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of contest to export") group = parser.add_mutually_exclusive_group() group.add_argument("-f", "--files", action="store_true", help="only export files, ignore database structure") group.add_argument("-F", "--no-files", action="store_true", help="only export database structure, ignore files") parser.add_argument("-l", "--light", action="store_true", help="light export (without testcases and " "automatically generated files)") parser.add_argument("-S", "--no-submissions", action="store_true", help="don't export submissions") parser.add_argument("-U", "--no-user-tests", action="store_true", help="don't export user tests") parser.add_argument("export_target", nargs='?', default="", help="target directory or archive for export") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() ContestExporter(contest_id=args.contest_id, export_target=args.export_target, dump_files=not args.no_files, dump_model=not args.files, light=args.light, skip_submissions=args.no_submissions, skip_user_tests=args.no_user_tests).do_export()
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser( description="Load a contest from the Italian repository " "over an old one in CMS.") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of contest to overwrite") parser.add_argument("-f", "--force", action="store_true", help="force the reimport even if some users or tasks " "may get lost") parser.add_argument("import_directory", help="source directory from where import") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() YamlReimporter(path=args.import_directory, contest_id=args.contest_id, force=args.force).run()
def main(): """Parse arguments and launch process.""" parser = argparse.ArgumentParser( description="Reimport a contest from disk", epilog=build_epilog(), formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of contest to overwrite") parser.add_argument("-f", "--force", action="store_true", help="force the reimport even if some users or tasks " "may get lost") parser.add_argument("-L", "--loader", action="store", default=None, help="use the specified loader (default: autodetect)") parser.add_argument("-F", "--full", action="store_true", help="reimport tasks even if they haven't changed") parser.add_argument("import_directory", help="source directory from where import") args = parser.parse_args() loader_class = choose_loader(args.loader, args.import_directory, parser.error) if args.contest_id is None: args.contest_id = ask_for_contest() Reimporter(path=args.import_directory, contest_id=args.contest_id, force=args.force, loader_class=loader_class, full=args.full).do_reimport()
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser(description="Add a participation to CMS.") parser.add_argument("username", action="store", type=utf8_decoder, help="username to add to the contest") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of the contest the users will be attached to") parser.add_argument("-i", "--ip", action="store", type=utf8_decoder, help="ip address of this user") parser.add_argument("-d", "--delay_time", action="store", type=int, help="how much the contest is shifted, in seconds") parser.add_argument("-e", "--extra_time", action="store", type=int, help="how much additional time, in seconds") parser.add_argument("-p", "--password", action="store", type=utf8_decoder, help="how much additional time, in seconds") parser.add_argument("-t", "--team", action="store", type=utf8_decoder, help="code of the team for this participation") parser.add_argument("--hidden", action="store_true", help="if the participation is hidden") parser.add_argument("--unrestricted", action="store_true", help="if the participation is unrestricted") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() success = add_participation(args.username, args.contest_id, args.ip, args.delay_time, args.extra_time, args.password, args.team, args.hidden, args.unrestricted) return 0 if success is True else 1
def main(): """Parse arguments and launch process.""" parser = argparse.ArgumentParser(description="Exporter of CMS contests.") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of contest to export") group = parser.add_mutually_exclusive_group() group.add_argument("-f", "--files", action="store_true", help="only export files, ignore database structure") group.add_argument("-F", "--no-files", action="store_true", help="only export database structure, ignore files") parser.add_argument("-G", "--no-generated", action="store_true", help="don't export data and files that can be " "automatically generated") parser.add_argument("-S", "--no-submissions", action="store_true", help="don't export submissions") parser.add_argument("-U", "--no-user-tests", action="store_true", help="don't export user tests") parser.add_argument("export_target", nargs='?', default="", help="target directory or archive for export") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() ContestExporter(contest_id=args.contest_id, export_target=args.export_target, dump_files=not args.no_files, dump_model=not args.files, skip_generated=args.no_generated, skip_submissions=args.no_submissions, skip_user_tests=args.no_user_tests).do_export()
def main(): """Parses arguments and launch service. """ parser = argparse.ArgumentParser( description="Resource monitor and service starter for CMS.") parser.add_argument("-a", "--autorestart", metavar="CONTEST_ID", help="restart automatically services on its machine", nargs="?", type=int, const=-1) parser.add_argument("shard", type=int, nargs="?", default=-1) args = parser.parse_args() # If the shard is -1 (i.e., unspecified) we find it basing on the # local IP addresses if args.shard == -1: addrs = find_local_addresses() args.shard = get_shard_from_addresses("ResourceService", addrs) if args.autorestart is not None: if args.autorestart == -1: ResourceService(args.shard, contest_id=ask_for_contest()).run() else: if is_contest_id(args.autorestart): ResourceService(args.shard, contest_id=args.autorestart).run() else: import sys print >> sys.stderr, "There is no contest " \ "with the specified id. Please try again." sys.exit(1) else: ResourceService(args.shard).run()
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser(description="Exporter of CMS contests.") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of contest to export") parser.add_argument("-s", "--skip-submissions", action="store_true", help="don't export submissions, only contest data") parser.add_argument("-t", "--skip-user-tests", action="store_true", help="don't export user tests, only contest data") parser.add_argument("-l", "--light", action="store_true", help="light export (without executables and " "testcases)") parser.add_argument("export_target", nargs='?', default="", help="target directory or archive for export") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() ContestExporter(contest_id=args.contest_id, export_target=args.export_target, skip_submissions=args.skip_submissions, skip_user_tests=args.skip_user_tests, light=args.light).run()
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser(description="Adds a user to a contest in CMS.") parser.add_argument("first_name", help="first name of the user") parser.add_argument("last_name", help="last name of the user") parser.add_argument("username", help="username of the user") parser.add_argument("-c", "--contest-id", help="id of contest where to add the user", action="store", type=int) parser.add_argument("-p", "--password", help="password of the user", action="store") parser.add_argument("-i", "--ip-address", help="ip address of the user", action="store") parser.add_argument("-e", "--email", help="email address of the user", action="store") parser.add_argument("-H", "--hidden", help="if the user is hidden", action="store_true") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() add_user( contest_id=args.contest_id, first_name=args.first_name, last_name=args.last_name, username=args.username, password=args.password, ip_address=args.ip_address, email=args.email, hidden=args.hidden, ) return 0
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser(description="Exporter of CMS contests.") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of contest to export") parser.add_argument("-d", "--dump-database", action="store_true", help="include a SQL dump of the database (this will " "disclose data about other contests stored in the " "same database) - deprecated") parser.add_argument("-s", "--skip-submissions", action="store_true", help="don't export submissions, only contest data") parser.add_argument("-l", "--light", action="store_true", help="light export (without executables and " "testcases)") parser.add_argument("export_target", nargs='?', default="", help="target directory or archive for export") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() ContestExporter(contest_id=args.contest_id, dump=args.dump_database, export_target=args.export_target, skip_submissions=args.skip_submissions, light=args.light).run()
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser( description="Adds a user to a contest in CMS.") parser.add_argument("first_name", action="store", type=utf8_decoder, help="first name of the user") parser.add_argument("last_name", action="store", type=utf8_decoder, help="last name of the user") parser.add_argument("username", action="store", type=utf8_decoder, help="username of the user") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of contest where to add the user") parser.add_argument("-p", "--password", action="store", type=utf8_decoder, help="password of the user") parser.add_argument("-i", "--ip-address", action="store", type=utf8_decoder, help="ip address of the user") parser.add_argument("-e", "--email", action="store", type=utf8_decoder, help="email address of the user") parser.add_argument("-H", "--hidden", action="store_true", help="if the user is hidden") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() add_user(contest_id=args.contest_id, first_name=args.first_name, last_name=args.last_name, username=args.username, password=args.password, ip_address=args.ip_address, email=args.email, hidden=args.hidden) return 0
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser( description="Remove one or more submissions.") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of contest the user is in") parser.add_argument("-u", "--username", action="store", type=utf8_decoder, help="username of the user") parser.add_argument("-t", "--task_name", action="store", type=utf8_decoder, help="short name of the task") parser.add_argument("-s", "--submission_id", action="store", type=utf8_decoder, help="submission id") args = parser.parse_args() # We have a submission id, we do not need anything else. if args.submission_id is not None: if args.contest_id is not None \ or args.username is not None or args.task_name is not None: print("Submission id require no other parameters.") return 1 remove_submission(args.submission_id) return 0 # Otherwise, it's either user or task, but not both. if args.username is not None and args.task_name is not None: print("Cannot set both task and user.") return 1 elif args.username is None and args.task_name is None: print("Please set some filter.") return 1 # In any case, we require a contest. if args.contest_id is None: args.contest_id = ask_for_contest() if args.username is not None: remove_submissions_for_user(contest_id=args.contest_id, username=args.username) elif args.task_name is not None: remove_submissions_for_task(contest_id=args.contest_id, task_name=args.task_name) return 0
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser(description="Add a participation to CMS.") parser.add_argument("username", action="store", type=utf8_decoder, help="username to add to the contest") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of the contest the users will be attached to") parser.add_argument("-i", "--ip", action="store", type=utf8_decoder, help="ip address of this user") parser.add_argument("-d", "--delay_time", action="store", type=int, help="how much the contest is shifted, in seconds") parser.add_argument("-e", "--extra_time", action="store", type=int, help="how much additional time, in seconds") parser.add_argument("-t", "--team", action="store", type=utf8_decoder, help="code of the team for this participation") parser.add_argument("--hidden", action="store_true", help="if the participation is hidden") parser.add_argument("--unrestricted", action="store_true", help="if the participation is unrestricted") parser.add_argument("-g", "--group", action="store", type=utf8_decoder, help="name of the group to use") password_group = parser.add_mutually_exclusive_group() password_group.add_argument( "-p", "--plaintext-password", action="store", type=utf8_decoder, help="password of the user in plain text") password_group.add_argument( "-H", "--hashed-password", action="store", type=utf8_decoder, help="password of the user, already hashed using the given algorithm " "(currently only --bcrypt)") method_group = parser.add_mutually_exclusive_group() method_group.add_argument( "--bcrypt", dest="method", action="store_const", const="bcrypt", help="whether the password will be stored in bcrypt-hashed format " "(if omitted it will be stored in plain text)") args = parser.parse_args() if args.hashed_password is not None and args.method is None: parser.error("hashed password given but no method specified") if args.contest_id is None: args.contest_id = ask_for_contest() success = add_participation( args.username, args.contest_id, args.ip, args.delay_time, args.extra_time, args.plaintext_password or args.hashed_password, args.method or "plaintext", args.hashed_password is not None, args.team, args.hidden, args.unrestricted, args.group) return 0 if success is True else 1
def main(): """Parse arguments and launch process. return (int): exit code of the program. """ parser = argparse.ArgumentParser( description="Adds a submission to a contest in CMS.") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of contest where to add the user") parser.add_argument("-f", "--file", action="append", type=utf8_decoder, help="in the form <name>:<file>, where name is the " "name as required by CMS, and file is the name of " "the file in the filesystem - may be specified " "multiple times", required=True) parser.add_argument("username", action="store", type=utf8_decoder, help="user doing the submission") parser.add_argument("task_name", action="store", type=utf8_decoder, help="name of task the submission is for") parser.add_argument("-t", "--timestamp", action="store", type=int, help="timestamp of the submission in seconds from " "epoch, e.g. `date +%%s` (now if not set)") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() if args.timestamp is None: import time args.timestamp = time.time() split_files = [file_.split(":", 1) for file_ in args.file] if any(len(file_) != 2 for file_ in split_files): parser.error("Invalid value for the file argument: format is " "<name>:<file>.") return 1 files = {} for name, filename in split_files: if name in files: parser.error("Duplicate assignment for file `%s'." % name) return 1 files[name] = filename if add_submission(contest_id=args.contest_id, username=args.username, task_name=args.task_name, timestamp=args.timestamp, files=files): return 0 else: return 1
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser(description="Exporter for the Italian repository for CMS.") parser.add_argument("-c", "--contest-id", help="id of contest to export", action="store", type=int) parser.add_argument("export_directory", help="target directory where to export") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() SpoolExporter(contest_id=args.contest_id, spool_dir=args.export_directory).run()
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser(description="Add a participation to CMS.") parser.add_argument("username", action="store", type=utf8_decoder, help="username to add to the contest") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of the contest the users will be attached to") parser.add_argument("-i", "--ip", action="store", type=utf8_decoder, help="ip address of this user") parser.add_argument("-d", "--delay_time", action="store", type=int, help="how much the contest is shifted, in seconds") parser.add_argument("-e", "--extra_time", action="store", type=int, help="how much additional time, in seconds") parser.add_argument("-t", "--team", action="store", type=utf8_decoder, help="code of the team for this participation") parser.add_argument("--hidden", action="store_true", help="if the participation is hidden") parser.add_argument("--unrestricted", action="store_true", help="if the participation is unrestricted") password_group = parser.add_mutually_exclusive_group() password_group.add_argument( "-p", "--plaintext-password", action="store", type=utf8_decoder, help="password of the user in plain text") password_group.add_argument( "-H", "--hashed-password", action="store", type=utf8_decoder, help="password of the user, already hashed using the given algorithm " "(currently only --bcrypt)") method_group = parser.add_mutually_exclusive_group() method_group.add_argument( "--bcrypt", dest="method", action="store_const", const="bcrypt", help="whether the password will be stored in bcrypt-hashed format " "(if omitted it will be stored in plain text)") args = parser.parse_args() if args.hashed_password is not None and args.method is None: parser.error("hashed password given but no method specified") if args.contest_id is None: args.contest_id = ask_for_contest() success = add_participation( args.username, args.contest_id, args.ip, args.delay_time, args.extra_time, args.plaintext_password or args.hashed_password, args.method or "plaintext", args.hashed_password is not None, args.team, args.hidden, args.unrestricted) return 0 if success is True else 1
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser( description="Remove a contest from CMS.") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of the contest") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() remove_contest(contest_id=args.contest_id)
def main(): """Parse arguments and launch process.""" parser = argparse.ArgumentParser( description="Reimport a contest from disk", epilog=build_epilog(), formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of contest to overwrite") parser.add_argument("-f", "--force", action="store_true", help="force the reimport even if some users or tasks " "may get lost") parser.add_argument("-u", "--users", action="store_true", help="(re)load the users from the .yaml file") parser.add_argument("-L", "--loader", action="store", type=utf8_decoder, default=None, help="use the specified loader (default: autodetect)") parser.add_argument("-F", "--full", action="store_true", help="reimport tasks even if they haven't changed") parser.add_argument("import_directory", action="store", type=utf8_decoder, help="source directory from where import") args = parser.parse_args() loader_class = choose_loader(args.loader, args.import_directory, parser.error) if args.contest_id is None: args.contest_id = ask_for_contest() Reimporter(path=args.import_directory, contest_id=args.contest_id, force=args.force, loader_class=loader_class, full=args.full, users=args.users).do_reimport()
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser(description="Remove a contest from CMS.") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of the contest") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() remove_contest(contest_id=args.contest_id)
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser( description="Remove a participation from a contest in CMS.") parser.add_argument("username", action="store", type=utf8_decoder, help="username of the user") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of contest the user is in") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() return remove_participation(contest_id=args.contest_id, username=args.username)
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser( description="Remove a participation from a contest in CMS.") parser.add_argument("username", action="store", type=utf8_decoder, help="username of the user") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of contest the user is in") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() success = remove_participation(contest_id=args.contest_id, username=args.username) return 0 if success is True else 1
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser( description="Remove a task from a contest in CMS.") parser.add_argument("task_name", help="short name of the task") parser.add_argument("-c", "--contest-id", help="id of contest the task is in", action="store", type=int) args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() remove_task(contest_id=args.contest_id, task_name=args.task_name) return 0
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser( description="Load a contest from the Italian repository " "over an old one in CMS.") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of contest to overwrite") parser.add_argument("import_directory", help="source directory from where import") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() YamlReimporter(path=args.import_directory, contest_id=args.contest_id).run()
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser( description="Exporter for the Italian repository for CMS.") parser.add_argument("-c", "--contest-id", help="id of contest to export", action="store", type=int) parser.add_argument("export_directory", help="target directory where to export") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() SpoolExporter(contest_id=args.contest_id, spool_dir=args.export_directory).run()
def main(): """Parse arguments and launch process.""" parser = argparse.ArgumentParser( description="Reimport a contest from disk using YamlLoader") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of contest to overwrite") parser.add_argument("-f", "--force", action="store_true", help="force the reimport even if some users or tasks " "may get lost") parser.add_argument("import_directory", help="source directory from where import") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() Reimporter(path=args.import_directory, contest_id=args.contest_id, force=args.force).do_reimport()
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser( description="Add a participation for every user to CMS.") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of the contest the users will be attached to") parser.add_argument("-g", "--group", action="store", type=utf8_decoder, help="name of the group to use") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() success = add_participations(args.contest_id, args.group) return 0 if success is True else 1
import os, argparse from cms.db import ask_for_contest parser = argparse.ArgumentParser(description='Add user') parser.add_argument('users', help='path to the users.txt') args = parser.parse_args() contest_id = ask_for_contest() with open(args.users, 'r') as f: users = f.read().split("\n") for u in users: u = u.strip() if len(u) == 0: continue if " " in u: user, password = u.split() else: user, password = u, u print "Add user {} with password {}".format(user, password) os.system("cmsAddUser '' {} {} &>/dev/null".format(user, user)) os.system("cmsAddParticipation -c {} -p {} {} &>/dev/null".format( contest_id, user, password))
def main(): """Parse arguments and launch process. """ parser = argparse.ArgumentParser(description="Replay a contest in CMS.") parser.add_argument("-c", "--contest-id", action="store", type=int, help="id of the contest") parser.add_argument("-t", "--task-id", action="store", type=int, help="id of task (default: all tasks)") parser.add_argument("-u", "--user-id", action="store", type=int, help="id of user (default: all users)") parser.add_argument("-sid", "--submission-id", action="store", type=int, help="id of submission (default: all submissions)") parser.add_argument("--cws_address", action="store", type=utf8_decoder, default="http://127.0.0.1:8888", help="http address of CWS") parser.add_argument("-r", "--resume", action="store", type=utf8_decoder, help="start from (%%H:%%M:%%S)") parser.add_argument("-d", "--duration", action="store", type=utf8_decoder, help="duration is (%%H:%%M:%%S)") parser.add_argument("-s", "--speed", action="store", type=int, default=1, help="speed of replaying") args = parser.parse_args() if args.contest_id is None: args.contest_id = ask_for_contest() start_from = 0 if args.resume is not None: try: h, m, s = args.resume.split(':') start_from = int(h) * 3600 + int(m) * 60 + int(s) except: msg = "Invalid resume time %s, format is %%H:%%M:%%S" % args.resume logger.critical(msg) return 1 duration = None if args.duration is not None: try: h, m, s = args.duration.split(':') duration = int(h) * 3600 + int(m) * 60 + int(s) except: msg = "Invalid duration %s, format is %%H:%%M:%%S" % args.duration logger.critical(msg) return 1 success = replay_contest(contest_id=args.contest_id, start_from=start_from, duration=duration, cws_address=args.cws_address, speed=args.speed, task_id=args.task_id, user_id=args.user_id, submission_id=args.submission_id) return 0 if success is True else 1