#!/usr/bin/env python # Copyright (c) OpenMMLab. All rights reserved. import os import os.path as osp import re from glob import glob def _get_project_docs(): """Get all project document files. Returns: list[str]: file paths """ project_root = osp.join('..', '..', 'projects') pattern = osp.sep.join(['*'] * 2) + '.md' docs = glob(osp.join(project_root, pattern)) docs = [ doc for doc in docs if 'example_project' not in doc and '_CN' not in doc ] return docs def _parse_project_doc_path(fn): """Get project name and banner from a project reference file. Returns: tuple: - project_name (str) - project_banner (str) """ project_banner, project_name = None, None with open(fn, 'r', encoding='utf-8') as f: for line in f.readlines(): if re.match('^( )*#', line) faq_doc.append(line) return faq_doc def main(): # Build output folders os.makedirs('projects', exist_ok=True) # Collect all document contents project_doc_list = _get_project_docs() project_lines = [] for path in project_doc_list: name, banner = _parse_project_doc_path(path) _path = path.split(osp.sep) _rel_path = _path[_path.index('projects'):-1] url = 'https://github.com/open-mmlab/mmpose/blob/dev-1.x/' + '/'.join( _rel_path) _name = name.split(':', 1) name, description = _name[0], '' if len( _name) < 2 else f': {_name[-1]}' project_lines += [ f'- **{name}**{description} [\\[github\\]]({url})', '', '