示例#1
0
def make_type_rest(all_types, data_type, header_char, prefix):
    """
    Arguments:
      header_char: "=" or "-".
      prefix: the label prefix (e.g. "single-xml" or "multi-xml").
    """
    type_map = all_types.type_map
    if prefix.split('-')[-1] == 'csv':
        type_name = data_type.csv_name
    else:
        type_name = data_type.name
    ref_label = "{0}-{1}".format(prefix, data_type.spinal_name)
    rest = make_rest_header(type_name,
                            label=ref_label,
                            header_char=header_char)

    yaml_data = data_type.yaml

    description = yaml_data.get('description')
    if description:
        rest = add_rest_section(rest, description, prefix=prefix)

    if data_type.tags:
        table_rest = make_table(type_map, data_type, prefix=prefix)
        rest = add_rest_section(rest, table_rest, prefix=prefix)

    if prefix.split('-')[-1] == 'xml':
        post = yaml_data.get('post')
        if post:
            rest = add_rest_section(rest, post, prefix=prefix)
    elif prefix.split('-')[-1] == 'csv':
        post = yaml_data.get('csv-post')
        if post:
            rest = add_rest_section(rest, post, prefix=prefix)

    header_char = get_next_header_char(header_char)
    for sub_type_name in data_type.sub_types:
        sub_type = common.get_type(type_map, sub_type_name)
        sub_rest = make_type_rest(all_types,
                                  sub_type,
                                  header_char=header_char,
                                  prefix=prefix)
        # Separate types with an additional line.
        rest = add_rest_section(rest, sub_rest, prefix=prefix, sep="\n\n")

    for extend_name in data_type.extends:
        extend = common.get_type(type_map, extend_name)
        extend_rest = make_type_rest(all_types,
                                     extend,
                                     header_char=header_char,
                                     prefix=prefix)
        rest = add_rest_section(rest, extend_rest, prefix=prefix, sep="\n\n")

    if not rest.endswith("\n"):
        rest += "\n"

    return rest
示例#2
0
def update_table_files(type_name=None):
    all_types = common.read_types()
    if type_name is None:
        type_names = sorted(all_types.keys())
    else:
        type_names = [type_name]

    for type_name in type_names:
        data_type = common.get_type(all_types, type_name)
        table = make_table(all_types, data_type)
        text = TABLE_COMMENT + table
        rest_path = data_type.table_path
        dir_path = os.path.dirname(rest_path)
        if not os.path.exists(dir_path):
            os.makedirs(dir_path)
        common.write_file(rest_path, text)
示例#3
0
def update_rest_files(type_name=None):
    """
    Update auto-generated reST files.
    """
    prefix = "multi-xml"
    all_types = common.get_all_types()
    type_map = all_types.type_map

    if type_name is None:
        type_names = sorted(type_map.keys())
    else:
        type_names = [type_name]

    update_rest_file_single_page(all_types)

    for type_name in type_names:
        _log.debug("updating rest files for type: {0}".format(type_name))
        data_type = common.get_type(type_map, type_name)
        update_table_file(type_map, data_type, prefix=prefix)
        update_rest_file(all_types, data_type, prefix=prefix)
示例#4
0
def update_rest_files(type_name=None):
    """
    Update auto-generated reST files.
    """
    prefix = "multi-xml"
    all_types = common.get_all_types()
    type_map = all_types.type_map

    if type_name is None:
        type_names = sorted(type_map.keys())
    else:
        type_names = [type_name]

    update_rest_file_single_page(all_types)

    for type_name in type_names:
        _log.debug("updating rest files for type: {0}".format(type_name))
        data_type = common.get_type(type_map, type_name)
        update_table_file(type_map, data_type, prefix=prefix)
        update_rest_file(all_types, data_type, prefix=prefix)
示例#5
0
def make_type_rest(all_types, data_type, header_char, prefix):
    """
    Arguments:
      header_char: "=" or "-".
      prefix: the label prefix (e.g. "single-xml" or "multi-xml").
    """
    type_map = all_types.type_map
    type_name = data_type.name
    ref_label = "{0}-{1}".format(prefix, data_type.spinal_name)
    rest = make_rest_header(type_name, label=ref_label, header_char=header_char)

    yaml_data = data_type.yaml

    description = yaml_data.get('description')
    if description:
        rest = add_rest_section(rest, description, prefix=prefix)

    if data_type.tags:
        table_rest = make_table(type_map, data_type, prefix=prefix)
        rest = add_rest_section(rest, table_rest, prefix=prefix)

    post = yaml_data.get('post')
    if post:
        rest = add_rest_section(rest, post, prefix=prefix)

    header_char = get_next_header_char(header_char)
    for sub_type_name in data_type.sub_types:
        sub_type = common.get_type(type_map, sub_type_name)
        sub_rest = make_type_rest(all_types, sub_type, header_char=header_char, prefix=prefix)
        # Separate types with an additional line.
        rest = add_rest_section(rest, sub_rest, prefix=prefix, sep="\n\n")

    if not rest.endswith("\n"):
        rest += "\n"

    return rest