def update_docs(pk, record=True, pdf=True, version_pk=None, touch=False): """ A Celery task that updates the documentation for a project. """ ### # Handle passed in arguments ### project = Project.objects.live().get(pk=pk) print "Building %s" % project if version_pk: versions = [Version.objects.get(pk=version_pk)] else: branch = project.default_branch or project.vcs_repo().fallback_branch latest = Version.objects.filter(project=project, slug='latest') if len(latest): #Handle changing of latest's branch latest = latest[0] if not latest.identifier == branch: latest.identifier = branch latest.save() versions = [latest] else: versions = [Version.objects.create(project=project, identifier=branch, slug='latest', verbose_name='latest')] for version in versions: #Make Dirs path = project.doc_path if not os.path.exists(path): os.makedirs(path) with project.repo_lock(30): if project.is_imported: try: confpy = update_imported_docs(project, version) except ProjectImportError, err: print("Error importing project: %s. Skipping build." % err) return else: if confpy == -1: return -1 scrape_conf_file(version) else: update_created_docs(project) # kick off a build (ret, out, err) = build_docs(project, version, pdf, record, touch) if not 'no targets are out of date.' in out: if ret == 0: print "Build OK" purge_version(version, subdomain=True, mainsite=True, cname=True) update_intersphinx(version.pk) print "Purged %s" % version else: print "Build ERROR" print err else: print "Build Unchanged"
version_data["built"] = True # Need to delete this because a bug in tastypie breaks on the users list. del version_data["project"] try: api.version(version.pk).put(version_data) except Exception, e: log.error("Unable to post a new version", exc_info=True) # Build Finished, do house keeping bits if "no targets are out of date." in out: log.info("Build Unchanged") else: if ret == 0: log.info("Successful Build") purge_version(version, subdomain=True, mainsite=True, cname=True) symlink_cname(version) # This requires database access, must disable it for now. # send_notifications(version, build) log.info("Purged %s" % version) else: log.warning("Failed HTML Build") # TODO: Find a better way to handle indexing. fileify.delay(version.pk) # Things that touch redis update_result = update_intersphinx(version.pk) # Needs to happen after update_intersphinx clear_artifacts(version.pk)
# Need to delete this because a bug in tastypie breaks on the users # list. del version_data['project'] try: api.version(version.pk).put(version_data) except Exception, e: log.error("Unable to post a new version", exc_info=True) # Build Finished, do house keeping bits if 'no targets are out of date.' in out: log.info("Build Unchanged") else: if ret == 0: log.info("Successful Build") purge_version(version, subdomain=True, mainsite=True, cname=True) symlink_cname(version) # This requires database access, must disable it for now. # symlink_translations(version) #send_notifications(version, build) log.info("Purged %s" % version) else: log.warning("Failed HTML Build") # TODO: Find a better way to handle indexing. fileify.delay(version.pk) # Things that touch redis update_intersphinx(version.pk) # Needs to happen after update_intersphinx clear_artifacts(version.pk)
def update_docs(pk, record=True, pdf=True, version_pk=None, touch=False): """ A Celery task that updates the documentation for a project. """ ### # Handle passed in arguments ### project = Project.objects.live().get(pk=pk) print "Building %s" % project if version_pk: versions = [Version.objects.get(pk=version_pk)] else: branch = project.default_branch or project.vcs_repo().fallback_branch latest = Version.objects.filter(project=project, slug='latest') if len(latest): #Handle changing of latest's branch latest = latest[0] if not latest.identifier == branch: latest.identifier = branch latest.save() versions = [latest] else: versions = [ Version.objects.create(project=project, identifier=branch, slug='latest', verbose_name='latest') ] for version in versions: #Make Dirs path = project.doc_path if not os.path.exists(path): os.makedirs(path) with project.repo_lock(30): if project.is_imported: try: confpy = update_imported_docs(project, version) except ProjectImportError, err: print("Error importing project: %s. Skipping build." % err) return else: if confpy == -1: return -1 scrape_conf_file(version) else: update_created_docs(project) # kick off a build (ret, out, err) = build_docs(project, version, pdf, record, touch) if not 'no targets are out of date.' in out: if ret == 0: print "Build OK" purge_version(version, subdomain=True, mainsite=True, cname=True) update_intersphinx(version.pk) print "Purged %s" % version else: print "Build ERROR" print err else: print "Build Unchanged"
def update_docs(pk, record=True, pdf=True, man=True, epub=True, version_pk=None, force=False): """ 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. """ ### # Handle passed in arguments ### project = Project.objects.live().get(pk=pk) print "Building %s" % project if version_pk: versions = [Version.objects.get(pk=version_pk)] else: branch = project.default_branch or project.vcs_repo().fallback_branch latest = Version.objects.filter(project=project, slug='latest') if len(latest): #Handle changing of latest's branch latest = latest[0] if not latest.identifier == branch: latest.identifier = branch latest.save() versions = [latest] else: versions = [Version.objects.create(project=project, identifier=branch, slug='latest', verbose_name='latest')] for version in versions: #Make Dirs path = project.doc_path if not os.path.exists(path): os.makedirs(path) with project.repo_lock(30): if project.is_imported: try: update_imported_docs(project, version) except ProjectImportError, err: print("Error importing project: %s. Skipping build." % err) return False scrape_conf_file(version) else: update_created_docs(project) # kick off a build (ret, out, err) = build_docs(project=project, version=version, pdf=pdf, man=man, epub=epub, record=record, force=force) if not 'no targets are out of date.' in out: if ret == 0: print "HTML Build OK" purge_version(version, subdomain=True, mainsite=True, cname=True) update_intersphinx(version.pk) print "Purged %s" % version else: print "HTML Build ERROR" else: print "Build Unchanged"