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 serialize(self): output_directory = self.directory + '-olx' course_directory = os.path.join(output_directory, 'course') for directory in OLX_DIRECTORIES: subdirectory = os.path.join(course_directory, directory) filesystem.create_directory(subdirectory) output_filename = self.directory + '.tar.gz' with tarfile.open(output_filename, 'w:gz') as tar: tar.add(course_directory, arcname=os.path.basename(course_directory))
def serialize(self): output_directory = self.directory + '-olx' course_directory = os.path.join(output_directory, 'course') for directory in OLX_DIRECTORIES: subdirectory = os.path.join(course_directory, directory) filesystem.create_directory(subdirectory) self.write_xml(self.get_course_xml(), course_directory, 'course.xml') run_file = "course/{run}.xml".format(run=self.get_course_run()) self.write_xml(self.get_run_xml(), course_directory, run_file) output_filename = self.directory + '.tar.gz' with tarfile.open(output_filename, 'w:gz') as tar: tar.add(course_directory, arcname=os.path.basename(course_directory))
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 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/')])
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()