def copy_asset_file(source, destination, context=None, renderer=None): """Copy an asset file to destination. On copying, it expands the template variables if context argument is given and the asset is a template file. :param source: The path to source file :param destination: The path to destination file or directory :param context: The template variables. If not given, template files are simply copied :param renderer: The template engine. If not given, SphinxRenderer is used by default """ if not os.path.exists(source): return if os.path.exists(destination) and os.path.isdir(destination): # Use source filename if destination points a directory destination = os.path.join(destination, os.path.basename(source)) if source.lower().endswith('_t') and context: if renderer is None: from sphinx.util.template import SphinxRenderer renderer = SphinxRenderer() with codecs.open(source, 'r', encoding='utf-8') as fsrc: with codecs.open(destination[:-2], 'w', encoding='utf-8') as fdst: fdst.write(renderer.render_string(fsrc.read(), context)) else: copyfile(source, destination)
def copy_assets(app, exception): """ Copy asset files to the output """ if 'getLogger' in dir(logging): log = logging.getLogger(__name__).info # pylint: disable=no-member else: log = app.info builders = get_compatible_builders(app) if exception: return if app.builder.name not in builders: if not app.config['sphinx_tabs_nowarn']: app.warn( 'Not copying tabs assets! Not compatible with %s builder' % app.builder.name) return log('Copying tabs assets') installdir = os.path.join(app.builder.outdir, '_static', 'sphinx_tabs') for path in FILES: source = resource_filename('sphinx_tabs', path) dest = os.path.join(installdir, path) destdir = os.path.dirname(dest) if not os.path.exists(destdir): os.makedirs(destdir) copyfile(source, dest)
def copy_static(app, exception): if app.builder.format != 'html' or exception: return for filename in ['jsdemo.js', 'jsdemo.css']: src = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename) dst = os.path.join(app.builder.outdir, '_static', filename) copyfile(src, dst)
def copy_image_files_pil(self): """Copy images using the PIL. The method tries to read and write the files with the PIL, converting the format and resizing the image if necessary/possible. """ ensuredir(path.join(self.outdir, self.imagedir)) for src in self.app.status_iterator(self.images, "copying images... ", brown, len(self.images)): dest = self.images[src] try: img = Image.open(path.join(self.srcdir, src)) except IOError: if not self.is_vector_graphics(src): self.warn("cannot read image file %r: copying it instead" % (path.join(self.srcdir, src),)) try: copyfile(path.join(self.srcdir, src), path.join(self.outdir, self.imagedir, dest)) except (IOError, OSError) as err: self.warn("cannot copy image file %r: %s" % (path.join(self.srcdir, src), err)) continue if self.config.epub_fix_images: if img.mode in ("P",): # See PIL documentation for Image.convert() img = img.convert() if self.config.epub_max_image_width > 0: (width, height) = img.size nw = self.config.epub_max_image_width if width > nw: nh = (height * nw) / width img = img.resize((nw, nh), Image.BICUBIC) try: img.save(path.join(self.outdir, self.imagedir, dest)) except (IOError, OSError) as err: self.warn("cannot write image file %r: %s" % (path.join(self.srcdir, src), err))
def copy_stylesheet(app, exception=None): on_rtd = (os.environ.get('READTHEDOCS', None) == 'True') if not on_rtd and (app.builder.name != 'html' or exception): return # TODO: change _static to variable from config (something like that exists?) if on_rtd: base_path = os.path.join(app.builder.srcdir, '_static') else: base_path = os.path.join(app.builder.outdir, '_static') path = os.path.abspath(os.path.join(base_path, 'fancybox')) if not os.path.exists(path): os.makedirs(path) app.info('Copying fancybox stylesheets... ', nonl=True) for file in CSS_FILES: copyfile( os.path.join(os.path.dirname(__file__), file), os.path.join(base_path, file) ) app.info('done') app.info('Copying fancybox javascript... ', nonl=True) for file in JS_FILES: copyfile( os.path.join(os.path.dirname(__file__), file), os.path.join(base_path, file) ) app.info('done')
def copy_resources(self): """Copy supporting resources to the output folder.""" resource_iterator = status_iterator( self.resources.items(), "copying resources... ", "brown", len(self.resources), self.app.verbosity, stringify_func=lambda r: r[0], ) for dest, (op, value) in resource_iterator: logger.debug("[tutorial]: %s: (%s, %s)", dest, op, value) destination = pathlib.Path(self.outdir, dest) if not destination.parent.exists(): destination.parent.mkdir(parents=True) if op == "copy": copyfile(str(value), str(destination)) continue if op == "create": with destination.open("w") as f: f.write(value) continue raise TypeError(f"Unknown resource operation: '{op}'")
def handle_page(self, pagename, ctx, templatename='page.html', outfilename=None, event_arg=None): ctx['current_page_name'] = pagename self.add_sidebars(pagename, ctx) if not outfilename: outfilename = path.join(self.outdir, os_path(pagename) + self.out_suffix) self.app.emit('html-page-context', pagename, templatename, ctx, event_arg) ensuredir(path.dirname(outfilename)) f = open(outfilename, 'wb') try: self.implementation.dump(ctx, f, 2) finally: f.close() # if there is a source file, copy the source file for the # "show source" link if ctx.get('sourcename'): source_name = path.join(self.outdir, '_sources', os_path(ctx['sourcename'])) ensuredir(path.dirname(source_name)) copyfile(self.env.doc2path(pagename), source_name)
def copy_static_entry(source, targetdir, builder, context={}, exclude_matchers=(), level=0): """Copy a HTML builder static_path entry from source to targetdir. Handles all possible cases of files, directories and subdirectories. """ if exclude_matchers: relpath = relative_path(path.join(builder.srcdir, 'dummy'), source) for matcher in exclude_matchers: if matcher(relpath): return if path.isfile(source): target = path.join(targetdir, path.basename(source)) if source.lower().endswith('_t') and builder.templates: # templated! fsrc = open(source, 'r', encoding='utf-8') fdst = open(target[:-2], 'w', encoding='utf-8') fdst.write(builder.templates.render_string(fsrc.read(), context)) fsrc.close() fdst.close() else: copyfile(source, target) elif path.isdir(source): if not path.isdir(targetdir): os.mkdir(targetdir) for entry in os.listdir(source): if entry.startswith('.'): continue newtarget = targetdir if path.isdir(path.join(source, entry)): newtarget = path.join(targetdir, entry) copy_static_entry(path.join(source, entry), newtarget, builder, context, level=level+1, exclude_matchers=exclude_matchers)
def copy_static_entry(source, targetdir, builder, context={}, exclude_matchers=(), level=0): """Copy a HTML builder static_path entry from source to targetdir. Handles all possible cases of files, directories and subdirectories. """ if exclude_matchers: relpath = relative_path(builder.srcdir, source) for matcher in exclude_matchers: if matcher(relpath): return if path.isfile(source): target = path.join(targetdir, path.basename(source)) if source.lower().endswith('_t') and builder.templates: # templated! fsrc = open(source, 'r', encoding='utf-8') fdst = open(target[:-2], 'w', encoding='utf-8') fdst.write(builder.templates.render_string(fsrc.read(), context)) fsrc.close() fdst.close() else: copyfile(source, target) elif path.isdir(source): if level == 0: for entry in os.listdir(source): if entry.startswith('.'): continue copy_static_entry(path.join(source, entry), targetdir, builder, context, level=1, exclude_matchers=exclude_matchers) else: target = path.join(targetdir, path.basename(source)) if path.exists(target): shutil.rmtree(target) shutil.copytree(source, target)
def copy_asset_file(source, destination, context=None, renderer=None): # type: (unicode, unicode, Dict, BaseRenderer) -> None """Copy an asset file to destination. On copying, it expands the template variables if context argument is given and the asset is a template file. :param source: The path to source file :param destination: The path to destination file or directory :param context: The template variables. If not given, template files are simply copied :param renderer: The template engine. If not given, SphinxRenderer is used by default """ if not os.path.exists(source): return if os.path.exists(destination) and os.path.isdir(destination): # Use source filename if destination points a directory destination = os.path.join(destination, os.path.basename(source)) if source.lower().endswith('_t') and context: if renderer is None: from sphinx.util.template import SphinxRenderer renderer = SphinxRenderer() with codecs.open(source, 'r', encoding='utf-8') as fsrc: # type: ignore if destination.lower().endswith('_t'): destination = destination[:-2] with codecs.open(destination, 'w', encoding='utf-8') as fdst: # type: ignore fdst.write(renderer.render_string(fsrc.read(), context)) else: copyfile(source, destination)
def handle_page(self, pagename, ctx, templatename='page.html', outfilename=None, event_arg=None): ctx['current_page_name'] = pagename self.add_sidebars(pagename, ctx) if not outfilename: outfilename = path.join(self.outdir, os_path(pagename) + self.out_suffix) self.app.emit('html-page-context', pagename, templatename, ctx, event_arg) ensuredir(path.dirname(outfilename)) self.dump_context(ctx, outfilename) # if there is a source file, copy the source file for the # "show source" link if ctx.get('sourcename'): source_name = path.join(self.outdir, '_sources', os_path(ctx['sourcename'])) ensuredir(path.dirname(source_name)) copyfile(self.env.doc2path(pagename), source_name)
def finish(app, exception): if exception or app.builder.name != 'gettext': return # Copy our JS theme translations copyfile(os.path.join(PACKAGE_DIR, 'theme.pot'), os.path.join(app.builder.outdir, 'theme.pot'))
def copy_assets(app, exception): """ Copy asset files to the output """ if 'getLogger' in dir(logging): log = logging.getLogger(__name__).info # pylint: disable=no-member warn = logging.getLogger(__name__).warning # pylint: disable=no-member else: log = app.info warn = app.warning builders = get_compatible_builders(app) if exception: return if app.builder.name not in builders: if not app.config['sphinx_tabs_nowarn']: warn( 'Not copying tabs assets! Not compatible with %s builder' % app.builder.name) return log('Copying tabs assets') installdir = os.path.join(app.builder.outdir, '_static', 'sphinx_tabs') for path in FILES: source = resource_filename('sphinx_tabs', path) dest = os.path.join(installdir, path) destdir = os.path.dirname(dest) if not os.path.exists(destdir): os.makedirs(destdir) copyfile(source, dest)
def handle_page(self, pagename, ctx, templatename='page.html', outfilename=None, event_arg=None): # type: (str, Dict, str, str, Any) -> None ctx['current_page_name'] = pagename self.add_sidebars(pagename, ctx) if not outfilename: outfilename = path.join(self.outdir, os_path(pagename) + self.out_suffix) # we're not taking the return value here, since no template is # actually rendered self.app.emit('html-page-context', pagename, templatename, ctx, event_arg) # make context object serializable for key in list(ctx): if isinstance(ctx[key], types.FunctionType): del ctx[key] ensuredir(path.dirname(outfilename)) self.dump_context(ctx, outfilename) # if there is a source file, copy the source file for the # "show source" link if ctx.get('sourcename'): source_name = path.join(self.outdir, '_sources', os_path(ctx['sourcename'])) ensuredir(path.dirname(source_name)) copyfile(self.env.doc2path(pagename), source_name)
def install_collapse_static_files(app, env): STATICS_DIR_PATH = os.path.join(app.builder.outdir, STATICS_DIR_NAME) dest_path = os.path.join(STATICS_DIR_PATH, 'sphinx-needs') source_folder = os.path.join(os.path.dirname(__file__), "libs/html") files_to_copy = [os.path.join(source_folder, "sphinx_needs_collapse.js")] if parse_version(sphinx_version) < parse_version("1.6"): global status_iterator status_iterator = app.status_iterator for source_file_path in status_iterator( files_to_copy, 'Copying static files for sphinx-needs collapse support...', brown, len(files_to_copy)): if not os.path.isabs(source_file_path): raise IOError( "Path must be absolute. Got: {}".format(source_file_path)) if not os.path.exists(source_file_path): raise IOError("File not found: {}".format(source_file_path)) dest_file_path = os.path.join( dest_path, os.path.relpath(source_file_path, source_folder)) if not os.path.exists(os.path.dirname(dest_file_path)): ensuredir(os.path.dirname(dest_file_path)) copyfile(source_file_path, dest_file_path) safe_remove_file("sphinx-needs/libs/html/sphinx_needs_collapse.js", app) safe_add_file("sphinx-needs/libs/html/sphinx_needs_collapse.js", app)
def install_backend_static_files(app, env): STATICS_DIR_PATH = os.path.join(app.builder.outdir, STATICS_DIR_NAME) dest_path = os.path.join( STATICS_DIR_PATH, 'sphinxcontrib-images', app.sphinxcontrib_images_backend.__class__.__name__) files_to_copy = app.sphinxcontrib_images_backend.STATIC_FILES for source_file_path in status_iterator( files_to_copy, 'Copying static files for sphinxcontrib-images...', brown, len(files_to_copy)): dest_file_path = os.path.join(dest_path, source_file_path) if not os.path.exists(os.path.dirname(dest_file_path)): ensuredir(os.path.dirname(dest_file_path)) source_file_path = os.path.join( os.path.dirname(sys.modules[app.sphinxcontrib_images_backend. __class__.__module__].__file__), source_file_path) copyfile(source_file_path, dest_file_path) if dest_file_path.endswith('.js'): app.add_javascript( os.path.relpath(dest_file_path, STATICS_DIR_PATH)) elif dest_file_path.endswith('.css'): app.add_stylesheet( os.path.relpath(dest_file_path, STATICS_DIR_PATH))
def copy_assets(app, exception): """ Copy asset files to the output """ builders = ['html', 'singlehtml', 'dirhtml', 'readthedocs', 'readthedocsdirhtml', 'readthedocssinglehtml', 'readthedocssinglehtmllocalmedia', 'spelling'] builders.extend(app.config['sphinx_tabs_valid_builders']) if exception: return if app.builder.name not in builders: if not app.config['sphinx_tabs_nowarn']: app.warn( 'Not copying tabs assets! Not compatible with %s builder' % app.builder.name) return app.info('Copying tabs assets... ', nonl=True) installdir = os.path.join(app.builder.outdir, '_static', 'sphinx_tabs') for path in FILES: source = os.path.join(DIR, path) dest = os.path.join(installdir, path) destdir = os.path.dirname(dest) if not os.path.exists(destdir): os.makedirs(destdir) copyfile(source, dest) app.info('done')
def copy_assets(app, exception): """ Copy asset files to the output """ if "getLogger" in dir(logging): log = logging.getLogger(__name__).info # pylint: disable=no-member warn = logging.getLogger(__name__).warning # pylint: disable=no-member else: log = app.info warn = app.warning builders = get_compatible_builders(app) if exception: return if app.builder.name not in builders: if not app.config["sphinx_tabs_nowarn"]: warn("Not copying tabs assets! Not compatible with %s builder" % app.builder.name) return log("Copying tabs assets") installdir = Path(app.builder.outdir) / "_static" / "sphinx_tabs" for path in FILES: source = resource_filename("sphinx_tabs", path) dest = installdir / path destdir = dest.parent if not destdir.exists(): destdir.mkdir(parents=True) copyfile(source, dest)
def install_backend_static_files(app, env): STATICS_DIR_PATH = os.path.join(app.builder.outdir, STATICS_DIR_NAME) dest_path = os.path.join(STATICS_DIR_PATH, 'sphinxcontrib-images', app.sphinxcontrib_images_backend.__class__.__name__) files_to_copy = app.sphinxcontrib_images_backend.STATIC_FILES for source_file_path in app.builder.status_iterator( files_to_copy, 'Copying static files for sphinxcontrib-images...', brown, len(files_to_copy)): dest_file_path = os.path.join(dest_path, source_file_path) if not os.path.exists(os.path.dirname(dest_file_path)): ensuredir(os.path.dirname(dest_file_path)) source_file_path = os.path.join(os.path.dirname( sys.modules[app.sphinxcontrib_images_backend.__class__.__module__].__file__), source_file_path) copyfile(source_file_path, dest_file_path) if dest_file_path.endswith('.js'): app.add_javascript(os.path.relpath(dest_file_path, STATICS_DIR_PATH)) elif dest_file_path.endswith('.css'): app.add_stylesheet(os.path.relpath(dest_file_path, STATICS_DIR_PATH))
def install_lightbox_static_files(app): source_static_path = os.path.join(app.builder.srcdir, '_static') target_static_path = os.path.join(app.builder.outdir, '_static') source_lightbox_path = os.path.join(source_static_path, 'lightbox2') target_lightbox_path = os.path.join(target_static_path, 'lightbox2') relative_file_paths = [] for root, _, file_names in os.walk(source_lightbox_path): for file_name in file_names: absolute_file_path = os.path.join(root, file_name) relative_file_path = os.path.relpath( absolute_file_path, source_static_path, ) relative_file_paths.append(relative_file_path) if os.path.exists(target_lightbox_path): shutil.rmtree(target_lightbox_path) for relative_file_path in app.builder.status_iterator( relative_file_paths, 'installing lightbox files... ', brown, len(relative_file_paths), ): source_path = os.path.join(source_static_path, relative_file_path) target_path = os.path.join(target_static_path, relative_file_path) target_directory = os.path.dirname(target_path) if not os.path.exists(target_directory): ensuredir(target_directory) copyfile(source_path, target_path) if relative_file_path.endswith('.js'): app.add_javascript(relative_file_path) elif relative_file_path.endswith('.css'): app.add_stylesheet(relative_file_path)
def copy_assets(app, exception): """ Copy asset files to the output """ builders = ('html', 'readthedocs', 'readthedocssinglehtmllocalmedia', 'singlehtml') if app.builder.name not in builders: app.warn('Not copying tabs assets! Not compatible with %s builder' % app.builder.name) return if exception: app.warn('Not copying tabs assets! Error occurred previously') return app.info('Copying tabs assets... ', nonl=True) installdir = os.path.join(app.builder.outdir, '_static', 'sphinx_tabs') for path in FILES: source = os.path.join(DIR, path) dest = os.path.join(installdir, path) destdir = os.path.dirname(dest) if not os.path.exists(destdir): os.makedirs(destdir) copyfile(source, dest) app.info('done')
def install_static_files( app: Sphinx, source_dir: Path, destination_dir: Path, files_to_copy: Iterable[Path], message: str, ): # Do not copy static_files for our "needs" builder if app.builder.name == "needs": return for source_file_path in status_iterator( files_to_copy, message, brown, ): source_file = Path(source_file_path) if not source_file.is_absolute(): raise OSError(f"Path must be absolute. Got: {source_file}") if not source_file.exists(): raise OSError(f"File not found: {source_file}") relative_path = source_file.relative_to(source_dir) destination_file = destination_dir / relative_path destination_file.parent.mkdir(parents=True, exist_ok=True) copyfile(str(source_file), str(destination_file))
def handle_page(self, pagename, addctx, templatename='page.html', outfilename=None, event_arg=None): ctx = self.globalcontext.copy() # current_page_name is backwards compatibility ctx['pagename'] = ctx['current_page_name'] = pagename default_baseuri = self.get_target_uri(pagename) # in the singlehtml builder, default_baseuri still contains an #anchor # part, which relative_uri doesn't really like... default_baseuri = default_baseuri.rsplit('#', 1)[0] def pathto(otheruri, resource=False, baseuri=default_baseuri): if resource and '://' in otheruri: # allow non-local resources given by scheme return otheruri elif not resource: otheruri = self.get_target_uri(otheruri) uri = relative_uri(baseuri, otheruri) or '#' return uri ctx['pathto'] = pathto ctx['hasdoc'] = lambda name: name in self.env.all_docs if self.name != 'htmlhelp': ctx['encoding'] = encoding = self.config.html_output_encoding else: ctx['encoding'] = encoding = self.encoding ctx['toctree'] = lambda **kw: self._get_local_toctree(pagename, **kw) self.add_sidebars(pagename, ctx) ctx.update(addctx) newtmpl = self.app.emit_firstresult('html-page-context', pagename, templatename, ctx, event_arg) if newtmpl: templatename = newtmpl try: output = self.templates.render(templatename, ctx) except UnicodeError: self.warn("a Unicode error occurred when rendering the page %s. " "Please make sure all config values that contain " "non-ASCII content are Unicode strings." % pagename) return if not outfilename: outfilename = self.get_outfilename(pagename) # outfilename's path is in general different from self.outdir ensuredir(path.dirname(outfilename)) try: f = codecs.open(outfilename, 'w', encoding, 'xmlcharrefreplace') try: f.write(output) finally: f.close() except (IOError, OSError) as err: self.warn("error writing file %s: %s" % (outfilename, err)) if self.copysource and ctx.get('sourcename'): # copy the source file for the "show source" link source_name = path.join(self.outdir, '_sources', os_path(ctx['sourcename'])) ensuredir(path.dirname(source_name)) copyfile(self.env.doc2path(pagename), source_name)
def install_styles_static_files(app, env): STATICS_DIR_PATH = os.path.join(app.builder.outdir, IMAGE_DIR_NAME) dest_path = os.path.join(STATICS_DIR_PATH, 'sphinx-needs') files_to_copy = ["common.css"] if app.config.needs_css == 'modern.css': source_folder = os.path.join(os.path.dirname(__file__), "css/modern/") for root, dirs, files in os.walk(source_folder): for single_file in files: files_to_copy.append(os.path.join(root, single_file)) elif app.config.needs_css == 'dark.css': source_folder = os.path.join(os.path.dirname(__file__), "css/dark/") for root, dirs, files in os.walk(source_folder): for single_file in files: files_to_copy.append(os.path.join(root, single_file)) elif app.config.needs_css == 'blank.css': source_folder = os.path.join(os.path.dirname(__file__), "css/blank/") for root, dirs, files in os.walk(source_folder): for single_file in files: files_to_copy.append(os.path.join(root, single_file)) else: files_to_copy += [app.config.needs_css] # Be sure no "old" css layout is already set safe_remove_file("sphinx-needs/common.css", app) safe_remove_file("sphinx-needs/blank.css", app) safe_remove_file("sphinx-needs/modern.css", app) safe_remove_file("sphinx-needs/dark.css", app) if parse_version(sphinx_version) < parse_version("1.6"): global status_iterator status_iterator = app.status_iterator for source_file_path in status_iterator( files_to_copy, 'Copying static files for sphinx-needs custom style support...', brown, len(files_to_copy)): if not os.path.isabs(source_file_path): source_file_path = os.path.join(os.path.dirname(__file__), "css", source_file_path) if not os.path.exists(source_file_path): source_file_path = os.path.join(os.path.dirname(__file__), "css", "blank", "blank.css") logger.warning( "{0} not found. Copying sphinx-internal blank.css".format( source_file_path)) dest_file_path = os.path.join(dest_path, os.path.basename(source_file_path)) if not os.path.exists(os.path.dirname(dest_file_path)): ensuredir(os.path.dirname(dest_file_path)) copyfile(source_file_path, dest_file_path) safe_add_file(os.path.relpath(dest_file_path, STATICS_DIR_PATH), app)
def copy_stylesheet(app, exception): if app.builder.name != "html" or exception: return app.info(bold("Copying issuetracker stylesheet... "), nonl=True) dest = path.join(app.builder.outdir, "_static", "issuetracker.css") source = path.join(path.abspath(path.dirname(__file__)), "issuetracker.css") copyfile(source, dest) app.info("done")
def on_html_coolect_pages(app): """on copy static files""" app.info(' rstdemo', nonl=1) ensuredir(path.join(app.outdir, '_static')) for f in os.listdir(STATICDIR): copyfile(path.join(STATICDIR, f), path.join(app.outdir, '_static', f)) return [] #no pages
def copy_assets(app, exception): if app.builder.name != 'html' or exception: return app.info('Copying examplecode stylesheet/javascript... ', nonl=True) dest = os.path.join(app.builder.outdir, '_static', JS_FILE) source = os.path.join(os.path.abspath(os.path.dirname(__file__)), JS_FILE) copyfile(source, dest) app.info('done')
def copy_stylesheet(app, exception): if app.builder.name != 'html' or exception: return app.info('Copying requirements stylesheet... ', nonl=True) dest = os.path.join(app.builder.outdir, '_static', CSS_FILE) source = os.path.join(os.path.abspath(os.path.dirname(__file__)), CSS_FILE) copyfile(source, dest) app.info('done')
def copy_assets(app, exception): if app.builder.name != "html" or exception: return logger.info("Copying examplecode stylesheet/javascript... ", nonl=True) dest = os.path.join(app.builder.outdir, "_static", JS_FILE) source = os.path.join(os.path.abspath(os.path.dirname(__file__)), JS_FILE) copyfile(source, dest) logger.info("done")
def copy_stylesheet(app, exception): if app.builder.name != 'html' or exception: return app.info(bold('Copying issuetracker stylesheet... '), nonl=True) dest = path.join(app.builder.outdir, '_static', 'issuetracker.css') source = path.join(path.abspath(path.dirname(__file__)), 'issuetracker.css') copyfile(source, dest) app.info('done')
def finish(self, *args, **kwargs): super(CustomLaTeXBuilder, self).finish(*args, **kwargs) # copy additional files again *after* tex support files so we can override them! if self.config.latex_additional_files: self.info(bold("copying additional files again..."), nonl=1) for filename in self.config.latex_additional_files: self.info(" " + filename, nonl=1) copyfile(os.path.join(self.confdir, filename), os.path.join(self.outdir, os.path.basename(filename))) self.info()
def copy_assets(app, exception): if app.builder.name not in ['html', 'readthedocs'] or exception: return logger = logging.getLogger(__name__) logger.info('Copying multicol stylesheet... ', nonl=True) dest = os.path.join(app.builder.outdir, '_static', CSS_FILE) source = os.path.join(os.path.abspath(os.path.dirname(__file__)), CSS_FILE) copyfile(source, dest) logger.info('done')
def copy_assets(app, exception): assets = ['support-matrix.css', 'support-matrix.js'] if app.builder.name != 'html' or exception: return app.info('Copying assets: %s' % ', '.join(assets)) for asset in assets: dest = os.path.join(app.builder.outdir, '_static', asset) source = os.path.abspath(os.path.dirname(__file__)) copyfile(os.path.join(source, 'assets', asset), dest)
def copy_assets(app, exception): assets = ['support-matrix.css', 'support-matrix.js'] if app.builder.name != 'html' or exception: return LOG.info('Copying assets: %s' % ', '.join(assets)) for asset in assets: dest = os.path.join(app.builder.outdir, '_static', asset) source = os.path.abspath(os.path.dirname(__file__)) copyfile(os.path.join(source, 'assets', asset), dest)
def copy_stylesheet(app, exception): if app.builder.name != 'html' or exception: return stylesheet = app.config.html_ansi_stylesheet if stylesheet: app.info(bold('Copying ansi stylesheet... ')) dest = path.join(app.builder.outdir, '_static', 'ansi.css') source = path.abspath(path.dirname(__file__)) copyfile(path.join(source, stylesheet), dest) app.info('done')
def copy_image_files(self): # copy image files if self.images: ensuredir(path.join(self.outdir, "_images")) for src in self.status_iterator(self.images, "copying images... ", brown, len(self.images)): dest = self.images[src] try: copyfile(path.join(self.srcdir, src), path.join(self.outdir, "_images", dest)) except Exception, err: self.warn("cannot copy image file %r: %s" % (path.join(self.srcdir, src), err))
def finish_latex(app, exception): if exception is None and app.env.bibtex_path and \ isinstance(app.builder, LaTeXBuilder): app.info(bold("copying BibTeX file..."), nonl=1) src = app.env.bibtex_path dst = os.path.join(app.builder.outdir, os.path.basename(src)) copyfile(src, dst) app.info('done')
def finish(self): # copy image files if self.images: self.info(bold('copying images...'), nonl=1) for src, dest in self.images.iteritems(): self.info(' ' + src, nonl=1) dest_file = os.path.join(self.outdir, dest) copyfile(os.path.join(self.srcdir, src), dest_file) self.info() print "FIN"
def copy_static_files(app, _): # because we're using the extension system instead of the theme system, # it's our responsibility to copy over static files outselves. files = ['js/searchbox.js', 'css/searchbox.css'] for f in files: src = join(dirname(__file__), f) dest = join(app.outdir, '_static', f) if not exists(dirname(dest)): os.makedirs(dirname(dest)) copyfile(src, dest)
def copy_stylesheet(app, exception): if app.builder.name != "html" or exception: return stylesheet = app.config.html_ansi_stylesheet if stylesheet: app.info(bold("Copying ansi stylesheet... "), nonl=True) dest = path.join(app.builder.outdir, "_static", "ansi.css") source = path.abspath(path.dirname(__file__)) copyfile(path.join(source, stylesheet), dest) app.info("done")
def finish(self, *args, **kwargs): super(CustomLaTeXBuilder, self).finish(*args, **kwargs) # copy additional files again *after* tex support files so we can override them! if self.config.latex_additional_files: self.info(bold('copying additional files again...'), nonl=1) for filename in self.config.latex_additional_files: self.info(' ' + filename, nonl=1) copyfile(os.path.join(self.confdir, filename), os.path.join(self.outdir, os.path.basename(filename))) self.info()
def copy_assets(app, exception=None): if app.builder.name != 'html' or exception: return dest = os.path.join(app.builder.outdir, '_static/codeexample.css') source = os.path.join(os.path.abspath(os.path.dirname(__file__)), "_static/codeexample.css") copyfile(source, dest) dest = os.path.join(app.builder.outdir, '_static/codeexample.js') source = os.path.join(os.path.abspath(os.path.dirname(__file__)), "_static/codeexample.js") copyfile(source, dest)
def finish(self): # copy image files if self.images: self.info(bold('copying images...'), nonl=1) for src, dest in self.images.iteritems(): self.info(' '+src, nonl=1) dest_file = os.path.join(self.outdir, dest) copyfile(os.path.join(self.srcdir, src), dest_file) self.info() print "FIN"
def render(app): for ctx in app.config.redoc: # Setup options if they are not passed since 'redoc.j2' template # relies on them. ctx.setdefault('opts', {}) template_file = ctx.get('template') if template_file is not None: with io.open(template_file, encoding='utf-8') as f: template = jinja2.Template(f.read()) # In embed mode, we are going to embed the whole OpenAPI spec into # produced HTML. The rationale is very simple: we want to produce # browsable HTMLs ready to be used without any web server. if ctx.get('embed') is True: # Parse & dump the spec to have it as properly formatted json specfile = os.path.join(app.confdir, ctx['spec']) with io.open(specfile, encoding='utf-8') as specfp: try: spec_contents = yaml.load(specfp) except ValueError as ver: raise ValueError('Cannot parse spec %r: %s' % (ctx['spec'], ver)) ctx['spec'] = json.dumps(spec_contents) # The 'spec' may contain either HTTP(s) link or filesystem path. In # case of later we need to copy the spec into output directory, as # otherwise it won't be available when the result is deployed. elif not ctx['spec'].startswith(('http', 'https')): specpath = os.path.join(app.builder.outdir, '_specs') specname = os.path.basename(ctx['spec']) ensuredir(specpath) copyfile( # Since the path may be relative it should be joined with # base URI which is a path of directory with conf.py in # our case. os.path.join(app.confdir, ctx['spec']), os.path.join(specpath, specname)) # The link inside the rendered document must refer to a new # location, the place where it has been copied to. ctx['spec'] = os.path.join('_specs', specname) # Propagate information about page rendering to Sphinx. There's # a little trick in here: we pass an actual Jinja2 template instance # instead of template name. This is passible due to Jinja2 API where # we can pass a template instance to Jinja2 environment and so on. # Such little trick allows us to avoid other hacks which require # manipulating of Sphinx's 'templates_path' option. yield ctx['page'], ctx, template
def copy_assets(app, exception): if app.builder.name != 'html' or exception: return app.info('Copying examplecode stylesheet/javascript... ', nonl=True) dest = os.path.join(app.builder.outdir, '_static', CSS_FILE) source = os.path.join(os.path.abspath(os.path.dirname(__file__)), CSS_FILE) copyfile(source, dest) dest = os.path.join(app.builder.outdir, '_static', JS_FILE) source = os.path.join(os.path.abspath(os.path.dirname(__file__)), JS_FILE) copyfile(source, dest) app.info('done')
def copy_assets(app, exception): if app.builder.name != "html" or exception: return app.info("Copying osexample stylesheet/javascript... ", nonl=True) dest = os.path.join(app.builder.outdir, "_static", CSS_FILE) source = os.path.join(os.path.abspath(os.path.dirname(__file__)), CSS_FILE) copyfile(source, dest) dest = os.path.join(app.builder.outdir, "_static", JS_FILE) source = os.path.join(os.path.abspath(os.path.dirname(__file__)), JS_FILE) copyfile(source, dest) app.info("done")
def copy_assets(app, exception): if app.builder.name not in ['html', 'readthedocs'] or exception: return app.info('Copying contentui stylesheet/javascript... ', nonl=True) dest = os.path.join(app.builder.outdir, '_static', CSS_FILE) source = os.path.join(os.path.abspath(os.path.dirname(__file__)), CSS_FILE) copyfile(source, dest) dest = os.path.join(app.builder.outdir, '_static', JS_FILE) source = os.path.join(os.path.abspath(os.path.dirname(__file__)), JS_FILE) copyfile(source, dest) app.info('done')
def copy_download_files(self): # copy downloadable files if self.env.dlfiles: ensuredir(path.join(self.outdir, "_downloads")) for src in self.status_iterator( self.env.dlfiles, "copying downloadable files... ", brown, len(self.env.dlfiles) ): dest = self.env.dlfiles[src][1] try: copyfile(path.join(self.srcdir, src), path.join(self.outdir, "_downloads", dest)) except Exception, err: self.warn("cannot copy downloadable file %r: %s" % (path.join(self.srcdir, src), err))
def copy_image_files(self): # copy image files if self.images: for src in self.status_iterator(self.images, 'copying images... ', brown, len(self.images)): dest = path.join(self.outdir, src) ensuredir(path.dirname(dest)) try: copyfile(path.join(self.srcdir, src), dest) except Exception, err: self.warn('cannot copy image file %r: %s' % (path.join(self.srcdir, src), err))
def copy_static_files(app, exception): if app.builder.name != "html" or exception: return base_directory = os.path.dirname(__file__) static_directory = os.path.join(base_directory, "static") for filename in os.listdir(static_directory): source_path = os.path.join(static_directory, filename) destination_path = os.path.join(app.builder.outdir, "_static", filename) copyfile(source_path, destination_path)
def copy_image_files(self): # copy image files if self.images: ensuredir(path.join(self.outdir, self.imagedir)) for src in self.app.status_iterator(self.images, 'copying images... ', brown, len(self.images)): dest = self.images[src] try: copyfile(path.join(self.srcdir, src), path.join(self.outdir, self.imagedir, dest)) except Exception as err: self.warn('cannot copy image file %r: %s' % (path.join(self.srcdir, src), err))