def move(self, **kwargs): project = self.version.project if project.full_build_path(self.version.slug): # Copy the html files. target = project.rtd_build_path(self.version.slug) if "_" in project.slug: new_slug = project.slug.replace("_", "-") new_target = target.replace(project.slug, new_slug) # Only replace 1, so user_builds doesn't get replaced >:x targets = [target, new_target] else: targets = [target] for target in targets: if getattr(settings, "MULTIPLE_APP_SERVERS", None): log.info("Copying docs to remote server.") copy_to_app_servers(project.full_build_path(self.version.slug), target) else: if os.path.exists(target): shutil.rmtree(target) log.info("Copying docs on the local filesystem") shutil.copytree(project.full_build_path(self.version.slug), target) # Copy the zip file. to_path = os.path.join(settings.MEDIA_ROOT, "htmlzip", project.slug, self.version.slug) to_file = os.path.join(to_path, "%s.zip" % project.slug) from_path = project.checkout_path(self.version.slug) from_file = os.path.join(from_path, "%s.zip" % project.slug) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) run("mv -f %s %s" % (from_file, to_file)) else: log.warning("Not moving docs, because the build dir is unknown.")
def move(self, **kwargs): project = self.version.project if project.full_build_path(self.version.slug): #Copy the html files. target = project.rtd_build_path(self.version.slug) if getattr(settings, "MULTIPLE_APP_SERVERS", None): log.info("Copying docs to remote server.") copy_to_app_servers(project.full_build_path(self.version.slug), target) else: if os.path.exists(target): shutil.rmtree(target) log.info("Copying docs on the local filesystem") shutil.copytree(project.full_build_path(self.version.slug), target) #Copy the zip file. to_path = os.path.join(settings.MEDIA_ROOT, 'htmlzip', project.slug, self.version.slug) to_file = os.path.join(to_path, '%s.zip' % project.slug) from_path = project.checkout_path(self.version.slug) from_file = os.path.join(from_path, '%s.zip' % project.slug) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) run('mv -f %s %s' % (from_file, to_file)) else: log.warning("Not moving docs, because the build dir is unknown.")
def build(self): project = self.version.project os.chdir(project.conf_dir(self.version.slug)) # Default to this so we can return it always. pdf_results = (1, "", "") if project.use_virtualenv: latex_results = run( "%s -b latex -d _build/doctrees . _build/latex" % project.venv_bin(version=self.version.slug, bin="sphinx-build") ) else: latex_results = run("sphinx-build -b latex " "-d _build/doctrees . _build/latex") if latex_results[0] == 0: os.chdir("_build/latex") tex_globs = glob("*.tex") if tex_globs: tex_file = tex_globs[0] pdf_results = run("pdflatex -interaction=nonstopmode %s" % tex_file) pdf_match = pdf_re.search(pdf_results[1]) if pdf_match: to_path = os.path.join(settings.MEDIA_ROOT, "pdf", project.slug, self.version.slug) from_file = os.path.join(os.getcwd(), "*.pdf") to_file = os.path.join(to_path, "%s.pdf" % project.slug) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) run("mv -f %s %s" % (from_file, to_file)) else: print "PDF Building failed. Moving on." return (latex_results, pdf_results)
def update_static_metadata(project_pk): """Update static metadata JSON file Metadata settings include the following project settings: version The default version for the project, default: `latest` language The default language for the project, default: `en` languages List of languages built by linked translation projects. """ project_base = apiv2.project(project_pk) project_data = project_base.get() project = make_api_project(project_data) translations = project_base.translations.get()["translations"] languages = set([translation["language"] for translation in translations if "language" in translation]) # Convert to JSON safe types metadata = {"version": project.default_version, "language": project.language, "languages": list(languages)} try: path = project.static_metadata_path() fh = open(path, "w") json.dump(metadata, fh) fh.close() copy_file_to_app_servers(path, path) except IOError as e: log.debug( LOG_TEMPLATE.format(project=project.slug, version="", msg="Cannot write to metadata.json: {0}".format(e)) )
def move(self): project = self.version.project outputted_path = os.path.join(project.conf_dir(self.version.slug), '_build', 'pdf') to_path = os.path.join(settings.MEDIA_ROOT, 'pdf', project.slug, self.version.slug) from_file = os.path.join(outputted_path, "%s.pdf" % project.slug) to_file = os.path.join(to_path, "%s.pdf" % project.slug) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) if os.path.exists(to_file): os.unlink(to_file) # Get a list of files that match the wildcard, and then only move # the first one. Seems to be more reliable than mv command. from_files = glob.glob(from_file) if len(from_files): shutil.move(from_files[0], to_file) else: print "Failed to move pdf file"
def move(self, **kwargs): project = self.version.project outputted_path = self.version.project.checkout_path(self.version.slug) to_path = os.path.join(settings.MEDIA_ROOT, 'dash', project.slug, self.version.slug) from_globs = glob(os.path.join(outputted_path, "*.tgz")) if from_globs: from_file = from_globs[0] to_file = os.path.join(to_path, "%s.tgz" % project.doc_name) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) run('mv -f %s %s' % (from_file, to_file)) xml_globs = glob(os.path.join(outputted_path, "*.xml")) if xml_globs: from_file = xml_globs[0] to_file = os.path.join(to_path, "%s.xml" % project.doc_name) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) run('mv -f %s %s' % (from_file, to_file))
def move(self): project = self.version.project if project.full_build_path(self.version.slug): #Copy the html files. target = project.rtd_build_path(self.version.slug) if getattr(settings, "MULTIPLE_APP_SERVERS", None): log.info("Copying docs to remote server.") copy_to_app_servers(project.full_build_path(self.version.slug), target) else: if os.path.exists(target): shutil.rmtree(target) log.info("Copying docs on the local filesystem") shutil.copytree(project.full_build_path(self.version.slug), target) #Copy the zip file. to_path = os.path.join(settings.MEDIA_ROOT, 'htmlzip', project.slug, self.version.slug) to_file = os.path.join(to_path, '%s.zip' % project.slug) from_path = project.checkout_path(self.version.slug) from_file = os.path.join(from_path, '%s.zip' % project.slug) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) run('mv -f %s %s' % (from_file, to_file)) else: log.warning("Not moving docs, because the build dir is unknown.")
def build(self): project = self.version.project os.chdir(project.conf_dir(self.version.slug)) if project.use_virtualenv and project.whitelisted: latex_results = run('%s -b latex -d _build/doctrees . _build/latex' % project.venv_bin(version=self.version.slug, bin='sphinx-build')) else: latex_results = run('sphinx-build -b latex ' '-d _build/doctrees . _build/latex') if latex_results[0] == 0: os.chdir('_build/latex') tex_globs = glob('*.tex') if tex_globs: tex_file = tex_globs[0] else: return False pdf_results = run('pdflatex -interaction=nonstopmode %s' % tex_file) pdf_match = pdf_re.search(pdf_results[1]) if pdf_match: to_path = os.path.join(settings.MEDIA_ROOT, 'pdf', project.slug, self.version.slug) from_file = os.path.join(os.getcwd(), "*.pdf") to_file = os.path.join(to_path, '%s.pdf' % project.slug) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) run('mv -f %s %s' % (from_file, to_file)) else: print "PDF Building failed. Moving on." return latex_results
def build(self, **kwargs): project = self.version.project os.chdir(project.conf_dir(self.version.slug)) #Default to this so we can return it always. pdf_results = (1, '', '') if project.use_virtualenv: latex_results = run( '%s -b latex -d _build/doctrees . _build/latex' % project.venv_bin(version=self.version.slug, bin='sphinx-build')) else: latex_results = run('sphinx-build -b latex ' '-d _build/doctrees . _build/latex') if latex_results[0] == 0: os.chdir('_build/latex') #if project.whitelisted: # For whitelisted projects, read LaTeX sources from conf.py #conf_py_file = project.conf_file(self.version.slug) #conf = {} #execfile(conf_py_file, conf, conf) #tex_files = [d[1] for d in conf.get('latex_documents', [])] #else: # Otherwise treat all .tex files as sources tex_files = glob('*.tex') # Run LaTeX -> PDF conversions pdflatex_cmds = [ 'pdflatex -interaction=nonstopmode %s' % tex_file for tex_file in tex_files ] pdf_results = run(*pdflatex_cmds) if pdf_results[0] == 0: for tex_file in tex_files: to_path = os.path.join(settings.MEDIA_ROOT, 'pdf', project.slug, self.version.slug) to_file = os.path.join(to_path, '%s.pdf' % project.slug) # pdflatex names its output predictably: foo.tex -> foo.pdf pdf_filename = os.path.splitext(tex_file)[0] + '.pdf' from_file = os.path.join(os.getcwd(), pdf_filename) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) run('mv -f %s %s' % (from_file, to_file)) if latex_results[0] != 0 or pdf_results[0] != 0: log.warning("PDF Building failed. Moving on.") return (latex_results, pdf_results)
def move(self): project = self.version.project outputted_path = os.path.join(project.conf_dir(self.version.slug), '_build', 'epub') to_path = os.path.join(settings.MEDIA_ROOT, 'epub', project.slug, self.version.slug) from_file = os.path.join(outputted_path, "*.epub") to_file = os.path.join(to_path, "%s.epub" % project.slug) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) run('mv -f %s %s' % (from_file, to_file))
def build(self, **kwargs): project = self.version.project os.chdir(project.conf_dir(self.version.slug)) #Default to this so we can return it always. pdf_results = (1, '', '') if project.use_virtualenv: latex_results = run('%s -b latex -d _build/doctrees . _build/latex' % project.venv_bin(version=self.version.slug, bin='sphinx-build')) else: latex_results = run('sphinx-build -b latex ' '-d _build/doctrees . _build/latex') if latex_results[0] == 0: os.chdir('_build/latex') #if project.whitelisted: # For whitelisted projects, read LaTeX sources from conf.py #conf_py_file = project.conf_file(self.version.slug) #conf = {} #execfile(conf_py_file, conf, conf) #tex_files = [d[1] for d in conf.get('latex_documents', [])] #else: # Otherwise treat all .tex files as sources tex_files = glob('*.tex') # Run LaTeX -> PDF conversions pdflatex_cmds = ['pdflatex -interaction=nonstopmode %s' % tex_file for tex_file in tex_files] pdf_results = run(*pdflatex_cmds) if pdf_results[0] == 0: for tex_file in tex_files: to_path = os.path.join(settings.MEDIA_ROOT, 'pdf', project.slug, self.version.slug) to_file = os.path.join(to_path, '%s.pdf' % project.slug) # pdflatex names its output predictably: foo.tex -> foo.pdf pdf_filename = os.path.splitext(tex_file)[0] + '.pdf' from_file = os.path.join(os.getcwd(), pdf_filename) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) run('mv -f %s %s' % (from_file, to_file)) if latex_results[0] != 0 or pdf_results[0] != 0: log.warning("PDF Building failed. Moving on.") return (latex_results, pdf_results)
def move(self): project = self.version.project outputted_path = os.path.join(project.conf_dir(self.version.slug), '_build', 'man') to_path = os.path.join(settings.MEDIA_ROOT, 'man', project.slug, self.version.slug) from_file = os.path.join(outputted_path, "*.1") to_file = os.path.join(to_path, '%s.1' % project.slug) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) run('mv -f %s %s' % (from_file, to_file))
def move(self, **kwargs): project = self.version.project outputted_path = os.path.join(project.conf_dir(self.version.slug), '_build', 'man') to_path = os.path.join(settings.MEDIA_ROOT, 'man', project.slug, self.version.slug) from_globs = glob(os.path.join(outputted_path, "*.1")) if from_globs: from_file = from_globs[0] to_file = os.path.join(to_path, '%s.1' % project.slug) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) run('mv -f %s %s' % (from_file, to_file))
def update_static_metadata(project_pk): """Update static metadata JSON file Metadata settings include the following project settings: version The default version for the project, default: `latest` language The default language for the project, default: `en` languages List of languages built by linked translation projects. """ project_base = apiv2.project(project_pk) project_data = project_base.get() project = make_api_project(project_data) log.info(LOG_TEMPLATE.format( project=project.slug, version='', msg='Updating static metadata', )) translations = project_base.translations.get()['translations'] languages = set([ translation['language'] for translation in translations if 'language' in translation ]) # Convert to JSON safe types metadata = { 'version': project.default_version, 'language': project.language, 'languages': list(languages), 'single_version': project.single_version, } try: path = project.static_metadata_path() fh = open(path, 'w') json.dump(metadata, fh) fh.close() copy_file_to_app_servers(path, path) except IOError as e: log.debug(LOG_TEMPLATE.format( project=project.slug, version='', msg='Cannot write to metadata.json: {0}'.format(e) ))
def update_static_metadata(project_pk): """Update static metadata JSON file Metadata settings include the following project settings: version The default version for the project, default: `latest` language The default language for the project, default: `en` languages List of languages built by linked translation projects. """ project_base = apiv2.project(project_pk) project_data = project_base.get() project = make_api_project(project_data) log.info( LOG_TEMPLATE.format( project=project.slug, version='', msg='Updating static metadata', )) translations = project_base.translations.get()['translations'] languages = set([ translation['language'] for translation in translations if 'language' in translation ]) # Convert to JSON safe types metadata = { 'version': project.default_version, 'language': project.language, 'languages': list(languages), 'single_version': project.single_version, } try: path = project.static_metadata_path() fh = open(path, 'w') json.dump(metadata, fh) fh.close() copy_file_to_app_servers(path, path) except IOError as e: log.debug( LOG_TEMPLATE.format( project=project.slug, version='', msg='Cannot write to metadata.json: {0}'.format(e)))
def build(self): project = self.version.project os.chdir(project.conf_dir(self.version.slug)) if project.use_virtualenv and project.whitelisted: latex_results = run('%s -b latex -d _build/doctrees . _build/latex' % project.venv_bin(version=self.version.slug, bin='sphinx-build')) else: latex_results = run('sphinx-build -b latex ' '-d _build/doctrees . _build/latex') if latex_results[0] == 0: os.chdir('_build/latex') tex_globs = glob('*.tex') if tex_globs: tex_file = tex_globs[0] else: return False pdf_results = run('pdflatex -interaction=nonstopmode %s' % tex_file) pdf_match = pdf_re.search(pdf_results[1]) if pdf_match: to_path = os.path.join(settings.MEDIA_ROOT, 'pdf', project.slug, self.version.slug) from_file = os.path.join(os.getcwd(), "*.pdf") to_file = os.path.join(to_path, '%s.pdf' % project.slug) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) if os.path.exists(to_file): os.unlink(to_file) # Get a list of files that match the wildcard, and then only # move the first one. Seems to be more reliable than mv # command. from_files = glob(from_file) if len(from_files): shutil.move(from_files[0], to_file) else: print "Failed to move pdf file" else: print "PDF Building failed. Moving on." return latex_results
def move(self, **kwargs): project = self.version.project outputted_path = os.path.join(project.conf_dir(self.version.slug), '_build', 'epub') to_path = os.path.join(settings.MEDIA_ROOT, 'epub', project.slug, self.version.slug) from_globs = glob(os.path.join(outputted_path, "*.epub")) if from_globs: from_file = from_globs[0] to_file = os.path.join(to_path, "%s.epub" % project.slug) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) run('mv -f %s %s' % (from_file, to_file))
def move(self, **kwargs): #This needs to be thought about more because of all the state above. #We could just shove the filename on the instance or something. project = self.version.project os.chdir(os.path.join(project.conf_dir(self.version.slug), '_build', 'latex')) tex_files = glob('*.tex') for tex_file in tex_files: to_path = os.path.join(settings.MEDIA_ROOT, 'pdf', project.slug, self.version.slug) to_file = os.path.join(to_path, '%s.pdf' % project.slug) # pdflatex names its output predictably: foo.tex -> foo.pdf pdf_filename = os.path.splitext(tex_file)[0] + '.pdf' from_file = os.path.join(os.getcwd(), pdf_filename) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) run('mv -f %s %s' % (from_file, to_file))
def build(self): project = self.version.project os.chdir(project.conf_dir(self.version.slug)) #Default to this so we can return it always. pdf_results = (1, '', '') if project.use_virtualenv: latex_results = run( '%s -b latex -d _build/doctrees . _build/latex' % project.venv_bin(version=self.version.slug, bin='sphinx-build')) else: latex_results = run('sphinx-build -b latex ' '-d _build/doctrees . _build/latex') if latex_results[0] == 0: os.chdir('_build/latex') tex_globs = glob('*.tex') if tex_globs: tex_file = tex_globs[0] pdf_results = run('pdflatex -interaction=nonstopmode %s' % tex_file) pdf_match = pdf_re.search(pdf_results[1]) if pdf_match: to_path = os.path.join(settings.MEDIA_ROOT, 'pdf', project.slug, self.version.slug) from_globs = glob(os.path.join(os.getcwd(), "*.pdf")) if from_globs: from_file = from_globs[0] to_file = os.path.join(to_path, '%s.pdf' % project.slug) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) run('mv -f %s %s' % (from_file, to_file)) else: log.warning("PDF Building failed. Moving on.") return (latex_results, pdf_results)
def move(self, **kwargs): project = self.version.project if project.full_build_path(self.version.slug): #Copy the html files. target = project.rtd_build_path(self.version.slug) if "_" in project.slug: new_slug = project.slug.replace('_', '-') new_target = target.replace(project.slug, new_slug) #Only replace 1, so user_builds doesn't get replaced >:x targets = [target, new_target] else: targets = [target] for target in targets: if getattr(settings, "MULTIPLE_APP_SERVERS", None): log.info("Copying docs to remote server.") copy_to_app_servers( project.full_build_path(self.version.slug), target) else: if os.path.exists(target): shutil.rmtree(target) log.info("Copying docs on the local filesystem") shutil.copytree(project.full_build_path(self.version.slug), target) #Copy the zip file. to_path = os.path.join(settings.MEDIA_ROOT, 'htmlzip', project.slug, self.version.slug) to_file = os.path.join(to_path, '%s.zip' % project.slug) from_path = project.checkout_path(self.version.slug) from_file = os.path.join(from_path, '%s.zip' % project.slug) if os.path.exists(from_file): if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) run('mv -f %s %s' % (from_file, to_file)) else: log.warning("Not moving docs, because the build dir is unknown.")
def build(self, **kwargs): project = self.version.project os.chdir(project.conf_dir(self.version.slug)) #Default to this so we can return it always. pdf_results = (1, '', '') if project.use_virtualenv: latex_results = run('%s -b latex -d _build/doctrees . _build/latex' % project.venv_bin(version=self.version.slug, bin='sphinx-build')) else: latex_results = run('sphinx-build -b latex ' '-d _build/doctrees . _build/latex') if latex_results[0] == 0: os.chdir('_build/latex') tex_globs = glob('*.tex') if tex_globs: tex_file = tex_globs[0] pdf_results = run('pdflatex -interaction=nonstopmode %s' % tex_file) pdf_match = pdf_re.search(pdf_results[1]) if pdf_match: to_path = os.path.join(settings.MEDIA_ROOT, 'pdf', project.slug, self.version.slug) from_globs = glob(os.path.join(os.getcwd(), "*.pdf")) if from_globs: from_file = from_globs[0] to_file = os.path.join(to_path, '%s.pdf' % project.slug) if getattr(settings, "MULTIPLE_APP_SERVERS", None): copy_file_to_app_servers(from_file, to_file) else: if not os.path.exists(to_path): os.makedirs(to_path) run('mv -f %s %s' % (from_file, to_file)) else: log.warning("PDF Building failed. Moving on.") return (latex_results, pdf_results)