def main(): '''Generates a python api documentation website.''' if FileHandler('documentation').is_directory(): current_working_directory = FileHandler() index_file = FileHandler('documentation/source/index.rst') modules_to_document = '\ninit' FileHandler( location='%sinit.rst' % index_file.directory.path ).content = ( (79 * '=') + '\n{name}\n' + (79 * '=') + '\n\n.. automodule::' + ' {name}\n :members:' ).format(name=current_working_directory.name) for file in FileHandler(): if Module.is_package(file.path): modules_to_document += '\n %s' % file.name FileHandler(location='%s%s.rst' % ( index_file.directory.path, file.name )).content = ( (79 * '=') + '\n{name}.{package}\n' + (79 * '=') + '\n\n.. automodule:: {name}.{package}\n' ' :members:' ).format( name=current_working_directory.name, package=file.name) for module in __get_all_modules__(file.path): modules_to_document += '\n %s.%s' % (file.name, module) FileHandler(location='%s%s.%s.rst' % ( index_file.directory.path, file.name, module )).content = ( (79 * '=') + '\n{name}.{package}.{module}\n' + (79 * '=') + '\n\n.. automodule:: {name}.{package}.' '{module}\n :members:' ).format( name=current_working_directory.name, package=file.name, module=module) index_file.content = regularExpression.compile( '\n ([a-z][a-zA-Z]+\n)+$', regularExpression.DOTALL ).sub(modules_to_document, index_file.content) Platform.run('/usr/bin/env git add --all', error=False, log=True) FileHandler('documentation').change_working_directory() makefile = FileHandler('Makefile') # # python3.5 FileHandler('MakefilePython3').copy(makefile) FileHandler('MakefilePython2').copy(makefile) Platform.run( command='make html', native_shell=True, error=False, log=True) makefile.remove_file() FileHandler('build/html').path = '../apiDocumentation' FileHandler('build').remove_deep()
def generate_and_push_new_documentation_page( temporary_documentation_folder, distribution_bundle_file, has_api_documentation, temporary_documentation_node_modules_directory ): # # ''' Renders a new index.html file and copies new assets to generate a new \ documentation homepage. ''' global BUILD_DOCUMENTATION_PAGE_COMMAND __logger__.info('Update documentation design.') if distribution_bundle_file: new_distribution_bundle_file = FileHandler(location='%s%s%s' % ( temporary_documentation_folder.path, DOCUMENTATION_BUILD_PATH, DISTRIBUTION_BUNDLE_FILE_PATH)) new_distribution_bundle_file.directory.make_directories() distribution_bundle_file.path = new_distribution_bundle_file new_distribution_bundle_directory = FileHandler(location='%s%s%s' % ( temporary_documentation_folder.path, DOCUMENTATION_BUILD_PATH, DISTRIBUTION_BUNDLE_DIRECTORY_PATH)) new_distribution_bundle_directory.make_directories() zipfile.ZipFile(distribution_bundle_file.path).extractall( new_distribution_bundle_directory.path) favicon = FileHandler(location='favicon.png') if favicon: favicon.copy(target='%s/source/image/favicon.ico' % temporary_documentation_folder.path) parameter = builtins.dict(builtins.map(lambda item: ( String(item[0]).camel_case_to_delimited.content.upper(), item[1] ), SCOPE.get('documentationWebsite', {}).items())) if 'TAGLINE' not in parameter and 'description' in SCOPE: parameter['TAGLINE'] = SCOPE['description'] if 'NAME' not in parameter and 'name' in SCOPE: parameter['NAME'] = SCOPE['name'] __logger__.debug('Found parameter "%s".', json.dumps(parameter)) api_documentation_path = None if has_api_documentation: api_documentation_path = '%s%s' % ( API_DOCUMENTATION_PATH[1], API_DOCUMENTATION_PATH_SUFFIX) if not FileHandler(location='%s%s' % ( FileHandler().path, api_documentation_path )).is_directory(): api_documentation_path = API_DOCUMENTATION_PATH[1] parameter.update({ 'CONTENT': CONTENT, 'CONTENT_FILE_PATH': None, 'RENDER_CONTENT': False, 'API_DOCUMENTATION_PATH': api_documentation_path, 'DISTRIBUTION_BUNDLE_FILE_PATH': DISTRIBUTION_BUNDLE_FILE_PATH if ( distribution_bundle_file and distribution_bundle_file.is_file() ) else None }) # # python3.5 # # parameter = Dictionary(parameter).convert( # # value_wrapper=lambda key, value: value.replace( # # '!', '#%%%#' # # ) if builtins.isinstance(value, builtins.str) else value # # ).content parameter = Dictionary(parameter).convert( value_wrapper=lambda key, value: value.replace( '!', '#%%%#' ) if builtins.isinstance(value, builtins.unicode) else value ).content # # if __logger__.isEnabledFor(logging.DEBUG): BUILD_DOCUMENTATION_PAGE_COMMAND = \ BUILD_DOCUMENTATION_PAGE_COMMAND[:-1] + [ '-debug' ] + BUILD_DOCUMENTATION_PAGE_COMMAND[-1:] serialized_parameter = json.dumps(parameter) parameter_file = FileHandler(location=make_secure_temporary_file('.json')[ 1]) parameter_file.content = \ BUILD_DOCUMENTATION_PAGE_PARAMETER_TEMPLATE.format( serializedParameter=serialized_parameter, **SCOPE) for index, command in builtins.enumerate(BUILD_DOCUMENTATION_PAGE_COMMAND): BUILD_DOCUMENTATION_PAGE_COMMAND[index] = \ BUILD_DOCUMENTATION_PAGE_COMMAND[index].format( serializedParameter=serialized_parameter, parameterFilePath=parameter_file._path, **SCOPE) __logger__.debug('Use parameter "%s".', serialized_parameter) __logger__.info('Run "%s".', ' '.join(BUILD_DOCUMENTATION_PAGE_COMMAND)) current_working_directory_backup = FileHandler() temporary_documentation_folder.change_working_directory() Platform.run( command=BUILD_DOCUMENTATION_PAGE_COMMAND[0], command_arguments=BUILD_DOCUMENTATION_PAGE_COMMAND[1:], error=False, log=True) current_working_directory_backup.change_working_directory() parameter_file.remove_file() for file in FileHandler(): if not (file in (temporary_documentation_folder, FileHandler( location='.%s' % API_DOCUMENTATION_PATH[1] )) or is_file_ignored(file)): file.remove_deep() documentation_build_folder = FileHandler(location='%s%s' % ( temporary_documentation_folder.path, DOCUMENTATION_BUILD_PATH ), must_exist=True) documentation_build_folder.iterate_directory( function=copy_repository_file, recursive=True, source=documentation_build_folder, target=FileHandler()) if (Platform.run( "/usr/bin/env sudo umount '%s'" % temporary_documentation_node_modules_directory.path, native_shell=True, error=False, log=True )['return_code'] == 0): temporary_documentation_folder.remove_deep() Platform.run( ( '/usr/bin/env git add --all', '/usr/bin/env git commit --message "%s" --all' % PROJECT_PAGE_COMMIT_MESSAGE, '/usr/bin/env git push', '/usr/bin/env git checkout master' ), native_shell=True, error=False, log=True )