def convert_one_file(settings, input_file): print("Converting", input_file) workspace = settings['workspace'] filesystem.create_directory(workspace) cartridge = Cartridge(input_file) data = cartridge.load_manifest_extracted() cartridge.normalize() # print() # print("=" * 100) # import json; print(json.dumps(cartridge.normalized, indent=4)) xml = olx.OlxExport(cartridge).xml() olx_filename = os.path.join(workspace, cartridge.directory + "-course.xml") with open(olx_filename, "w") as olxfile: olxfile.write(xml) tgz_filename = os.path.join(workspace, cartridge.directory + ".tar.gz") olx.onefile_tar_gz(tgz_filename, xml.encode("utf8"), "course.xml")
def test_load_manifest_extracted(imscc_file, settings, temp_workspace_dir): """ Tests, that all resources and metadata are loaded fine. """ cartridge = Cartridge(imscc_file, settings["workspace"]) cartridge.load_manifest_extracted() cartridge_version = "1.3.0" assert cartridge.version == cartridge_version assert cartridge.directory == Path(temp_workspace_dir.strpath) / "output" / imscc_file.stem assert cartridge.metadata["schema"] == { "name": "IMS Common Cartridge", "version": cartridge_version } assert len(cartridge.resources) == 5 assert len(cartridge.resources[0]["children"]) == 6 assert isinstance(cartridge.resources[0]["children"][0], ResourceFile)
def test_cartridge_initialize(imscc_file, settings): """ Tests, that ``Cartridge`` initializes without errors. """ cartridge = Cartridge(imscc_file, settings["workspace"]) assert cartridge.normalized is None assert cartridge.resources is None assert isinstance(cartridge.cartridge, zipfile.ZipFile) assert cartridge.file_path == imscc_file
def convert_one_file(input_file, workspace, link_file=None): filesystem.create_directory(workspace) cartridge = Cartridge(input_file, workspace) cartridge.load_manifest_extracted() cartridge.normalize() olx_export = olx.OlxExport(cartridge, link_file) olx_filename = cartridge.directory.parent / (cartridge.directory.name + "-course.xml") policy_filename = cartridge.directory.parent / "policy.json" with open(str(olx_filename), "w") as olxfile: olxfile.write(olx_export.xml()) with open(str(policy_filename), "w") as policy: policy.write(olx_export.policy()) tgz_filename = (workspace / cartridge.directory.name).with_suffix(".tar.gz") file_list = [ (str(olx_filename), "course.xml"), (str(policy_filename), "policies/course/policy.json"), (str(cartridge.directory / "web_resources"), "/{}/".format(OLX_STATIC_DIR)), ] # Add static files that are outside of web_resources directory file_list += [ (str(cartridge.directory / filepath), "/static/{}".format(filepath)) for filepath in cartridge.extra_static_files ] filesystem.add_in_tar_gz(str(tgz_filename), file_list)
def cartridge(imscc_file, settings): cartridge = Cartridge(imscc_file, settings["workspace"]) cartridge.load_manifest_extracted() cartridge.normalize() yield cartridge shutil.rmtree(str(settings["workspace"] / imscc_file.stem))
def convert_one_file(input_file, workspace): filesystem.create_directory(workspace) cartridge = Cartridge(input_file, workspace) cartridge.load_manifest_extracted() cartridge.normalize() xml = olx.OlxExport(cartridge).xml() olx_filename = cartridge.directory.parent / (cartridge.directory.name + "-course.xml") with open(str(olx_filename), "w") as olxfile: olxfile.write(xml) tgz_filename = (workspace / cartridge.directory.name).with_suffix('.tar.gz') filesystem.add_in_tar_gz( str(tgz_filename), [(str(olx_filename), 'course.xml'), (str(cartridge.directory / 'web_resources'), '/static/')])
def test_cartridge_normalize(imscc_file, settings): cartridge = Cartridge(imscc_file, settings["workspace"]) cartridge.load_manifest_extracted() cartridge.normalize() assert cartridge.normalized == { "children": [ { "children": [ { "children": [ { "children": [ { "identifier": "vertical", "identifierref": "resource_3_vertical", "title": "Vertical", } ], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "Vertical", }, { "children": [ { "identifier": "lti", "identifierref": "resource_2_lti", "title": "LTI", } ], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "LTI", }, { "children": [ { "identifier": "qti", "identifierref": "resource_4_qti", "title": "QTI" } ], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "QTI" }, ], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "Sequence", } ], "identifier": "sequence", "identifierref": None, "title": "Sequence", } ], "identifier": "org_1", "structure": "rooted-hierarchy", }
import logging import os.path import pprint from cc2olx.settings import collect_settings from cc2olx import filesystem from cc2olx import models from cc2olx.models import Cartridge if __name__ == '__main__': settings = collect_settings() logging.basicConfig(**settings['logging_config']) logger = logging.getLogger() workspace = settings['workspace'] filesystem.create_directory(workspace) for input_file in settings['input_files']: cartridge = Cartridge(input_file) data = cartridge.load_manifest_extracted() pp = pprint.PrettyPrinter(indent=2) pp.pprint(data) cartridge.serialize()
def test_cartridge_normalize(imscc_file, settings): cartridge = Cartridge(imscc_file, settings["workspace"]) cartridge.load_manifest_extracted() cartridge.normalize() assert cartridge.normalized == { "children": [ { "children": [{ "children": [ { "children": [{ "identifier": "vertical", "identifierref": "resource_3_vertical", "title": "Vertical", }], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "Vertical", }, { "children": [{ "identifier": "lti", "identifierref": "resource_2_lti", "title": "LTI", }], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "LTI", }, { "children": [{ "identifier": "qti", "identifierref": "resource_4_qti", "title": "QTI", }], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "QTI", }, { "children": [{ "identifier": "discussion_topic_item", "identifierref": "discussion_topic", "title": "Discussion", }], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "Discussion", }, { "children": [{ "identifier": "image_file", "title": "Image File Webcontent", "identifierref": "resource_5_image_file", }], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "Image File Webcontent", }, { "children": [{ "identifier": "wiki_content", "identifierref": "resource_6_wiki_content", "title": "Wiki Content", }], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "Wiki Content", }, { "children": [{ "identifier": "canvas_content", "identifierref": "resource_7_canvas_content", "title": "Canvas Content", }], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "Canvas Content", }, { "children": [{ "identifier": "video", "identifierref": "resource_5_video", "title": "Video", }], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "Video", }, { "children": [{ "identifier": "video", "identifierref": "resource_9_video", "title": "Video With Other Content", }], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "Video With Other Content", }, { "children": [{ "identifier": "pdf_outside_resource", "identifierref": "pdf_dependency", "title": "PDF Outside of Web Resources", }], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "PDF Outside of Web Resources", }, { "children": [{ "identifier": "web_link_content", "identifierref": "resource_8_web_link_content", "title": "Web Link Content", }], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "Web Link Content", }, ], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "Sequence", }], "identifier": "sequence", "identifierref": None, "title": "Sequence", }, { "children": [ { "children": [{ "children": [{ "identifier": "vertical1", "identifierref": "resource_3_vertical", "title": "Vertical", }], "identifier": "vertical1", "identifierref": "resource_3_vertical", "title": "Vertical", }], "identifier": "vertical1", "identifierref": "resource_3_vertical", "title": "Vertical", }, { "children": [{ "children": [{ "identifier": "subheader1_vertical", "identifierref": "resource_3_vertical", "title": "Vertical", }], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "Vertical", }], "identifier": "subheader1", "identifierref": None, "title": "Sub Header 1", }, { "children": [{ "children": [{ "identifier": "subheader2_vertical", "identifierref": "resource_3_vertical", "title": "Vertical", }], "identifier": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "identifierref": None, "title": "Vertical", }], "identifier": "subheader2", "identifierref": None, "title": "Sub Header 2", }, ], "identifier": "sequence2", "identifierref": None, "title": "Sequence2", }, ], "identifier": "org_1", "structure": "rooted-hierarchy", }