def main(): parser = argparse.ArgumentParser() parser.add_argument('root', help='Path to the root of the Repository') parser.add_argument('-s', '--subprojects', default='', help='Comma seperated subprojects') parser.add_argument('-d', '--sub-docpaths', default='', help='Comma seperated docpaths for subprojects') args = parser.parse_args() subprojects, sub_docpaths = [], [] if args.subprojects: subprojects = [name.strip().replace('/', os.path.sep) for name in deserialize(args.subprojects)] if args.sub_docpaths: sub_docpaths = [name.strip().replace('/', os.path.sep) for name in deserialize(args.sub_docpaths)] if len(subprojects) != len(sub_docpaths): raise ValueError("Invalid arguments") content = get_index(args.root, subprojects, sub_docpaths) with open('index.rst', 'w') as file: file.write(content)
def test_empty_list(self): self.assertEqual(deserialize("[]"), [])
def test_nested_list(self): self.assertEqual(deserialize("[true,[1,],Hello,[false]]"), [True, [1, ''], "Hello", [False]])
def test_string_list(self): self.assertEqual(deserialize("[qw,asd,zxcv]"), ['qw','asd','zxcv'])
def test_int_list_no_numeric(self): self.assertEqual(deserialize("[1,2,3]", numeric=False), ['1','2','3'])
def test_int_list(self): self.assertEqual(deserialize("[1,2,3]"), [1,2,3])
def test_with_bool(self): self.assertEqual(deserialize("True"), True) self.assertEqual(deserialize("False"), False) self.assertEqual(deserialize("true"), True) self.assertEqual(deserialize("false"), False)
def get_index(root, subprojects, sub_docpaths): index = [] subproject_dirs = [subproject.split(os.path.sep)[0] for subproject in subprojects] included_files = [] # Include files from the root root_files = next(os.walk(root))[2] for filename in deserialize(os.environ.get('AUTOINDEX_INCLUDE_FILES', '[]')): if filename in root_files: included_files.append(filename) index.append(get_include(root, filename)) if deserialize(os.environ.get('AUTOINDEX_INCLUDE_TOC', 'true')): # Add toctrees as per the directory structure for (dirpath, dirnames, filenames) in os.walk(os.curdir): _ignore_files(dirpath, filenames, included_files, root) _ignore_files(dirpath, filenames, filter(lambda x: x.startswith('.'), filenames)) _ignore_dirs(dirpath, dirnames, filter(lambda x: x.startswith('.'), dirnames)) _ignore_dirs(dirpath, dirnames, ['yaydoctemp', 'yaydocclone']) _ignore_dirs(dirpath, dirnames, ['source'] + subproject_dirs, os.curdir) if filenames: toctree = get_toctree(dirpath, filenames, 1) if toctree: index.append(toctree) if deserialize(os.environ.get('AUTOINDEX_INCLUDE_SUBPROJECT', 'true')): # Add title sub project if subprojects: index.append(get_heading(os.environ.get('AUTOINDEX_SUBPROJECT_HEADING', 'Sub Projects'), 1)) # Add links to sub projects for subproject, sub_docpath in zip(subprojects, sub_docpaths): sub_index_path = os.path.normpath(os.path.join(subproject, sub_docpath, 'index.rst')) toctree = get_toctree(os.curdir, [sub_index_path], 2, _title(subproject.split(os.path.sep)[0])) index.append(toctree) if deserialize(os.environ.get('AUTOINDEX_INCLUDE_APIDOC', 'true')): include_javadoc = deserialize(os.environ.get('AUTOINDEX_INCLUDE_JAVADOC', 'true')) include_swagger = deserialize(os.environ.get('AUTOINDEX_INCLUDE_SWAGGER', 'true')) javadoc = os.environ.get('JAVADOC_PATH', '') swagger = os.environ.get('SWAGGER_SPEC_URL', '') if (javadoc and include_javadoc) or (swagger and include_swagger): index.append(get_heading(os.environ.get('AUTOINDEX_APIDOC_HEADING', 'API Documentation'), 1)) # Add javadoc if javadoc exist if javadoc and include_javadoc: index.append(get_javadoc()) if swagger and include_swagger: index.append(get_swagger_ui()) rss_url = os.environ.get('AUTOINDEX_RSS_URL', '') twitter_query = os.environ.get('AUTOINDEX_TWEETS_QUERY', '') if rss_url: index.append(get_heading(os.environ.get('AUTOINDEX_RSS_HEADING', 'RSS'), 1)) index.append(get_rss_feed(rss_url)) if twitter_query: index.append(get_heading(os.environ.get('AUTOINDEX_TWEETS_HEADING', 'Tweets'), 1)) index.append(get_twitter_feed(twitter_query)) return '\n\n'.join(index) + '\n'
def test_string_list(self): self.assertEqual(deserialize("[qw,asd,zxcv]"), ['qw', 'asd', 'zxcv'])
def test_int_list_no_numeric(self): self.assertEqual(deserialize("[1,2,3]", numeric=False), ['1', '2', '3'])
def test_int_list(self): self.assertEqual(deserialize("[1,2,3]"), [1, 2, 3])