コード例 #1
0
def get_structure_dictionary_from_file(structure_file):
    """Returns a structure as a dictionary from the given file.
    """
    properties = property_reader_utils.make_dictionary(structure_file)
    properties = {key: processor_utils.adjust_property_value(properties[key])
                  for key in list(properties.keys())}
    return properties
コード例 #2
0
def get_translator_dictionary_from_file(translator_file):
    """Returns a translator as a dictionary from the given file.
    """
    properties = property_reader_utils.make_dictionary(translator_file)
    properties = {key: processor_utils.adjust_property_value(properties[key])
                  for key in list(properties.keys())}
    properties['translator_file'] = translator_file
    return properties
コード例 #3
0
def file_to_properties(extension, rel_exec_path=None, rel_property_path=None):
    current_path = os.path.dirname(os.path.realpath(__file__))
    setup_file = current_path.replace(rel_exec_path, rel_property_path)
    setup_file += extension
    properties = property_reader_utils.make_dictionary(setup_file)
    return properties
コード例 #4
0
def get_records_from_file(variables):
    """Accepts a dictionary containing a fields parameter as a list of field
    dictionaries ([f1,f2,f3] where f1 has at least a name and type and can possibly
    have other instructions), a file path, and optionally a field separator,
    and returns the records from the file.
    """
    fields = variables['fields']
    field_types = [(field['name'], field['type']) for field in fields]
    path = variables['path']
    separator = None
    if 'separator' in list(variables.keys()):
        separator = translate_delimiter(variables['separator'])
    slices = None
    if 'start_position' in list(fields[0].keys()):
        start_positions = [field['start_position'] for field in fields]
        slices = make_slices(make_intervals(strings_to_ints(start_positions)))
    records = read_records('Record', field_types, path, slices, separator)
    return list(map(named_tuple_to_dictionary, records))


def named_tuple_to_dictionary(named_tuple):
    """Changes a named tuple to its equivalent dictionary.
    """
    return named_tuple._asdict()


if __name__ == '__main__':
    print('Running direct method of record reader.')
    properties = make_dictionary(sys.argv[1])
    records = get_records_as_tuples(properties)
コード例 #5
0
ファイル: filesystem_dao.py プロジェクト: ShriyaSalian/mars
def get_dictionary_by_profile(path, full_path=False):
    if not full_path:
        path = replace_relative_path(path, '/src/main/dao/filesystem',
                                     '/properties/profiles/')
    return property_reader_utils.make_dictionary(path)