oioioi.problems.package

This module contains a problem package backend interface. You should create a package.py file in your new app and implement your package backend (inheriting from ProblemPackageBackend) whenever you introduce a new problem package format.

Module Contents

Classes

ProblemPackageBackend

A class which manages problem packages.

Functions

backend_for_package(filename[, original_filename])

Finds a backend suitable for unpacking the given package and returns

Attributes

oioioi.problems.package.logger[source]
exception oioioi.problems.package.ProblemPackageError[source]

Bases: Exception

A generic exception to be used by or subclassed by backends.

exception oioioi.problems.package.PackageProcessingError(func_name, func_doc)[source]

Bases: ProblemPackageError

A generic exception to be used by or subclassed by backends.

class oioioi.problems.package.ProblemPackageBackend[source]

Bases: oioioi.base.utils.RegisteredSubclassesBase, oioioi.base.utils.ObjectWithMixins

A class which manages problem packages.

The main functionality is extracting archives with problem statements, data, model solutions etc. and building Problem instances.

description = __human_readable_name_here__[source]
abstract = True[source]
modules_with_subclasses = package[source]
abstract 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.

abstract 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.

abstract 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 from simple_unpack() (e.g. when a problem is added from a command line).

Used env keys:

package_id: an id of the ProblemPackage instance with the package file to unpack.

Produced env keys:

problem_id: an id of the Problem instance representing the created or modified problem.

simple_unpack(filename, existing_problem=None)[source]

This function may be used for unpacking outside unpackmgr.

Parameters
  • filename – a path to the problem package file

  • existing_problem

    an instance of Problem to be changed.

    If None, a new Problem is created.

Returns a Problem instance.

abstract pack(problem)[source]

Creates a package from problem, returns a django.http.HttpResponse instance.

Should raise NotImplementedError if creating packages is not supported.

exception oioioi.problems.package.NoBackend[source]

Bases: NotImplementedError

Method or function hasn’t been implemented yet.

oioioi.problems.package.backend_for_package(filename, original_filename=None)[source]

Finds a backend suitable for unpacking the given package and returns its dotted name.

Parameters
  • filename – a path to the processed problem package

  • original_filename – the name of the package specified by the

uploading user.