Example #1
0
def make_file_translator(translator):
    """Updates a file translator type, returning the updated translator.
    """

    field_translator_dictionary = {}
    field_translator_dictionary['field_names'] = 'name'
    field_translator_dictionary['field_types'] = 'type'
    field_translator_dictionary['field_start_positions'] = 'start_position'
    field_translator_dictionary['field_end_positions'] = 'end_position'
    field_translator_dictionary['field_justify'] = 'justify'
    field_translator_dictionary['field_precision'] = 'precision'
    file_translator_dictionary = {}
    file_translator_dictionary['file_path'] = 'path'
    file_variables_dictionary = {}
    file_variables_dictionary['field_separator'] = 'separator'
    remove_keys = utils.flatten([field_translator_dictionary.keys(),
                                 file_translator_dictionary.keys(),
                                 file_variables_dictionary.keys()], [])
    translator['variables'] = {}
    translator['variables']['method'] = 'file'
    field_properties = {key: translator[key] for key in translator.keys()
                        if key in field_translator_dictionary.keys()}
    field_tool = generic_model.field_converter_closure(field_properties, field_translator_dictionary)
    field_properties = map(field_tool, field_properties)
    translator['variables']['fields'] = map(generic_model.combine_fields, zip(*field_properties))
    translator['variables']['path'] = translator['file_path']
    if 'field_separator' in translator.keys():
        translator['variables']['separator'] = translator['field_separator']
    utils.remove_dictionary_keys(translator, remove_keys)
    return translator
Example #2
0
 def add_source(translator):
     source_properties = {key: translator[key] for key in translator.keys() if is_source_key(key)}
     source_tool = generic_model.field_converter_closure(source_properties, source_translator_dictionary)
     source_properties = map(source_tool, source_properties)
     translator['source'] = map(generic_model.combine_fields, zip(*source_properties))[0]
     utils.remove_dictionary_keys(translator, source_translator_dictionary.keys())
     return translator
Example #3
0
 def adjust_indeces(template):
     index_properties = {key: template[key] for key in template.keys() if is_index_key(key)}
     field_tool = generic_model.field_converter_closure(index_properties, index_translator_dictionary)
     index_properties = map(field_tool, index_properties)
     template['indeces'] = map(generic_model.combine_fields, zip(*index_properties))
     utils.remove_dictionary_keys(template, index_translator_dictionary.keys())
     return template
Example #4
0
def remove_identifiers(parameter):
    """Removes the identifiers (extraneous information) that should not be stored
    with the other information about the parameter.
    """
    identifiers = ['harness', 'component', 'function', 'type']
    utils.remove_dictionary_keys(parameter, identifiers)
    return parameter
Example #5
0
 def adjust_name(template):
     if 'name' not in template.keys():
         if 'template_file' in template.keys():
             template['name'] = parse_template_file_name(template['template_file'])
         else:
             template['name'] = 'auto_' + utils.get_random_string(length=10)
     utils.remove_dictionary_keys(template, ['template_file'])
     return template
Example #6
0
 def modify_ushcn_station(station):
     station["location"] = make_ushcn_location(station)
     station["composites"] = make_ushcn_composites(station)
     remove_keys = ["latitude", "longitude", "elevation", "state", "locality",
                    "composite1", "composite2", "composite3", "composite4",
                    "time_zone"]
     utils.remove_dictionary_keys(station, remove_keys)
     return station
Example #7
0
 def modify_northam_station(station):
     station["point"] = spatial_utils.make_point(station["longitude"],
                                                 station["latitude"],
                                                 station["elevation"])
     station["location"] = make_northam_location(station)
     remove_keys = ["latitude", "longitude", "elevation"]
     utils.remove_dictionary_keys(station, remove_keys)
     return station
Example #8
0
 def adjust_fields(template):
     if setup:
         field_properties = {key: template[key] for key in template.keys() if is_field_key(key)}
         field_tool = generic_model.field_converter_closure(field_properties, field_translator_dictionary)
         field_properties = map(field_tool, field_properties)
         template['fields'] = map(generic_model.combine_fields, zip(*field_properties))
         utils.remove_dictionary_keys(template, field_translator_dictionary.keys())
     elif 'fields' not in template.keys():
         template['fields'] = []
     return template
Example #9
0
 def add_target(translator):
     target_properties = {key: translator[key] for key in translator.keys() if is_target_key(key)}
     if target_properties:
         target_tool = generic_model.field_converter_closure(target_properties, target_translator_dictionary)
         target_properties = map(target_tool, target_properties)
         translator['target'] = map(generic_model.combine_fields, zip(*target_properties))[0]
         utils.remove_dictionary_keys(translator, target_translator_dictionary.keys())
     else:
         translator['target'] = {}
         translator['target']['structure'] = template['structure']
         translator['target']['template'] = template['name']
     return translator
Example #10
0
def make_web_translator(translator):
    """Updates a web translator type, returning the updated translator.
    """
    field_translator_dictionary = {}
    field_translator_dictionary['field_names'] = 'name'
    field_translator_dictionary['field_types'] = 'type'
    field_translator_dictionary['field_precision'] = 'precision'
    translator['variables'] = {}
    translator['variables']['method'] = 'web'
    field_properties = {key: translator[key] for key in translator.keys()
                        if key in field_translator_dictionary.keys()}
    field_tool = generic_model.field_converter_closure(field_properties, field_translator_dictionary)
    field_properties = map(field_tool, field_properties)
    translator['variables']['fields'] = map(generic_model.combine_fields, zip(*field_properties))
    remove_keys = utils.flatten([field_translator_dictionary.keys()], [])
    utils.remove_dictionary_keys(translator, remove_keys)
    return translator
Example #11
0
 def move_setup_properties(template):
     template['setup'] = {key: template[key] for key in get_setup_keys()}
     utils.remove_dictionary_keys(template, get_setup_keys())
     return template
Example #12
0
 def move_setup_properties(structure):
     structure['setup'] = {key: structure[key] for key in get_setup_keys()}
     utils.remove_dictionary_keys(structure, get_setup_keys())
     return structure
Example #13
0
 def remove_identifiers(function):
     identifiers = ["harness"]
     utils.remove_dictionary_keys(function, identifiers)
Example #14
0
 def cleanup(translator):
     utils.remove_dictionary_keys(translator, get_cleanup_keys())
     return translator
Example #15
0
 def modify_ghcnm_station(station):
     station["location"] = make_ghcnm_location(station)
     remove_keys = ["latitude", "longitude", "elevation", "location_name"]
     utils.remove_dictionary_keys(station, remove_keys)
     return station
Example #16
0
def remove_workflow_identifier(workflow_function):
    """Simple filter to remove the workflow identifer from the passed function.
    """
    identifiers = ['workflow']
    utils.remove_dictionary_keys(workflow_function, identifiers)
    return workflow_function
Example #17
0
 def remove_identifiers(workflow_function):
     identifiers = ['harness']
     utils.remove_dictionary_keys(workflow_function, identifiers)
Example #18
0
def remove_function_identifier(function_parameter):
    """Removes the function identifier from the function_parameter object.
    """
    identifiers = ['function']
    utils.remove_dictionary_keys(function_parameter, identifiers)
    return function_parameter
Example #19
0
def remove_scope_identifier(function_parameter):
    """Removes the scope identifier (input or output) from the function parameter object.
    """
    identifiers = ['type']
    utils.remove_dictionary_keys(function_parameter, identifiers)
    return function_parameter
Example #20
0
 def add_map(translator):
     map_fields = [key for key in translator.keys() if key.startswith('Target')]
     translator['map'] = {replace_dots(field): replace_dots(translator[field]) for field in map_fields}
     utils.remove_dictionary_keys(translator, map_fields)
     return translator