Beispiel #1
0
def merge(source_files, output_filename="default.json", output_metrics=True):
    """Utility function to merge JSON assets."""
    LOG.info("%i assets -> %s", len(source_files), output_filename)
    merged = { }
    for i, f in enumerate(source_files):
        LOG.info("Processing:%03i:%s", i + 1, f)
        try:
            with open(f, 'r') as source:
                j = json_load(source)
                if isinstance(j, dict):
                    merged = merge_dictionaries(j, merged)
                else:
                    merged = j
        except IOError as e:
            LOG.error("Failed processing: %s", f)
            LOG.error('  >> %s', e)
    try:
        with open(output_filename, 'w') as target:
            LOG.info("Writing:%s", output_filename)
            json_encoder.FLOAT_REPR = float_to_string
            json_dump(merged, target, sort_keys=True, separators=(',', ':'))
    except IOError as e:
        LOG.error('Failed processing: %s', output_filename)
        LOG.error('  >> %s', e)
    else:
        if output_metrics:
            log_metrics(merged)
Beispiel #2
0
def standard_include(infiles):
    """Load and merge all the ``infiles``."""
    if infiles:
        definitions = {}
        for infile in infiles:
            if path_exists(infile):
                with open(infile, 'r') as infile_file:
                    infile_json = json_load(infile_file)
                    definitions = merge_dictionaries(infile_json, definitions)
            else:
                LOG.error('Missing file: %s', infile)
        return JsonAsset(definitions=definitions)
    else:
        return JsonAsset()
    return None
Beispiel #3
0
def standard_include(infiles):
    """Load and merge all the ``infiles``."""
    if infiles:
        definitions = { }
        for infile in infiles:
            if path_exists(infile):
                with open(infile, 'r') as infile_file:
                    infile_json = json_load(infile_file)
                    definitions = merge_dictionaries(infile_json, definitions)
            else:
                LOG.error('Missing file: %s', infile)
        return JsonAsset(definitions=definitions)
    else:
        return JsonAsset()
    return None