def update_docs(pk, record=True, pdf=True, man=True, epub=True, version_pk=None, force=False, **kwargs): """ The main entry point for updating documentation. It handles all of the logic around whether a project is imported or we created it. Then it will build the html docs and other requested parts. It also handles clearing the varnish cache. `pk` Primary key of the project to update `record` Whether or not to keep a record of the update in the database. Useful for preventing changes visible to the end-user when running commands from the shell, for example. """ ### # Handle passed in arguments ### project_data = api.project(pk).get() project = make_api_project(project_data) # Prevent saving the temporary Project instance def new_save(*args, **kwargs): log.warning("Called save on a non-real object.") return 0 project.save = new_save log.info("Building %s" % project) if version_pk: version_data = api.version(version_pk).get() else: branch = project.default_branch or project.vcs_repo().fallback_branch try: # Use latest version version_data = api.version( project.slug).get(slug='latest')['objects'][0] except (slumber.exceptions.HttpClientError, IndexError): # Create the latest version since it doesn't exist version_data = dict( project='/api/v1/project/%s/' % project.pk, slug='latest', active=True, verbose_name='latest', identifier=branch, ) try: version_data = api.version.post(version_data) except Exception as e: log.info("Exception in creating version: %s" % e) raise e version = make_api_version(version_data) version.save = new_save if not version_pk: # Lots of course correction. to_save = False if not version.verbose_name: version_data['verbose_name'] = 'latest' to_save = True if not version.active: version_data['active'] = True to_save = True if version.identifier != branch: version_data['identifier'] = branch to_save = True if to_save: version_data[ 'project'] = "/api/v1/version/%s/" % version_data['project'].pk api.version(version.pk).put(version_data) if record: # Create Build Object. build = api.build.post( dict( project='/api/v1/project/%s/' % project.pk, version='/api/v1/version/%s/' % version.pk, type='html', state='triggered', )) else: build = {} try: log.info("Updating docs from VCS") update_output = update_imported_docs(version.pk) #update_output = update_result.get() except ProjectImportError, err: log.error("Failed to import project; skipping build.", exc_info=True) build['state'] = 'finished' build[ 'setup_error'] = 'Failed to import project; skipping build.\nPlease make sure your repo is correct and you have a conf.py' api.build(build['id']).put(build) return False
def update_docs(pk, record=True, pdf=True, man=True, epub=True, version_pk=None, force=False, **kwargs): """ The main entry point for updating documentation. It handles all of the logic around whether a project is imported or we created it. Then it will build the html docs and other requested parts. It also handles clearing the varnish cache. `pk` Primary key of the project to update `record` Whether or not to keep a record of the update in the database. Useful for preventing changes visible to the end-user when running commands from the shell, for example. """ ### # Handle passed in arguments ### project_data = api.project(pk).get() project = make_api_project(project_data) # Prevent saving the temporary Project instance def new_save(*args, **kwargs): log.warning("Called save on a non-real object.") return 0 project.save = new_save log.info("Building %s" % project) if version_pk: version_data = api.version(version_pk).get() else: branch = project.default_branch or project.vcs_repo().fallback_branch try: # Use latest version version_data = api.version(project.slug).get(slug='latest')['objects'][0] except (slumber.exceptions.HttpClientError, IndexError): # Create the latest version since it doesn't exist version_data = dict( project='/api/v1/project/%s/' % project.pk, slug='latest', active=True, verbose_name='latest', identifier=branch, ) try: version_data = api.version.post(version_data) except Exception as e: log.info("Exception in creating version: %s" % e) raise e version = make_api_version(version_data) version.save = new_save if not version_pk: # Lots of course correction. to_save = False if not version.verbose_name: version_data['verbose_name'] = 'latest' to_save = True if not version.active: version_data['active'] = True to_save = True if version.identifier != branch: version_data['identifier'] = branch to_save = True if to_save: version_data['project'] = "/api/v1/version/%s/" % version_data['project'].pk api.version(version.pk).put(version_data) if record: # Create Build Object. build = api.build.post(dict( project='/api/v1/project/%s/' % project.pk, version='/api/v1/version/%s/' % version.pk, type='html', state='triggered', )) else: build = {} try: log.info("Updating docs from VCS") update_output = update_imported_docs(version.pk) #update_output = update_result.get() except ProjectImportError, err: log.error("Failed to import project; skipping build.", exc_info=True) build['state'] = 'finished' build['setup_error'] = 'Failed to import project; skipping build.\nPlease make sure your repo is correct and you have a conf.py' api.build(build['id']).put(build) return False
if record: # Update the build with info about the setup build['state'] = 'building' output_data = error_data = '' # Grab all the text from updating the code via VCS. for key in ['checkout', 'venv', 'sphinx', 'requirements', 'install']: data = update_output.get(key, None) if data: try: output_data += u"\n\n%s\n\n%s\n\n" % (key.upper(), data[1]) error_data += u"\n\n%s\n\n%s\n\n" % (key.upper(), data[2]) except UnicodeDecodeError: log.debug("Unicode Error in setup") build['setup'] = output_data build['setup_error'] = error_data api.build(build['id']).put(build) log.info("Building docs") # This is only checking the results of the HTML build, as it's a canary try: (html_results, latex_results, pdf_results, man_results, epub_results) = build_docs(version_pk=version.pk, pdf=pdf, man=man, epub=epub, record=record, force=force) (ret, out, err) = html_results except Exception as e: log.error("Exception in flailboat build_docs", exc_info=True) html_results = (999, "Project build Failed", str(e))
if record: # Update the build with info about the setup build['state'] = 'building' output_data = error_data = '' # Grab all the text from updating the code via VCS. for key in ['checkout', 'venv', 'sphinx', 'requirements', 'install']: data = update_output.get(key, None) if data: try: output_data += u"\n\n%s\n\n%s\n\n" % (key.upper(), data[1]) error_data += u"\n\n%s\n\n%s\n\n" % (key.upper(), data[2]) except UnicodeDecodeError: log.debug("Unicode Error in setup") build['setup'] = output_data build['setup_error'] = error_data api.build(build['id']).put(build) log.info("Building docs") # This is only checking the results of the HTML build, as it's a canary try: (html_results, latex_results, pdf_results, man_results, epub_results) = build_docs( version_pk=version.pk, pdf=pdf, man=man, epub=epub, record=record, force=force ) (ret, out, err) = html_results except Exception as e: log.error("Exception in flailboat build_docs", exc_info=True) html_results = (999, "Project build Failed", str(e)) latex_results = (999, "Project build Failed", str(e)) pdf_results = (999, "Project build Failed", str(e)) man_results = (999, "Project build Failed", str(e)) epub_results = (999, "Project build Failed", str(e))