class documentation

class SQLiteStorage(Storage):

Constructor: SQLiteStorage()

View In Hierarchy

This class stores data in a sqlite database on disk. SQLiteStorage.terms A dict mapping course identifiers to a set of terms that will be checked when searching courses. SQLiteStorage.search_results A dict mapping search terms to the return value of SQLiteStorage.find_courses() .

Method __init__ Initialise SQLiteStorage.
Method close_sqlite_connections Close all connections present in SQLiteStorage.connections .
Method ensure_course_connection Ensure that an up-to-date database connection exists for parameter 'course'.
Method find_courses Search for courses, and return a tuple (id_title_dict, match_dict).
Method get_cached_item Return an item from the course's cache as a dict.
Method get_content Return the variant data for the content of the step as specified by variant_format, or empty data.
Method get_course_metadata Return the metadata of the course as a dict.
Method get_format Return the format identifier of the first format that matches the tag list in tags.
Method get_html Return the content of the first HTML file found for the step, or an empty string.
Method get_step_titles Return a dictionary mapping step identifiers to their titles.
Method get_steps_ordered Return a nested OrderedDict of step identifiers and titles.
Method parse_group Scan the current group of steps, build output, and recurse into subgroups.
Method require_uuid Require that parameter 'course' is an uuid.UUID.
Method write_course Create a new SQLite database representing the course. Return a message indicating success or failure.
Instance Variable search_results Undocumented
Instance Variable terms Undocumented

Inherited from Storage:

Method delete_course Delete the course identified by course.
Method delete_learning_content Delete the learning content identified by learning_content_id.
Method delete_variant Attempt to delete the variant identified by variant_id. Return a message in case of success.
Method get_course_titles Return a list of titles of existing courses.
Method get_directory Return a tuple (directory_name, html) with the name of the first directory found in the learning content, and the content of the first HTML file found in there. Both elements may be empty.
Method get_image Return the URI to the first image found for the step, or an empty string.
Method get_steps Return a list of step identifiers for a course in arbitrary order.
Method get_variant_metadata Return the metadata of the variant as a dict.
Method get_variants Return a list of all variants for a learning content in a course.
Method get_variants_ids Return a list of identifiers of all variants for a learning content in a course.
Method write_learning_content Create a new learning content.
Method write_learning_contents_list Write an re-ordered list of learning contents into the course.
Method write_variant Write a variant consisting of a single or multiple files, and create the according meta files.
def __init__(self):

Initialise SQLiteStorage.

def close_sqlite_connections(self):

Close all connections present in SQLiteStorage.connections .

def ensure_course_connection(func):

Ensure that an up-to-date database connection exists for parameter 'course'.

def find_courses(self, term=None):

Search for courses, and return a tuple (id_title_dict, match_dict). id_title_dict maps course titles to their IDs, and IDs to titles. If term is given, id_title_dict will only contain courses that match the term in their set of SQLiteStorage.terms. The match will be fuzzy, i.e. find similar or misspelled terms. If term is given, match_dict will map course titles to a match ratio between 0.0 and 1.0 . Found courses with a required Luna LMS version different from the current one will be omitted.

def get_cached_item(self, course, path):

Return an item from the course's cache as a dict. course can be an identifier or the course title. An identifier is recommended, since titles may not be unique. Example: { "path": "square.svg", "data": bytes('<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg width="512" height="512" viewBox="0 0 135.46666 135.46667" version="1.1" id="svg5" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"><defs id="defs2" /><g id="layer1"><rect style="fill:#ba2bcd;fill-opacity:1;stroke:none;stroke-width:0.187088;stroke-linecap:square;stroke-linejoin:round" id="rect286" width="95.789398" height="95.789398" x="-47.894699" y="47.894699" transform="rotate(-45)" /></g></svg>', encoding = "utf-8"), "format": "image/svg+xml", "description": "A violet square, balancing on a corner." }

def get_content(self, course, step, variant_format=None):

Return the variant data for the content of the step as specified by variant_format, or empty data. course can be an identifier or the course title. An identifier is recommended, since titles may not be unique. variant_format can be a dot-separated Luna LMS format identifier, or a prefix of its sha256 hash. If a variant of the requested format does not exist, an empty data string will be returned. If variant_format evaluates to False, this method will try to return a variant in the default format, or any HTML variant. The return value is a tuple conforming to: (data, format, tagging) format is the identifier of the format being returned. tagging is a tuple of collections.namedtuple("Tagging", ["format_id", "tag_id", "title", "format_available"]) "format_id" and "tag_id" define a many-to-many association of formats and tags. "title" is the human-readable title of the tag. "format_available" is True when all non-empty steps of the course have a variant in this format. If even one variant is missing, the format is flagged as not available. The tuple is ordered by tag_id. The order is significant, and meant to be retained when displaying a list of tags. "title" and "format_available" are redundant in the tuple, but this way all information can be conveyed in a single simple data structure.

def get_course_metadata(self, course):

Return the metadata of the course as a dict. course can be an identifier or the course title. An identifier is recommended, since titles may not be unique.

def get_format(self, course, tags):

Return the format identifier of the first format that matches the tag list in tags. course can be an identifier or the course title. An identifier is recommended, since titles may not be unique.

def get_html(self, course, step):

Return the content of the first HTML file found for the step, or an empty string. course can be an identifier or the course title. An identifier is recommended, since titles may not be unique.

def get_step_titles(self, course):

Return a dictionary mapping step identifiers to their titles. course can be an identifier or the course title. An identifier is recommended, since titles may not be unique.

def get_steps_ordered(self, course):

Return a nested OrderedDict of step identifiers and titles. course can be an identifier or the course title. An identifier is recommended, since titles may not be unique.

def parse_group(self, current_level, current_parent, cursor, all_parents):

Scan the current group of steps, build output, and recurse into subgroups. This method is meant to be called from build_steps().

def require_uuid(func):

Require that parameter 'course' is an uuid.UUID.

def write_course(self, title):

Create a new SQLite database representing the course. Return a message indicating success or failure.

search_results: dict =

Undocumented

terms: dict =

Undocumented