Exemplo n.º 1
0
def create_modified_json(reference_files):
    config = _get_json_data(os.path.join(BASE_DIR, 'config.json'))
    refer_link = _.get(config, 'refer_link')
    origin_json_files = _get_json_file_path(TARGET_DIR)

    if len(origin_json_files) == 0:
        _error(f"JSON not found at ({TARGET_DIR})")
    else:
        total_dictionary = {}
        for json_path in origin_json_files:
            fname = get_file_syntax(json_path)
            full_single_json = _get_json_data(json_path)
            single = _.get(full_single_json, 'files')
            total_dictionary[key_path_creator(json_path)] = full_single_json
            for obj in single:
                new_desc = _modify_yaml_to_json(obj['description'])
                _.set(obj, 'description', new_desc)
                package = obj['package']
                enums = get_enums_dict(obj['enums'])
                services = _.get(obj, 'services')
                messages = _.get(obj, 'messages')
                message_names = [a['name'] for a in messages]

                for service in services:
                     for method in service['methods']:
                         method_status = is_exists_in_same_file(message_names, method, fname)

                         svc_desc = _modify_yaml_to_json(method['description'])
                         method['description'] = svc_desc
                         google_api = _.get(method, 'options')

                         if(google_api is not None):
                            rest_apis = google_api['google.api.http']['rules']
                            method['restAPI'] = rest_apis

                         if (method['requestFullType'] in [*refer_link] and not method_status['req_status']):
                             method['requestFullType_link'] = refer_link[method['requestFullType']]

                         if (method['responseFullType'] in [*refer_link] and not method_status['res_status']):
                             method['responseFullType_link'] = refer_link[method['responseFullType']]

                for message in messages:
                    for field in message["fields"]:
                        field_long_type_wrapper(message, field, enums)
                        field['description'] = field_desc_wrapper(field['description'])
                        field_full_type_wrapper(fname, field, refer_link, package)

            full_single_json['file_info'] = fname
        return total_dictionary
Exemplo n.º 2
0
def _generate_summary_mds(context_input, managed_link, history):
    table_of_contents = {}
    title_index = []
    config = _get_json_data(os.path.join(BASE_DIR, 'config.json'))

    for path in context_input:

        file_info = _get_file_name_syntax(path)
        full_path = path[path.find('api/') + 4:len(path)].replace(
            '.json', '.md')
        parsed_path = full_path.split('/')
        parsed_path[len(parsed_path) - 1] = parsed_path[len(parsed_path) -
                                                        1].replace('_', '-')
        full_file_name = '/'.join(parsed_path)
        parsed_path[len(parsed_path) - 1] = file_info['title']
        base_bullet = '* '
        check_key = ""

        for i in range(len(parsed_path)):
            if i != 0:
                check_key = check_key + '.' + parsed_path[i]
                base_bullet = '  ' + base_bullet
            else:
                check_key = parsed_path[i]

            title_no_under_bar = parsed_path[i].replace('_', ' ')
            updated_header = base_bullet + '[' + title_no_under_bar + ']'

            if _.get(table_of_contents, check_key, None) is None:
                if i == (len(parsed_path) - 1):
                    _.set(table_of_contents, check_key, {})
                    title_index.append({
                        'title': updated_header.title(),
                        'url': full_file_name.lower()
                    })
                else:
                    mk_path = check_key.replace('.', '/')
                    readme_url = mk_path + '/' + 'README.md'
                    readme_path = os.path.join(BASE_DIR, mk_path, 'README.md')

                    if not os.path.exists(readme_path):
                        _generate_md_file(readme_path, TEMPLATE_NAMES[2], '')

                    _.set(table_of_contents, check_key, {})
                    title_index.append({
                        'title': updated_header.title(),
                        'url': readme_url
                    })

    output_to_create = os.path.join(BASE_DIR, 'SUMMARY.md')
    normalized_link = _normalize_managed_link(managed_link)
    context_input = {
        'toc': title_index,
        'managed_link': normalized_link,
        'history': {
            'cur_version': history
        }
    }

    # Updating All SUMMARY.md
    _generate_md_file(output_to_create, TEMPLATE_NAMES[1], context_input)

    # Updating All README.md
    output_to_create = os.path.join(BASE_DIR, 'README.md')
    readme_output = _.get(config, 'intro_comment')
    version_info = history if history.startswith('v') else 'v' + history
    _.set(readme_output, 'version', version_info)
    _generate_md_file(output_to_create, TEMPLATE_NAMES[2], readme_output)
Exemplo n.º 3
0
url = api_protocol + "://" + api_host + ":" + port + "/api/" + api_version

api_client = cm_client.ApiClient(url)

role_config_group_resource_api = cm_client.RoleConfigGroupsResourceApi(
    api_client)

config_by_roles = role_config_group_resource_api.read_role_config_groups(
    cluster_name=cluster, service_name=service)

config_by_group = {}
role_config_group_name_displayname_mapping = {}
for item in config_by_roles.items:
    role_group_name = item.name
    _.set(role_config_group_name_displayname_mapping, "" + item.display_name,
          role_group_name)
    for subitem in item.config.items:
        _.set(
            config_by_group, "" + subitem.name,
            _.push(_.get(config_by_group, "" + subitem.name, []),
                   role_group_name))

updating_counter = 0
updated_counter = 0
for config in args.config:
    picked_role_config_group = None
    configuration = _.replace(config[0], '.', '_')
    value = config[1]
    specified_role_config_group = _.get(config, '[2]', None)
    specified_role_config_group_display_name = _.get(config, '[2]', None)
    if (specified_role_config_group_display_name
Exemplo n.º 4
0
def _generate_summary_mds(context_input, managed_link, history):
    table_of_contents = {}
    title_index = []
    config = _get_json_data(os.path.join(BASE_DIR, 'config.json'))
    for path in context_input:

        file_info = get_file_syntax(path)
        full_path = path[path.find('api/') + 4:len(path)].replace('.json', '.md')
        parsed_path = full_path.split('/')
        parsed_path[len(parsed_path) - 1] = parsed_path[len(parsed_path) - 1].replace('_', '-')
        full_file_name = '/'.join(parsed_path)
        parsed_path[len(parsed_path)-1] = file_info['title']
        base_bullet = '* '
        check_key = ""

        for i in range(len(parsed_path)):
            if(i != 0 ):
                check_key = check_key+'.'+parsed_path[i]
                base_bullet = '  ' + base_bullet
            else:
                check_key = parsed_path[i]

            updated_header = base_bullet + '[' + parsed_path[i] + ']'
            if(_.get(table_of_contents, check_key, None) == None ):
                if(i == (len(parsed_path)-1)):
                    _.set(table_of_contents, check_key, {})
                    title_index.append({'title': updated_header.title(), 'url': full_file_name})
                else:
                    mk_path = check_key.replace('.', '/')
                    readme_url = mk_path + '/'+ 'README.md'
                    readme_path = os.path.join(BASE_DIR, mk_path, 'README.md')

                    if not os.path.exists(readme_path):
                        _generate_md_file(readme_path, TEMPLATE_NAMES[2], '')

                    _.set(table_of_contents, check_key, {})
                    title_index.append({'title': updated_header.title(), 'url': readme_url})

    if ('version_record' in history and len(history['version_record']) > 0):
        vtable_of_contents = []
        gitbook_space = _.get(config, 'refer_link.git_book_space')
        previous_version_md = os.path.join(BASE_DIR, 'previous_version', 'README.md')

        for version in history['version_record']:
            line = f'* [{version}]({gitbook_space}previous-versions/previous_version/{version}/)'
            vtable_of_contents.append(line)

        _generate_md_file(previous_version_md, TEMPLATE_NAMES[3], {'list': vtable_of_contents})

    output_to_create = os.path.join(BASE_DIR, 'SUMMARY.md')
    context_input = {'toc': title_index}
    context_input['managed_link'] = _normalize_managed_link(managed_link)
    context_input['history'] = history

    # Updating All SUMMARY.md
    _generate_md_file(output_to_create, TEMPLATE_NAMES[1], context_input)

    # Updating All README.md
    output_to_create = os.path.join(BASE_DIR, 'README.md')
    README_OUTPUT = _.get(config, 'intro_comment')
    _.set(README_OUTPUT, 'version', history['cur_version'])
    _generate_md_file(output_to_create, TEMPLATE_NAMES[2], README_OUTPUT)
Exemplo n.º 5
0
cm_client.configuration.username = cm_client_username
cm_client.configuration.password = cm_client_password

url = f'{api_protocol}://{api_host}:{port}/api/{api_version}'

api_client = cm_client.ApiClient(url)

role_config_group_resource_api = cm_client.RoleConfigGroupsResourceApi(api_client)

config_by_roles = role_config_group_resource_api.read_role_config_groups(cluster_name=cluster, service_name=service)

config_by_group = {}
for item in config_by_roles.items:
    role_group_name = item.name
    for subitem in item.config.items:
        _.set(config_by_group, f'{subitem.name}', _.push(_.get(config_by_group, f'{subitem.name}', []), role_group_name))

for config in args.config:
    picked_role_config_group = None
    configuration = _.replace(config[0], '.', '_')
    value = config[1]
    specified_role_config_group = _.get(config, '[2]', None)

    if configuration in config_by_group:
        structures_for_config = config_by_group[configuration]

        picked_role_config_group = specified_role_config_group or _.find(structures_for_config, lambda x: _.ends_with(x, '-BASE'))

        if _.index_of(structures_for_config, picked_role_config_group) != -1:
            # updating configuration
            print(f"Updating: '{configuration}' for '{picked_role_config_group}' config group")