Exemple #1
0
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)
Exemple #2
0
def test_olx_export_wiki_page_disabled(cartridge, link_map_csv,
                                       studio_course_xml):
    policy_json = olx.OlxExport(cartridge, link_map_csv).policy()
    policy = json.loads(policy_json)
    tabs = policy["course/course"]["tabs"]

    for tab in tabs:
        if tab["name"] == "Wiki":
            assert tab["is_hidden"]
Exemple #3
0
    def _get_oxl_exporter(self, cartridge, link_map_csv):
        """
        Helper function to create olx exporter.

        Args:
            cartridge ([Cartridge]): Cartridge class instance.
            link_map_csv ([str]): Csv file path.

        Returns:
            [OlxExport]: OlxExport instance.
        """
        olx_exporter = olx.OlxExport(cartridge, link_file=link_map_csv)
        olx_exporter.doc = xml.dom.minidom.Document()
        return olx_exporter
Exemple #4
0
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")
Exemple #5
0
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/')])
Exemple #6
0
def test_olx_export(cartridge, studio_course_xml):
    xml = olx.OlxExport(cartridge).xml()

    assert format_xml(xml) == format_xml(studio_course_xml)
Exemple #7
0
def test_olx_export_xml(cartridge, link_map_csv, studio_course_xml):
    xml = olx.OlxExport(cartridge, link_map_csv).xml()

    assert format_xml(xml) == format_xml(studio_course_xml)