Ejemplo n.º 1
0
def main():
    """
    Use ``create_parser`` to get the commandline arguments, and pass them to
    the appropriate function in __init__.py (create_template, flatten or
    unflatten).

    """
    parser = create_parser()
    # Store the supplied arguments in args
    args = parser.parse_args()

    if args.subparser_name is None:
        parser.print_help()
    elif args.subparser_name == 'create-template':
        # Pass the arguments to the create_template function
        # If the schema file does not exist we catch it in this exception
        try:
            # Note: Ensures that empty arguments are not passed to the create_template function
            create_template(**kwargs_from_parsed_args(args))
        except (OSError, IOError) as e:
            print(text_type(e))
            return
    elif args.subparser_name == 'flatten':
        flatten(**kwargs_from_parsed_args(args))
    elif args.subparser_name == 'unflatten':
        unflatten(**kwargs_from_parsed_args(args))
Ejemplo n.º 2
0
def main():
    """
    Use ``create_parser`` to get the commandline arguments, and pass them to
    the appropriate function in __init__.py (create_template, flatten or
    unflatten).

    """
    parser = create_parser()
    # Store the supplied arguments in args
    args = parser.parse_args()

    if args.subparser_name is None:
        parser.print_help()
    elif args.subparser_name == 'create-template':
        # Pass the arguments to the create_template function
        # If the schema file does not exist we catch it in this exception
        try:
            # Note: Ensures that empty arguments are not passed to the create_template function
            create_template(**kwargs_from_parsed_args(args))
        except (OSError, IOError) as e:
            print(text_type(e))
            return
    elif args.subparser_name == 'flatten':
        flatten(**kwargs_from_parsed_args(args))
    elif args.subparser_name == 'unflatten':
        unflatten(**kwargs_from_parsed_args(args))
Ejemplo n.º 3
0
def main():
    """
    Takes any command line arguments and then passes them onto
    create_template
    Defaults are not set here, but rather given in the create_template
    function incase that function is called from elsewhere in future.
    """
    parser = create_parser()
    # Store the supplied arguments in args
    args = parser.parse_args()

    if args.subparser_name is None:
        parser.print_help()
    elif args.subparser_name == 'create-template':
        # Pass the arguments to the create_template function
        # If the schema file does not exist we catch it in this exception
        try:
            # Note: Ensures that empty arguments are not passed to the create_template function
            create_template(**kwargs_from_parsed_args(args))
        except (OSError, IOError) as e:
            print(text_type(e))
            return
    elif args.subparser_name == 'flatten':
        flatten(**kwargs_from_parsed_args(args))
    elif args.subparser_name == 'unflatten':
        unflatten(**kwargs_from_parsed_args(args))
Ejemplo n.º 4
0
def main():
    """
    Use ``create_parser`` to get the commandline arguments, and pass them to
    the appropriate function in __init__.py (create_template, flatten or
    unflatten).

    """
    parser = create_parser()
    # Store the supplied arguments in args
    args = parser.parse_args()

    if args.subparser_name is None:
        parser.print_help()
        return

    if not args.verbose:
        sys.excepthook = non_verbose_error_handler
        warnings.formatwarning = non_verbose_warning_formatter

    if args.subparser_name == "create-template":
        # Pass the arguments to the create_template function
        # If the schema file does not exist we catch it in this exception
        try:
            # Note: Ensures that empty arguments are not passed to the create_template function
            create_template(**kwargs_from_parsed_args(args))
        except (OSError, IOError) as e:
            print(str(e))
            return
    elif args.subparser_name == "flatten":
        flatten(**kwargs_from_parsed_args(args))
    elif args.subparser_name == "unflatten":
        unflatten(**kwargs_from_parsed_args(args))
Ejemplo n.º 5
0
def setup(app):
    app.add_config_value(
        'recommonmark_config',
        {
            #'url_resolver': lambda url: github_doc_root + url,
            'auto_toc_tree_section': 'Contents',
            'enable_eval_rst': True
        },
        True)
    app.add_transform(AutoStructify)

    import json
    import json_merge_patch
    import os
    import glob
    from collections import OrderedDict

    schema = OrderedDict()

    for file in glob.glob("../schema/firstmilefarmdataframe/*.json"
                          ) + glob.glob("../schema/components/*.json"):
        try:
            with open(file, 'r') as schema_file:
                print("Merging " + file)
                schema_element = json.loads(schema_file.read(),
                                            object_pairs_hook=OrderedDict)
                schema = json_merge_patch.merge(schema,
                                                schema_element,
                                                position='last')
        except Exception:
            print("Problem merging from " + file)
            pass

    with open("_static/first-mile-farm-data-schema.json", "w") as outfile:
        outfile.write(json.dumps(schema, indent=2))

    print("Full schema in first-mile-schema.json updated")

    from flattentool import create_template, unflatten, flatten
    create_template(schema="_static/first-mile-farm-data-schema.json",
                    output_name="_static/flattened")

    global html_static_path
    for file in glob.glob("extensions/*/*.json"):
        html_static_path = html_static_path + [file]

    for file in glob.glob("../schema/components/*.json"):
        html_static_path = html_static_path + [file]
Ejemplo n.º 6
0
import flattentool
import shutil

for dirname in ['../schema/multi-table', '../schema/summary-table']:
    try:
        shutil.rmtree(dirname)
    except FileNotFoundError:
        pass
    os.makedirs(dirname)

for output_format in ['csv', 'xlsx']:
    flattentool.create_template(
        root_id='',
        output_format=output_format,
        output_name='../schema/multi-table/360-giving-schema-fields.' +
        output_format,
        schema='../schema/360-giving-schema.json',
        main_sheet_name='grants',
    )

    flattentool.create_template(
        root_id='',
        output_format=output_format,
        output_name='../schema/summary-table/360-giving-schema-titles.' +
        output_format,
        schema='../schema/360-giving-schema.json',
        main_sheet_name='grants',
        rollup=True,
        use_titles=True,
    )
Ejemplo n.º 7
0
import json_merge_patch
import os
import glob
from collections import OrderedDict
from flattentool import create_template, unflatten, flatten

schema = OrderedDict()

for file in glob.glob("firstmilefarmdataframe/*.json") + glob.glob(
        "components/*.json"):
    try:
        with open(file, 'r') as schema_file:
            print("Merging " + file)
            schema_element = json.loads(schema_file.read(),
                                        object_pairs_hook=OrderedDict)
            schema = json_merge_patch.merge(schema,
                                            schema_element,
                                            position='last')
    except Exception:
        print("Problem merging from " + file)
        pass

with open("first-mile-farm-data-schema.json", "w") as outfile:
    outfile.write(json.dumps(schema, indent=2))

create_template(schema="first-mile-farm-data-schema.json",
                output_name="../csv",
                output_format='csv')

print("Full schema in first-mile-farm-data-schema.json updated")
Ejemplo n.º 8
0
import flattentool
import shutil

for dirname in ['../schema/multi-table', '../schema/summary-table']:
    try:
        shutil.rmtree(dirname)
    except FileNotFoundError:
        pass
    os.makedirs(dirname)

for output_format in ['csv', 'xlsx']:
    flattentool.create_template(
        root_id='',
        output_format=output_format,
        output_name='../schema/multi-table/360-giving-schema-fields.'+output_format,
        schema='../schema/360-giving-schema.json',
        main_sheet_name='grants',
    )

    flattentool.create_template(
        root_id='',
        output_format=output_format,
        output_name='../schema/summary-table/360-giving-schema-titles.'+output_format,
        schema='../schema/360-giving-schema.json',
        main_sheet_name='grants',
        rollup=True,
        use_titles=True,
    )

#mv README.md 360-giving-schema-titles.csv/