Ejemplo n.º 1
0
def main():
    parsed_args = parse_args()
    settings = collect_settings(parsed_args)

    workspace = settings["workspace"]
    link_file = settings["link_file"]

    # setup logger
    logging_config = settings["logging_config"]
    logging.basicConfig(level=logging_config["level"], format=logging_config["format"])
    logger = logging.getLogger()

    with tempfile.TemporaryDirectory() as tmpdirname:
        temp_workspace = Path(tmpdirname) / workspace.stem

        for input_file in settings["input_files"]:
            try:
                convert_one_file(input_file, temp_workspace, link_file)
            except Exception:
                logger.exception("Error while converting %s file", input_file)

        if settings["output_format"] == RESULT_TYPE_FOLDER:
            shutil.rmtree(str(workspace), ignore_errors=True)
            shutil.copytree(str(temp_workspace), str(workspace))

        if settings["output_format"] == RESULT_TYPE_ZIP:
            shutil.make_archive(str(workspace), "zip", str(temp_workspace))

    logger.info("Conversion completed")

    return 0
Ejemplo n.º 2
0
 def _extract(self):
     settings = collect_settings()
     workspace = settings['workspace']
     path_extracted = filesystem.unzip_directory(self.file_path, workspace)
     self.directory = path_extracted
     manifest = os.path.join(path_extracted, MANIFEST)
     return manifest
Ejemplo n.º 3
0
def main():
    parsed_args = parse_args()
    settings = collect_settings(parsed_args)

    workspace = settings["workspace"]

    # setup logger
    logging_config = settings["logging_config"]
    logging.basicConfig(level=logging_config["level"],
                        format=logging_config["format"])

    with tempfile.TemporaryDirectory() as tmpdirname:
        temp_workspace = Path(tmpdirname) / workspace.stem

        for input_file in settings["input_files"]:
            try:
                convert_one_file(input_file, temp_workspace)
            except Exception:
                traceback.print_exc()

        if settings["output_format"] == RESULT_TYPE_FOLDER:
            shutil.rmtree(str(workspace), ignore_errors=True)
            shutil.copytree(str(temp_workspace), str(workspace))

        if settings["output_format"] == RESULT_TYPE_ZIP:
            shutil.make_archive(str(workspace), "zip", str(temp_workspace))

    return 0
Ejemplo n.º 4
0
def main():
    settings = collect_settings()
    logging.basicConfig(**settings['logging_config'])
    logger = logging.getLogger()
    for input_file in settings['input_files']:
        try:
            convert_one_file(settings, input_file)
        except Exception:
            traceback.print_exc()
Ejemplo n.º 5
0
def settings(imscc_file):
    """
    Basic settings fixture.
    """

    parsed_args = parse_args(["-i", str(imscc_file)])

    _settings = collect_settings(parsed_args)

    yield _settings

    shutil.rmtree(_settings["workspace"], ignore_errors=True)
Ejemplo n.º 6
0
def test_collect_settings(imscc_file):
    parsed_args = parse_args(["-i", str(imscc_file)])

    settings = collect_settings(parsed_args)

    assert settings == {
        "input_files": {imscc_file},
        "output_format": parsed_args.result,
        "workspace": Path.cwd() / "output",
        "link_file": None,
        "logging_config": {
            "level": parsed_args.loglevel,
            "format": "{%(filename)s:%(lineno)d} - %(message)s",
        },
    }
Ejemplo n.º 7
0
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()