Ejemplo n.º 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
Ejemplo n.º 2
0
def add_records_from_filesystem(translators, profile=None):
    """Adds a set of records for a given set of of translators, returning
    the created records.
    """
    if type(translators) not in [list]:
        translators = [translators]
    record_maker = make_records_from_filesystem_closure(profile=profile)
    records = map(record_maker, translators)
    records = utils.flatten(records, [])
    return records
Ejemplo n.º 3
0
def add_templates_from_filesystem(database, structures, profile=None):
    """Makes a set of templates from a set of structures, then adds
    the created templates to the database in a new template collection.
    """
    if type(structures) not in [list]:
        structures = [structures]
    template_maker = make_templates_from_filesystem_closure(database, profile=profile)
    templates = map(template_maker, structures)
    templates = utils.flatten(templates, [])
    templates = create_template_collection(database, templates)
    templates = get_current_templates(database)
    return templates
Ejemplo n.º 4
0
def add_translators_from_filesystem(database, templates, profile=None):
    """Makes a set of translators from a set of templates, then adds the translators
    to the database in a new translator collection.
    """
    if type(templates) not in [list]:
        templates = [templates]
    translator_maker = make_translators_from_filesystem_closure(database, profile=profile)
    translators = map(translator_maker, templates)
    translators = utils.flatten(translators, [])
    translators = create_translator_collection(database, translators)
    translators = get_current_translators(database)
    return translators
Ejemplo n.º 5
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