def copy_media(app, exception):
    """ Move our dynamically generated files after build. """
    if app.builder.name in ['readthedocs', 'readthedocsdirhtml'
                            ] and not exception:
        for file in [
                'readthedocs-dynamic-include.js_t', 'readthedocs-data.js_t',
                'searchtools.js_t'
        ]:
            app.info(bold('Copying %s... ' % file), nonl=True)
            dest_dir = os.path.join(app.builder.outdir, '_static')
            source = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                  '_static', file)
            try:
                ctx = app.builder.globalcontext
            except AttributeError:
                ctx = {}
            if app.builder.indexer is not None:
                ctx.update(app.builder.indexer.context_for_searchtool())
            copy_static_entry(source, dest_dir, app.builder, ctx)
            app.info('done')

    if 'comments' in app.builder.name and not exception:
        for file in STATIC_FILES:
            app.info(bold('Copying %s... ' % file), nonl=True)
            dest_dir = os.path.join(app.builder.outdir, '_static')
            source = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                  '_static', file)
            try:
                ctx = app.builder.globalcontext
            except AttributeError:
                ctx = {}
            ctx['websupport2_base_url'] = app.builder.config.websupport2_base_url
            ctx['websupport2_static_url'] = app.builder.config.websupport2_static_url
            copy_static_entry(source, dest_dir, app.builder, ctx)
            app.info('done')
def copy_media(app, exception):
    """ Move our dynamically generated files after build. """
    if app.builder.name in ["readthedocs", "readthedocsdirhtml"] and not exception:
        for file in ["readthedocs-dynamic-include.js_t", "readthedocs-data.js_t", "searchtools.js_t"]:
            app.info(bold("Copying %s... " % file), nonl=True)
            dest_dir = os.path.join(app.builder.outdir, "_static")
            source = os.path.join(os.path.abspath(os.path.dirname(__file__)), "_static", file)
            try:
                ctx = app.builder.globalcontext
            except AttributeError:
                ctx = {}
            if app.builder.indexer is not None:
                ctx.update(app.builder.indexer.context_for_searchtool())
            copy_static_entry(source, dest_dir, app.builder, ctx)
            app.info("done")

    if "comments" in app.builder.name and not exception:
        for file in STATIC_FILES:
            app.info(bold("Copying %s... " % file), nonl=True)
            dest_dir = os.path.join(app.builder.outdir, "_static")
            source = os.path.join(os.path.abspath(os.path.dirname(__file__)), "_static", file)
            try:
                ctx = app.builder.globalcontext
            except AttributeError:
                ctx = {}
            ctx["websupport2_base_url"] = app.builder.config.websupport2_base_url
            ctx["websupport2_static_url"] = app.builder.config.websupport2_static_url
            copy_static_entry(source, dest_dir, app.builder, ctx)
            app.info("done")
 def copy_static_readthedocs_files(self):
     log.info(bold('copying readthedocs static files... '), nonl=True)
     for filename in self.static_readthedocs_files:
         path_dest = os.path.join(self.outdir, '_static')
         path_src = os.path.join(
             os.path.abspath(os.path.dirname(__file__)),
             '_static',
             filename
         )
         ctx = self.get_static_readthedocs_context()
         if sphinx.version_info < (1, 5):
             copy_static_entry(
                 path_src,
                 path_dest,
                 self,
                 context=ctx,
             )
         else:
             copy_asset(
                 path_src,
                 path_dest,
                 context=ctx,
                 renderer=self.templates
             )
     log.info('done')
Exemple #4
0
    def copy_static_files(self):
        # copy static files
        self.info(bold('copying static files... '), nonl=True)
        ensuredir(path.join(self.outdir, '_static'))
        # first, create pygments style file
        f = open(path.join(self.outdir, '_static', 'pygments.css'), 'w')
        f.write(self.highlighter.get_stylesheet())
        f.close()
        # then, copy translations JavaScript file
        if self.config.language is not None:
            jsfile = self._get_translations_js()
            if jsfile:
                copyfile(jsfile,
                         path.join(self.outdir, '_static', 'translations.js'))

        # add context items for search function used in searchtools.js_t
        ctx = self.globalcontext.copy()
        ctx.update(self.indexer.context_for_searchtool())

        # then, copy over theme-supplied static files
        if self.theme:
            themeentries = [
                path.join(themepath, 'static')
                for themepath in self.theme.get_dirchain()[::-1]
            ]
            for entry in themeentries:
                copy_static_entry(entry, path.join(self.outdir, '_static'),
                                  self, ctx)
        # then, copy over all user-supplied static files
        staticentries = [
            path.join(self.confdir, spath)
            for spath in self.config.html_static_path
        ]
        matchers = compile_matchers(
            self.config.exclude_patterns +
            ['**/' + d for d in self.config.exclude_dirnames])
        for entry in staticentries:
            if not path.exists(entry):
                self.warn('html_static_path entry %r does not exist' % entry)
                continue
            copy_static_entry(entry,
                              path.join(self.outdir, '_static'),
                              self,
                              ctx,
                              exclude_matchers=matchers)
        # copy logo and favicon files if not already in static path
        if self.config.html_logo:
            logobase = path.basename(self.config.html_logo)
            logotarget = path.join(self.outdir, '_static', logobase)
            if not path.isfile(logotarget):
                copyfile(path.join(self.confdir, self.config.html_logo),
                         logotarget)
        if self.config.html_favicon:
            iconbase = path.basename(self.config.html_favicon)
            icontarget = path.join(self.outdir, '_static', iconbase)
            if not path.isfile(icontarget):
                copyfile(path.join(self.confdir, self.config.html_favicon),
                         icontarget)
        self.info('done')
Exemple #5
0
    def copy_static_files(self):
        # copy static files
        self.info(bold('copying static files... '), nonl=True)
        ensuredir(path.join(self.outdir, '_static'))
        # first, create pygments style file
        f = open(path.join(self.outdir, '_static', 'pygments.css'), 'w')
        f.write(self.highlighter.get_stylesheet())
        f.close()
        # then, copy translations JavaScript file
        if self.config.language is not None:
            jsfile = self._get_translations_js()
            if jsfile:
                copyfile(jsfile, path.join(self.outdir, '_static',
                                           'translations.js'))

        # add context items for search function used in searchtools.js_t
        ctx = self.globalcontext.copy()
        ctx.update(self.indexer.context_for_searchtool())

        # then, copy over theme-supplied static files
        if self.theme:
            themeentries = [path.join(themepath, 'static')
                            for themepath in self.theme.get_dirchain()[::-1]]
            for entry in themeentries:
                copy_static_entry(entry, path.join(self.outdir, '_static'),
                                  self, ctx)
        # then, copy over all user-supplied static files
        staticentries = [path.join(self.confdir, spath)
                         for spath in self.config.html_static_path]
        matchers = compile_matchers(
            self.config.exclude_patterns +
            ['**/' + d for d in self.config.exclude_dirnames]
        )
        for entry in staticentries:
            if not path.exists(entry):
                self.warn('html_static_path entry %r does not exist' % entry)
                continue
            copy_static_entry(entry, path.join(self.outdir, '_static'), self,
                              ctx, exclude_matchers=matchers)
        # copy logo and favicon files if not already in static path
        if self.config.html_logo:
            logobase = path.basename(self.config.html_logo)
            logotarget = path.join(self.outdir, '_static', logobase)
            if not path.isfile(path.join(self.confdir, self.config.html_logo)):
                self.warn('logo file %r does not exist' % self.config.html_logo)
            elif not path.isfile(logotarget):
                copyfile(path.join(self.confdir, self.config.html_logo),
                         logotarget)
        if self.config.html_favicon:
            iconbase = path.basename(self.config.html_favicon)
            icontarget = path.join(self.outdir, '_static', iconbase)
            if not path.isfile(path.join(self.confdir, self.config.html_favicon)):
                self.warn('favicon file %r does not exist' % self.config.html_favicon)
            elif not path.isfile(icontarget):
                copyfile(path.join(self.confdir, self.config.html_favicon),
                         icontarget)
        self.info('done')
def build_finished(app, exception):
    """
    When the build is finished, we copy the javascript files (if specified)
    to the build directory (the static folder)
    """
    if app.config.offline_skin_js_path is not None:
        copy_static_entry(path.join(app.builder.srcdir, app.config.offline_skin_js_path), path.join(app.builder.outdir, '_static'), app.builder)
    if app.config.offline_wavedrom_js_path is not None:
        copy_static_entry(path.join(app.builder.srcdir, app.config.offline_wavedrom_js_path), path.join(app.builder.outdir, '_static'), app.builder)
Exemple #7
0
 def copy_extra_files(self):
     # copy html_extra_path files
     self.info(bold('copying extra files... '), nonl=True)
     extraentries = [path.join(self.confdir, epath)
                     for epath in self.config.html_extra_path]
     for entry in extraentries:
         if not path.exists(entry):
             self.warn('html_extra_path entry %r does not exist' % entry)
             continue
         copy_static_entry(entry, self.outdir, self)
def copy_media(app, exception):
    if app.builder.name != "readthedocs" or exception:
        return
    for file in ["readthedocs-ext.js_t"]:
        app.info(bold("Copying %s... " % file), nonl=True)
        dest_dir = os.path.join(app.builder.outdir, "_static")
        source = os.path.join(os.path.abspath(os.path.dirname(__file__)), "_static", file)
        ctx = app.builder.globalcontext
        copy_static_entry(source, dest_dir, app.builder, ctx)
        app.info("done")
Exemple #9
0
 def copy_extra_files(self):
     # copy html_extra_path files
     self.info(bold('copying extra files... '), nonl=True)
     extraentries = [path.join(self.confdir, epath)
                     for epath in self.config.html_extra_path]
     for entry in extraentries:
         if not path.exists(entry):
             self.warn('html_extra_path entry %r does not exist' % entry)
             continue
         copy_static_entry(entry, self.outdir, self)
     self.info('done')
def build_finished(app, exception):
    """
    When the build is finished, we copy the javascript files (if specified)
    to the build directory (the static folder)
    """
    # Skip for non-html or if javascript is not inlined
    if not app.env.config.wavedrom_html_jsinline:
        return

    if app.config.offline_skin_js_path is not None:
        copy_static_entry(path.join(app.builder.srcdir, app.config.offline_skin_js_path), path.join(app.builder.outdir, '_static'), app.builder)
    if app.config.offline_wavedrom_js_path is not None:
        copy_static_entry(path.join(app.builder.srcdir, app.config.offline_wavedrom_js_path), path.join(app.builder.outdir, '_static'), app.builder)
def copy_static_theme_files(self):
    # then, copy over theme-supplied static files
    for theme, options, templates in self.multithemes.values():
        ctx = self.globalcontext.copy()
        ctx.update(self.indexer.context_for_searchtool())
        ctx.update(theme_context(theme, options))

        themeentries = [path.join(themepath, 'static')
                        for themepath in theme.get_dirchain()[::-1]]
        theme_static_dir = path.join(self.outdir, '_static', theme.name)
        if not path.exists(theme_static_dir):
            makedirs(theme_static_dir)
        for entry in themeentries:
            copy_static_entry(entry, theme_static_dir, self, ctx)
def copy_media(app, exception):
    if app.builder.name != 'readthedocs' or exception:
        return
    for file in ['readthedocs-ext.js_t']:
        app.info(bold('Copying %s... ' % file), nonl=True)
        dest_dir = os.path.join(app.builder.outdir, '_static')
        source = os.path.join(
            os.path.abspath(os.path.dirname(__file__)), 
            '_static', 
            file
        )
        ctx = app.builder.globalcontext
        copy_static_entry(source, dest_dir, app.builder, ctx)
        app.info('done')
Exemple #13
0
    def copy_localized_files(self):
        source_dir = path.join(self.confdir,
                               self.config.applehelp_locale + '.lproj')
        target_dir = self.outdir

        if path.isdir(source_dir):
            self.info(bold('copying localized files... '), nonl=True)

            ctx = self.globalcontext.copy()
            matchers = compile_matchers(self.config.exclude_patterns)
            copy_static_entry(source_dir, target_dir, self, ctx,
                              exclude_matchers=matchers)

            self.info('done')
    def copy_localized_files(self):
        source_dir = path.join(self.confdir,
                               self.config.applehelp_locale + '.lproj')
        target_dir = self.outdir

        if path.isdir(source_dir):
            self.info(bold('copying localized files... '), nonl=True)

            ctx = self.globalcontext.copy()
            matchers = compile_matchers(self.config.exclude_patterns)
            copy_static_entry(source_dir, target_dir, self, ctx,
                              exclude_matchers=matchers)

            self.info('done')
Exemple #15
0
        def copy_visual_placeholder(self):
            """
            based on builders.html.copy_image_files

            :param sphinx.builders.Builder self:
            """

            outdir = path.join(self.outdir, self.imagedir)
            ensuredir(outdir)
            source = path.join(package_dir, 'theme', 'default', 'static', 'FFFFFF-0.png')
            try:
                copy_static_entry(source, outdir, self)
            except Exception as err:
                self.warn('cannot copy image file %r: %s' %
                          (source, err))
Exemple #16
0
    def copy_static_files(self):

        result = super(AbstractSlideBuilder, self).copy_static_files()

        # add context items for search function used in searchtools.js_t
        ctx = self.globalcontext.copy()
        ctx.update(self.indexer.context_for_searchtool())

        for theme in self._additional_themes[1:]:

            themeentries = [os.path.join(themepath, "static") for themepath in theme.get_dirchain()[::-1]]
            for entry in themeentries:
                copy_static_entry(entry, os.path.join(self.outdir, "_static"), self, ctx)

        return result
def copy_media(app, exception):
    if app.builder.name != 'websupport2' or exception:
        return
    for file in STATIC_FILES:
        app.info(bold('Copying %s... ' % file), nonl=True)
        dest_dir = os.path.join(app.builder.outdir, '_static')
        source = os.path.join(
            os.path.abspath(os.path.dirname(__file__)), 
            '_static', 
            file
        )
        ctx = app.builder.globalcontext
        ctx['websupport2_base_url'] = app.builder.config.websupport2_base_url
        ctx['websupport2_static_url'] = app.builder.config.websupport2_static_url
        copy_static_entry(source, dest_dir, app.builder, ctx)
        app.info('done')
Exemple #18
0
    def copy_static_files(self):
        # copy static files
        self.info(bold("copying static files... "), nonl=True)
        ensuredir(path.join(self.outdir, "_static"))

        ctx = self.globalcontext.copy()

        # copy over all user-supplied static files
        staticentries = [path.join(self.confdir, spath) for spath in self.config.html_static_path]
        matchers = compile_matchers(self.config.exclude_patterns)
        for entry in staticentries:
            if not path.exists(entry):
                self.warn("html_static_path entry %r does not exist" % entry)
                continue
            copy_static_entry(entry, path.join(self.outdir, "_static"), self, ctx, exclude_matchers=matchers)
        self.info("done")
Exemple #19
0
def build_finished(app, exception):
    """
    When the build is finished, we copy the javascript files (if specified)
    to the build directory (the static folder)
    """
    # Skip for non-html or if javascript is not inlined
    if not app.env.config.wavedrom_html_jsinline:
        return

    if app.config.offline_skin_js_path is not None:
        copy_static_entry(
            path.join(app.builder.srcdir, app.config.offline_skin_js_path),
            path.join(app.builder.outdir, '_static'), app.builder)
    if app.config.offline_wavedrom_js_path is not None:
        copy_static_entry(
            path.join(app.builder.srcdir, app.config.offline_wavedrom_js_path),
            path.join(app.builder.outdir, '_static'), app.builder)
Exemple #20
0
    def copy_static_files(self):

        result = super(AbstractSlideBuilder, self).copy_static_files()

        # add context items for search function used in searchtools.js_t
        ctx = self.globalcontext.copy()
        ctx.update(self.indexer.context_for_searchtool())

        for theme in self._additional_themes[1:]:

            themeentries = [os.path.join(themepath, 'static')
                            for themepath in theme.get_theme_dirs()[::-1]]
            for entry in themeentries:
                copy_static_entry(entry, os.path.join(self.outdir, '_static'),
                                  self, ctx)

        return result
Exemple #21
0
 def copy_static_files(self):
     # copy static files
     self.info(bold("copying static files... "), nonl=True)
     ensuredir(path.join(self.outdir, "_static"))
     # first, create pygments style file
     f = open(path.join(self.outdir, "_static", "pygments.css"), "w")
     f.write(self.highlighter.get_stylesheet())
     f.close()
     # then, copy translations JavaScript file
     if self.config.language is not None:
         jsfile_list = [
             path.join(package_dir, "locale", self.config.language, "LC_MESSAGES", "sphinx.js"),
             path.join(sys.prefix, "share/sphinx/locale", self.config.language, "sphinx.js"),
         ]
         for jsfile in jsfile_list:
             if path.isfile(jsfile):
                 copyfile(jsfile, path.join(self.outdir, "_static", "translations.js"))
                 break
     # then, copy over theme-supplied static files
     if self.theme:
         themeentries = [path.join(themepath, "static") for themepath in self.theme.get_dirchain()[::-1]]
         for entry in themeentries:
             copy_static_entry(entry, path.join(self.outdir, "_static"), self, self.globalcontext)
     # then, copy over all user-supplied static files
     staticentries = [path.join(self.confdir, spath) for spath in self.config.html_static_path]
     matchers = compile_matchers(self.config.exclude_patterns + ["**/" + d for d in self.config.exclude_dirnames])
     for entry in staticentries:
         if not path.exists(entry):
             self.warn("html_static_path entry %r does not exist" % entry)
             continue
         copy_static_entry(
             entry, path.join(self.outdir, "_static"), self, self.globalcontext, exclude_matchers=matchers
         )
     # copy logo and favicon files if not already in static path
     if self.config.html_logo:
         logobase = path.basename(self.config.html_logo)
         logotarget = path.join(self.outdir, "_static", logobase)
         if not path.isfile(logotarget):
             copyfile(path.join(self.confdir, self.config.html_logo), logotarget)
     if self.config.html_favicon:
         iconbase = path.basename(self.config.html_favicon)
         icontarget = path.join(self.outdir, "_static", iconbase)
         if not path.isfile(icontarget):
             copyfile(path.join(self.confdir, self.config.html_favicon), icontarget)
     self.info("done")
Exemple #22
0
    def copy_static_files(self):
        # copy static files
        self.info(bold('copying static files... '), nonl=True)
        ensuredir(path.join(self.outdir, '_static'))

        ctx = self.globalcontext.copy()

        # copy over all user-supplied static files
        staticentries = [path.join(self.confdir, spath)
                         for spath in self.config.html_static_path]
        matchers = compile_matchers(self.config.exclude_patterns)
        for entry in staticentries:
            if not path.exists(entry):
                self.warn('html_static_path entry %r does not exist' % entry)
                continue
            copy_static_entry(entry, path.join(self.outdir, '_static'), self,
                              ctx, exclude_matchers=matchers)
        self.info('done')
Exemple #23
0
def html_visit_chefserver(self, node):
  """
  This function generates html content from:
    - Mustache template file
    - Chef infos
  """
  # Gets sources
  content = node.content(self.builder)

  # Generate html content
  loader=jinja2.FileSystemLoader(self.builder.config.chefserver_templates)
  env=jinja2.Environment(loader=loader)
  template=env.get_template(node.config.get('filename', self.builder.config.chefserver_default_template)+'.html')
  html = template.render(content=content)
  self.body.append(html)

  # Copy css file
  for file in self.builder.config.chefserver_css_files:
    copy_static_entry(path.join(self.builder.config.chefserver_css_path, file),
      path.join(self.builder.outdir, '_static'),
      self.builder)
    self.builder.css_files.append(path.join('_static', file))

  raise nodes.SkipNode
Exemple #24
0
            staticdirnames = [path.join(themepath, 'static')
                              for themepath in self.theme.get_dirchain()[::-1]]
        else:
            staticdirnames = []
        staticdirnames += [path.join(self.confdir, spath)
                           for spath in self.config.html_static_path]
        for staticdirname in staticdirnames:
            if not path.isdir(staticdirname):
                self.warn('static directory %r does not exist' % staticdirname)
                continue
            for filename in os.listdir(staticdirname):
                if filename.startswith('.'):
                    continue
                fullname = path.join(staticdirname, filename)
                targetname = path.join(self.outdir, '_static', filename)
                copy_static_entry(fullname, targetname, self,
                                  self.globalcontext)
        # last, copy logo file (handled differently)
        if self.config.html_logo:
            logobase = path.basename(self.config.html_logo)
            copyfile(path.join(self.confdir, self.config.html_logo),
                     path.join(self.outdir, '_static', logobase))

        # write build info file
        fp = open(path.join(self.outdir, '.buildinfo'), 'w')
        try:
            fp.write('# Sphinx build info version 1\n'
                     '# This file hashes the configuration used when building'
                     ' these files. When it is not found, a full rebuild will'
                     ' be done.\nconfig: %s\ntags: %s\n' %
                     (self.config_hash, self.tags_hash))
        finally:
    def write(self, *ignored):
        version = self.config.version
        libchanges = {}
        apichanges = []
        otherchanges = {}
        if version not in self.env.versionchanges:
            self.info(bold('no changes in version %s.' % version))
            return
        self.info(bold('writing summary file...'))
        for type, docname, lineno, module, descname, content in \
                self.env.versionchanges[version]:
            if isinstance(descname, tuple):
                descname = descname[0]
            ttext = self.typemap[type]
            context = content.replace('\n', ' ')
            if descname and docname.startswith('c-api'):
                if not descname:
                    continue
                if context:
                    entry = '<b>%s</b>: <i>%s:</i> %s' % (descname, ttext,
                                                          context)
                else:
                    entry = '<b>%s</b>: <i>%s</i>.' % (descname, ttext)
                apichanges.append((entry, docname, lineno))
            elif descname or module:
                if not module:
                    module = _('Builtins')
                if not descname:
                    descname = _('Module level')
                if context:
                    entry = '<b>%s</b>: <i>%s:</i> %s' % (descname, ttext,
                                                          context)
                else:
                    entry = '<b>%s</b>: <i>%s</i>.' % (descname, ttext)
                libchanges.setdefault(module, []).append((entry, docname,
                                                          lineno))
            else:
                if not context:
                    continue
                entry = '<i>%s:</i> %s' % (ttext.capitalize(), context)
                title = self.env.titles[docname].astext()
                otherchanges.setdefault((docname, title), []).append(
                    (entry, docname, lineno))

        ctx = {
            'project': self.config.project,
            'version': version,
            'docstitle': self.config.html_title,
            'shorttitle': self.config.html_short_title,
            'libchanges': sorted(iteritems(libchanges)),
            'apichanges': sorted(apichanges),
            'otherchanges': sorted(iteritems(otherchanges)),
            'show_copyright': self.config.html_show_copyright,
            'show_sphinx': self.config.html_show_sphinx,
        }
        f = codecs.open(path.join(self.outdir, 'index.html'), 'w', 'utf8')
        try:
            f.write(self.templates.render('changes/frameset.html', ctx))
        finally:
            f.close()
        f = codecs.open(path.join(self.outdir, 'changes.html'), 'w', 'utf8')
        try:
            f.write(self.templates.render('changes/versionchanges.html', ctx))
        finally:
            f.close()

        hltext = ['.. versionadded:: %s' % version,
                  '.. versionchanged:: %s' % version,
                  '.. deprecated:: %s' % version]

        def hl(no, line):
            line = '<a name="L%s"> </a>' % no + htmlescape(line)
            for x in hltext:
                if x in line:
                    line = '<span class="hl">%s</span>' % line
                    break
            return line

        self.info(bold('copying source files...'))
        for docname in self.env.all_docs:
            f = codecs.open(self.env.doc2path(docname), 'r',
                            self.env.config.source_encoding)
            try:
                lines = f.readlines()
            except UnicodeDecodeError:
                self.warn('could not read %r for changelog creation' % docname)
                continue
            finally:
                f.close()
            targetfn = path.join(self.outdir, 'rst', os_path(docname)) + '.html'
            ensuredir(path.dirname(targetfn))
            f = codecs.open(targetfn, 'w', 'utf-8')
            try:
                text = ''.join(hl(i+1, line) for (i, line) in enumerate(lines))
                ctx = {
                    'filename': self.env.doc2path(docname, None),
                    'text': text
                }
                f.write(self.templates.render('changes/rstsource.html', ctx))
            finally:
                f.close()
        themectx = dict(('theme_' + key, val) for (key, val) in
                        iteritems(self.theme.get_options({})))
        copy_static_entry(path.join(package_dir, 'themes', 'default',
                                    'static', 'default.css_t'),
                          self.outdir, self, themectx)
        copy_static_entry(path.join(package_dir, 'themes', 'basic',
                                    'static', 'basic.css'),
                          self.outdir, self)
Exemple #26
0
        else:
            staticdirnames = []
        staticdirnames += [
            path.join(self.confdir, spath)
            for spath in self.config.html_static_path
        ]
        for staticdirname in staticdirnames:
            if not path.isdir(staticdirname):
                self.warn('static directory %r does not exist' % staticdirname)
                continue
            for filename in os.listdir(staticdirname):
                if filename.startswith('.'):
                    continue
                fullname = path.join(staticdirname, filename)
                targetname = path.join(self.outdir, '_static', filename)
                copy_static_entry(fullname, targetname, self,
                                  self.globalcontext)
        # last, copy logo file (handled differently)
        if self.config.html_logo:
            logobase = path.basename(self.config.html_logo)
            copyfile(path.join(self.confdir, self.config.html_logo),
                     path.join(self.outdir, '_static', logobase))

        # write build info file
        fp = open(path.join(self.outdir, '.buildinfo'), 'w')
        try:
            fp.write('# Sphinx build info version 1\n'
                     '# This file hashes the configuration used when building'
                     ' these files. When it is not found, a full rebuild will'
                     ' be done.\nconfig: %s\ntags: %s\n' %
                     (self.config_hash, self.tags_hash))
        finally:
Exemple #27
0
from flask import Flask

import runserver

app = Flask(__name__)
app.config.from_envvar('SPHINXWEB_SETTINGS')

import shutil
from sphinx.util import copy_static_entry
from sphinx.websupport import WebSupport

try:
    os.makedirs(os.path.join(app.config['BUILD_DIR'], 'templates'))
except os.error:
    pass

support = WebSupport(srcdir=app.config['SOURCE_DIR'],
                     builddir=app.config['BUILD_DIR'],
                     storage=app.config['DATABASE_URI'])
support.build()

# copy resources from this webapp
for name in ['static', 'templates']:
    source_dir = os.path.join(os.getcwd(), 'sphinxweb', name)
    target_dir = os.path.join(app.config['BUILD_DIR'], name)
    copy_static_entry(source_dir, target_dir, None)

shutil.copy(
    os.path.join(os.getcwd(), 'sphinxweb', 'static',  'websupport.js'), 
    os.path.join(app.config['BUILD_DIR'], 'static', '_static', 'websupport.js'))
    def write(self, *ignored):
        version = self.config.version
        libchanges = {}
        apichanges = []
        otherchanges = {}
        if version not in self.env.versionchanges:
            self.info(bold('no changes in version %s.' % version))
            return
        self.info(bold('writing summary file...'))
        for type, docname, lineno, module, descname, content in \
                self.env.versionchanges[version]:
            if isinstance(descname, tuple):
                descname = descname[0]
            ttext = self.typemap[type]
            context = content.replace('\n', ' ')
            if descname and docname.startswith('c-api'):
                if not descname:
                    continue
                if context:
                    entry = '<b>%s</b>: <i>%s:</i> %s' % (descname, ttext,
                                                          context)
                else:
                    entry = '<b>%s</b>: <i>%s</i>.' % (descname, ttext)
                apichanges.append((entry, docname, lineno))
            elif descname or module:
                if not module:
                    module = _('Builtins')
                if not descname:
                    descname = _('Module level')
                if context:
                    entry = '<b>%s</b>: <i>%s:</i> %s' % (descname, ttext,
                                                          context)
                else:
                    entry = '<b>%s</b>: <i>%s</i>.' % (descname, ttext)
                libchanges.setdefault(module, []).append(
                    (entry, docname, lineno))
            else:
                if not context:
                    continue
                entry = '<i>%s:</i> %s' % (ttext.capitalize(), context)
                title = self.env.titles[docname].astext()
                otherchanges.setdefault((docname, title), []).append(
                    (entry, docname, lineno))

        ctx = {
            'project': self.config.project,
            'version': version,
            'docstitle': self.config.html_title,
            'shorttitle': self.config.html_short_title,
            'libchanges': sorted(libchanges.iteritems()),
            'apichanges': sorted(apichanges),
            'otherchanges': sorted(otherchanges.iteritems()),
            'show_copyright': self.config.html_show_copyright,
            'show_sphinx': self.config.html_show_sphinx,
        }
        f = codecs.open(path.join(self.outdir, 'index.html'), 'w', 'utf8')
        try:
            f.write(self.templates.render('changes/frameset.html', ctx))
        finally:
            f.close()
        f = codecs.open(path.join(self.outdir, 'changes.html'), 'w', 'utf8')
        try:
            f.write(self.templates.render('changes/versionchanges.html', ctx))
        finally:
            f.close()

        hltext = [
            '.. versionadded:: %s' % version,
            '.. versionchanged:: %s' % version,
            '.. deprecated:: %s' % version
        ]

        def hl(no, line):
            line = '<a name="L%s"> </a>' % no + escape(line)
            for x in hltext:
                if x in line:
                    line = '<span class="hl">%s</span>' % line
                    break
            return line

        self.info(bold('copying source files...'))
        for docname in self.env.all_docs:
            f = codecs.open(self.env.doc2path(docname), 'r', 'latin1')
            lines = f.readlines()
            targetfn = path.join(self.outdir, 'rst',
                                 os_path(docname)) + '.html'
            ensuredir(path.dirname(targetfn))
            f = codecs.open(targetfn, 'w', 'latin1')
            try:
                text = ''.join(
                    hl(i + 1, line) for (i, line) in enumerate(lines))
                ctx = {
                    'filename': self.env.doc2path(docname, None),
                    'text': text
                }
                f.write(self.templates.render('changes/rstsource.html', ctx))
            finally:
                f.close()
        themectx = dict(
            ('theme_' + key, val)
            for (key, val) in self.theme.get_options({}).iteritems())
        copy_static_entry(
            path.join(package_dir, 'themes', 'default', 'static',
                      'default.css_t'), self.outdir, self, themectx)
        copy_static_entry(
            path.join(package_dir, 'themes', 'basic', 'static', 'basic.css'),
            self.outdir, self)
 def copy_static_files(self):
     # copy static files
     self.info(bold('copying static files... '), nonl=True)
     ensuredir(path.join(self.outdir, '_static'))
     # first, create pygments style file
     f = open(path.join(self.outdir, '_static', 'pygments.css'), 'w')
     f.write(self.highlighter.get_stylesheet())
     f.close()
     # then, copy translations JavaScript file
     if self.config.language is not None:
         jsfile_list = [
             path.join(package_dir, 'locale', self.config.language,
                       'LC_MESSAGES', 'sphinx.js'),
             path.join(sys.prefix, 'share/sphinx/locale',
                       self.config.language, 'sphinx.js')
         ]
         for jsfile in jsfile_list:
             if path.isfile(jsfile):
                 copyfile(
                     jsfile,
                     path.join(self.outdir, '_static', 'translations.js'))
                 break
     # then, copy over theme-supplied static files
     if self.theme:
         themeentries = [
             path.join(themepath, 'static')
             for themepath in self.theme.get_dirchain()[::-1]
         ]
         for entry in themeentries:
             copy_static_entry(entry, path.join(self.outdir, '_static'),
                               self, self.globalcontext)
     # then, copy over all user-supplied static files
     staticentries = [
         path.join(self.confdir, spath)
         for spath in self.config.html_static_path
     ]
     matchers = compile_matchers(
         self.config.exclude_patterns +
         ['**/' + d for d in self.config.exclude_dirnames])
     for entry in staticentries:
         if not path.exists(entry):
             self.warn('html_static_path entry %r does not exist' % entry)
             continue
         copy_static_entry(entry,
                           path.join(self.outdir, '_static'),
                           self,
                           self.globalcontext,
                           exclude_matchers=matchers)
     # copy logo and favicon files if not already in static path
     if self.config.html_logo:
         logobase = path.basename(self.config.html_logo)
         logotarget = path.join(self.outdir, '_static', logobase)
         if not path.isfile(logotarget):
             copyfile(path.join(self.confdir, self.config.html_logo),
                      logotarget)
     if self.config.html_favicon:
         iconbase = path.basename(self.config.html_favicon)
         icontarget = path.join(self.outdir, '_static', iconbase)
         if not path.isfile(icontarget):
             copyfile(path.join(self.confdir, self.config.html_favicon),
                      icontarget)
     self.info('done')
    def write(self, *ignored):
        version = self.config.version
        libchanges = {}
        apichanges = []
        otherchanges = {}
        if version not in self.env.versionchanges:
            self.info(bold("no changes in version %s." % version))
            return
        self.info(bold("writing summary file..."))
        for type, docname, lineno, module, descname, content in self.env.versionchanges[version]:
            if isinstance(descname, tuple):
                descname = descname[0]
            ttext = self.typemap[type]
            context = content.replace("\n", " ")
            if descname and docname.startswith("c-api"):
                if not descname:
                    continue
                if context:
                    entry = "<b>%s</b>: <i>%s:</i> %s" % (descname, ttext, context)
                else:
                    entry = "<b>%s</b>: <i>%s</i>." % (descname, ttext)
                apichanges.append((entry, docname, lineno))
            elif descname or module:
                if not module:
                    module = _("Builtins")
                if not descname:
                    descname = _("Module level")
                if context:
                    entry = "<b>%s</b>: <i>%s:</i> %s" % (descname, ttext, context)
                else:
                    entry = "<b>%s</b>: <i>%s</i>." % (descname, ttext)
                libchanges.setdefault(module, []).append((entry, docname, lineno))
            else:
                if not context:
                    continue
                entry = "<i>%s:</i> %s" % (ttext.capitalize(), context)
                title = self.env.titles[docname].astext()
                otherchanges.setdefault((docname, title), []).append((entry, docname, lineno))

        ctx = {
            "project": self.config.project,
            "version": version,
            "docstitle": self.config.html_title,
            "shorttitle": self.config.html_short_title,
            "libchanges": sorted(libchanges.iteritems()),
            "apichanges": sorted(apichanges),
            "otherchanges": sorted(otherchanges.iteritems()),
            "show_copyright": self.config.html_show_copyright,
            "show_sphinx": self.config.html_show_sphinx,
        }
        f = codecs.open(path.join(self.outdir, "index.html"), "w", "utf8")
        try:
            f.write(self.templates.render("changes/frameset.html", ctx))
        finally:
            f.close()
        f = codecs.open(path.join(self.outdir, "changes.html"), "w", "utf8")
        try:
            f.write(self.templates.render("changes/versionchanges.html", ctx))
        finally:
            f.close()

        hltext = [".. versionadded:: %s" % version, ".. versionchanged:: %s" % version, ".. deprecated:: %s" % version]

        def hl(no, line):
            line = '<a name="L%s"> </a>' % no + htmlescape(line)
            for x in hltext:
                if x in line:
                    line = '<span class="hl">%s</span>' % line
                    break
            return line

        self.info(bold("copying source files..."))
        for docname in self.env.all_docs:
            f = codecs.open(self.env.doc2path(docname), "r", self.env.config.source_encoding)
            try:
                lines = f.readlines()
            finally:
                f.close()
            targetfn = path.join(self.outdir, "rst", os_path(docname)) + ".html"
            ensuredir(path.dirname(targetfn))
            f = codecs.open(targetfn, "w", "utf-8")
            try:
                text = "".join(hl(i + 1, line) for (i, line) in enumerate(lines))
                ctx = {"filename": self.env.doc2path(docname, None), "text": text}
                f.write(self.templates.render("changes/rstsource.html", ctx))
            finally:
                f.close()
        themectx = dict(("theme_" + key, val) for (key, val) in self.theme.get_options({}).iteritems())
        copy_static_entry(
            path.join(package_dir, "themes", "default", "static", "default.css_t"), self.outdir, self, themectx
        )
        copy_static_entry(path.join(package_dir, "themes", "basic", "static", "basic.css"), self.outdir, self)