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
Exemple #2
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
Exemple #3
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
Exemple #4
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
Exemple #5
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
Exemple #6
0
 def adjust_indeces(template):
     index_properties = {
         key: template[key]
         for key in list(template.keys()) if is_index_key(key)
     }
     field_tool = generic_model.field_converter_closure(
         index_properties, index_translator_dictionary)
     index_properties = list(map(field_tool, index_properties))
     template['indeces'] = list(
         map(generic_model.combine_fields, list(zip(*index_properties))))
     general_utils.remove_dictionary_keys(
         template, list(index_translator_dictionary.keys()))
     return template
 def add_source(translator):
     source_properties = {
         key: translator[key]
         for key in list(translator.keys()) if is_source_key(key)
     }
     source_tool = generic_model.field_converter_closure(
         source_properties, source_translator_dictionary)
     source_properties = list(map(source_tool, source_properties))
     translator['source'] = list(
         map(generic_model.combine_fields,
             list(zip(*source_properties))))[0]
     general_utils.remove_dictionary_keys(
         translator, list(source_translator_dictionary.keys()))
     return translator
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
Exemple #9
0
 def adjust_fields(template):
     if setup:
         field_properties = {
             key: template[key]
             for key in list(template.keys()) if is_field_key(key)
         }
         field_tool = generic_model.field_converter_closure(
             field_properties, field_translator_dictionary)
         field_properties = list(map(field_tool, field_properties))
         template['fields'] = list(
             map(generic_model.combine_fields,
                 list(zip(*field_properties))))
         general_utils.remove_dictionary_keys(
             template, list(field_translator_dictionary.keys()))
     elif 'fields' not in list(template.keys()):
         template['fields'] = []
     return template
Exemple #10
0
 def add_target(translator):
     target_properties = {
         key: translator[key]
         for key in list(translator.keys()) if is_target_key(key)
     }
     if target_properties:
         target_tool = generic_model.field_converter_closure(
             target_properties, target_translator_dictionary)
         target_properties = list(map(target_tool, target_properties))
         translator['target'] = list(
             map(generic_model.combine_fields,
                 list(zip(*target_properties))))[0]
         general_utils.remove_dictionary_keys(
             translator, list(target_translator_dictionary.keys()))
     else:
         translator['target'] = {}
         translator['target']['structure'] = template['structure']
         translator['target']['template'] = template['name']
     return translator