oioioi.sinolpack.package
¶
Module Contents¶
Classes¶
Responsible for packing SinolPackages. |
|
Backend that use |
Functions¶
|
|
|
|
|
|
|
|
|
Removes files from zip file by creating new zip file with all |
Attributes¶
- oioioi.sinolpack.package._remove_from_zip(zipfname, *filenames)[source]¶
Removes files from zip file by creating new zip file with all the files except the files to remove. Then the old file is removed. It has to be done like this because zipfile module doesn’t implement function to delete file.
- class oioioi.sinolpack.package.SinolPackage(path, original_filename=None)[source]¶
Bases:
object
- _find_main_dir()[source]¶
Looks for the directory which contains at least the in/ and out/ subdirectories. Only one such directory should be found. Otherwise None is returned.
- _process_config_yml()[source]¶
Parses the
config.yml
file from the package.Extracted information is then saved for later use.
- _detect_full_name()[source]¶
Sets the problem’s full name from the
config.yml
(keytitle
) or from thetitle
tag in the LaTeX source file. Theconfig.yml
file takes precedence over the LaTeX source.- Example of how the
title
tag may look like: itle{A problem}
- Example of how the
- _detect_full_name_translations()[source]¶
Creates problem’s full name translations from the
config.yml
(keys matching the patterntitle_[a-z]{2}
, where[a-z]{2}
represents two-letter language code defined insettings.py
), if any such key is given.
- _detect_library()[source]¶
Finds if the problem has a library defined in
config.yml
.Tries to read a library name (filename library should be given during compilation) from the
config.yml
(keylibrary
).If there is no such key, assumes that a library is not needed.
- _find_and_save_files(files)[source]¶
Saves files in the database.
- Parameters
files – List of expected files.
- Returns
List of files that were not found.
- _process_statements()[source]¶
Creates a problem statement from html or pdf source.
If USE_SINOLPACK_MAKEFILES is set to True in the OIOIOI settings, the pdf file will be compiled from a LaTeX source.
- _force_index_encoding(htmlzipfile)[source]¶
Ensures index.html file is utf-8 encoded, if cannot apply this encoding raise
ProblemPackageError
.
- _generate_tests(total_score_if_auto=100)[source]¶
Generates tests for the problem.
First, time and memory limits are obtained from
config.yml
. Then, the judge system attempts to obtain a generic memory limit from the problem statement.Next, test instances are created, using input files (
*.in
) provided with the package and ingen (the input file generator) where applicable (ingen
-generated tests may replace*.in
files contained in the package if their respective names coincide).If USE_SINOLPACK_MAKEFILES is set to True in the OIOIOI settings, output files (
*.out
) will also be generated at this point, based on the model solution’s output (on condition that its source code is included within the package).The next step is veryfing whether the sum of time limits over all tests does not exceed the maximum defined by the OIOIOI installation’s owner.
If an input verifier is provided, it will then assert that all
*.in
files generated are valid, and abort the upload in case of failure.Here the
*.out
files will be generated if USE_SINOLPACK_MAKEFILES is set to False, based on the model solution’s output (on condition that its source code is included within the package).In the end, it is asserted that all tests have been correctly constructed, non-created tests are removed from the database and test scores are assigned to tests and testgroups based on the configuration from
config.yml
or set to default value if not specified.
- _detect_statement_memory_limit()[source]¶
Returns the memory limit in the problem statement, converted to KiB or
None
.
- _create_instances_for_tests()[source]¶
Iterate through available test inputs. :return: Triple (created tests instances,
outs that have to be generated, score groups (determined by test names))
- _verify_time_limits(time_limit_sum)[source]¶
Checks whether the sum of test time limits does not exceed the allowed maximum.
- Raises
if sum of tests time limits exceeds the maximum defined in the settings.py file.
- _validate_tests(created_tests)[source]¶
Checks if all tests have output files and that all tests have been successfully created.
- Raises
- _process_test(test, order, names_re, indir, outdir, collected_ins, scored_groups, outs_to_make)[source]¶
Responsible for saving test in and out files, setting test limits, assigning test kinds and groups.
- Parameters
test – Test name.
order – Test number.
names_re – Compiled regex to match test details from name. Should extract basename, test name, group number and test type.
indir – Directory with tests inputs.
outdir – Directory with tests outputs.
collected_ins – List of inputs that were generated, not taken from archive as a file.
scored_groups – Accumulator for score groups.
outs_to_make – Accumulator for name of output files to be generated by model solution.
- Returns
Test instance or None if name couldn’t be matched.
- _get_memory_limit(created, name, group)[source]¶
If we find the memory limit specified anywhere in the package: either in the
config.yml
or in the problem statement then we overwrite potential manual changes.(In the future we should disallow editing memory limits if they were taken from the package).
The memory limit is more important the more specific it is. In particular, the global memory limit is less important than the memory limit for a test group, while the memory limit for particular test is the most imporant. :return: Memory limit found in config or statement,
None otherwise.
- _get_time_limit(created, name, group)[source]¶
If we find the time limit specified anywhere in in the
config.yml
then we overwrite potential manual changes.The time limit is more important the more specific it is. In particular, the global time limit is less important than the time limit for a test group, while the time limit for particular test is the most imporant. :return: Time limit found in config, None otherwise.
- _make_outs(outs_to_make)[source]¶
Compiles the model solution and executes it in order to generate test outputs.
- Returns
Result from workers.
- _check_scores_from_config(scored_groups, config_scores)[source]¶
Called if
config.yml
specifies scores for any tests. Makes sure that all scored tests are present inconfig.yml
and that nothing else is there.
- _compute_scores_automatically(scored_groups, total_score)[source]¶
If there are no testscores specified
config.yml
, all groups get equal score, except few last groups that are given +1 to compensate rounding error and match the total sum oftotal_score
.
- _assign_scores(scored_groups, total_score_if_auto)[source]¶
Checks if there’s a
scores
entry in config and sets scores according to that or assigns them automatically otherwise.
- _process_language_override()[source]¶
Checks if there’s a override_limits entry in config and for existing tests, add additional limits overrides. Time limits are validated the same way it’s validated in default package.
- _prepare_overrides(lang)[source]¶
Prepares overrides for specified language, initially setting to default limits.
- _set_memory_limit_overrides(lang, rules)[source]¶
Sets memory limits overrides for specific language.
- _get_model_solutions_sources()[source]¶
- Returns
Sources as tuples (kind_of_solution, filename,
full path to file).
- _process_attachments()[source]¶
Removes previously added attachments for the problem, and saves new ones from the attachment directory.
- class oioioi.sinolpack.package.SinolPackageCreator(problem)[source]¶
Bases:
object
Responsible for packing SinolPackages.
- pack()[source]¶
- Returns
Archive from original package if such file exists,
otherwise new archive with test, statements and model solutions.
- class oioioi.sinolpack.package.SinolPackageBackend[source]¶
Bases:
oioioi.problems.package.ProblemPackageBackend
Backend that use
SinolPackage
to unpack andSinolPackageCreator
to pack sinol packages.- identify(path, original_filename=None)[source]¶
Checks if the backend is suitable for processing the specified problem package.
- Parameters
path – a path to the processed problem package
original_filename – the name of the package specified by the
uploading user.
Returns
True
if the backend can handle the specified problem package file.
- get_short_name(path, original_filename=None)[source]¶
Returns the problem’s short name.
- Parameters
path – a path to the processed problem package
original_filename – the name of the package specified by the
uploading user.
- unpack(env)[source]¶
Processes a package, creating a new
Problem
or updating an existing one.This function will be called either from
unpackmgr_job()
(Celery task) or fromsimple_unpack()
(e.g. when a problem is added from a command line).- Used
env
keys: package_id
: an id of theProblemPackage
instance with the package file to unpack.- Produced
env
keys: problem_id
: an id of theProblem
instance representing the created or modified problem.
- Used