mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
html: refactor with progress_message()
This commit is contained in:
parent
afefeebb52
commit
231bde7461
@ -38,8 +38,7 @@ from sphinx.highlighting import PygmentsBridge
|
|||||||
from sphinx.locale import _, __
|
from sphinx.locale import _, __
|
||||||
from sphinx.search import js_index
|
from sphinx.search import js_index
|
||||||
from sphinx.theming import HTMLThemeFactory
|
from sphinx.theming import HTMLThemeFactory
|
||||||
from sphinx.util import logging, status_iterator
|
from sphinx.util import logging, progress_message, status_iterator
|
||||||
from sphinx.util.console import bold # type: ignore
|
|
||||||
from sphinx.util.docutils import is_html5_writer_available, new_document
|
from sphinx.util.docutils import is_html5_writer_available, new_document
|
||||||
from sphinx.util.fileutil import copy_asset
|
from sphinx.util.fileutil import copy_asset
|
||||||
from sphinx.util.i18n import format_date
|
from sphinx.util.i18n import format_date
|
||||||
@ -626,6 +625,7 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
|
|
||||||
def finish(self) -> None:
|
def finish(self) -> None:
|
||||||
self.finish_tasks.add_task(self.gen_indices)
|
self.finish_tasks.add_task(self.gen_indices)
|
||||||
|
self.finish_tasks.add_task(self.gen_pages_from_extensions)
|
||||||
self.finish_tasks.add_task(self.gen_additional_pages)
|
self.finish_tasks.add_task(self.gen_additional_pages)
|
||||||
self.finish_tasks.add_task(self.copy_image_files)
|
self.finish_tasks.add_task(self.copy_image_files)
|
||||||
self.finish_tasks.add_task(self.copy_download_files)
|
self.finish_tasks.add_task(self.copy_download_files)
|
||||||
@ -636,9 +636,8 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
# dump the search index
|
# dump the search index
|
||||||
self.handle_finish()
|
self.handle_finish()
|
||||||
|
|
||||||
|
@progress_message(__('generating indices'))
|
||||||
def gen_indices(self) -> None:
|
def gen_indices(self) -> None:
|
||||||
logger.info(bold(__('generating indices...')), nonl=True)
|
|
||||||
|
|
||||||
# the global general index
|
# the global general index
|
||||||
if self.use_index:
|
if self.use_index:
|
||||||
self.write_genindex()
|
self.write_genindex()
|
||||||
@ -646,16 +645,14 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
# the global domain-specific indices
|
# the global domain-specific indices
|
||||||
self.write_domain_indices()
|
self.write_domain_indices()
|
||||||
|
|
||||||
logger.info('')
|
def gen_pages_from_extensions(self) -> None:
|
||||||
|
|
||||||
def gen_additional_pages(self) -> None:
|
|
||||||
# pages from extensions
|
# pages from extensions
|
||||||
for pagelist in self.events.emit('html-collect-pages'):
|
for pagelist in self.events.emit('html-collect-pages'):
|
||||||
for pagename, context, template in pagelist:
|
for pagename, context, template in pagelist:
|
||||||
self.handle_page(pagename, context, template)
|
self.handle_page(pagename, context, template)
|
||||||
|
|
||||||
logger.info(bold(__('writing additional pages...')), nonl=True)
|
@progress_message(__('writing additional pages'))
|
||||||
|
def gen_additional_pages(self) -> None:
|
||||||
# additional pages from conf.py
|
# additional pages from conf.py
|
||||||
for pagename, template in self.config.html_additional_pages.items():
|
for pagename, template in self.config.html_additional_pages.items():
|
||||||
logger.info(' ' + pagename, nonl=True)
|
logger.info(' ' + pagename, nonl=True)
|
||||||
@ -672,8 +669,6 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
fn = path.join(self.outdir, '_static', 'opensearch.xml')
|
fn = path.join(self.outdir, '_static', 'opensearch.xml')
|
||||||
self.handle_page('opensearch', {}, 'opensearch.xml', outfilename=fn)
|
self.handle_page('opensearch', {}, 'opensearch.xml', outfilename=fn)
|
||||||
|
|
||||||
logger.info('')
|
|
||||||
|
|
||||||
def write_genindex(self) -> None:
|
def write_genindex(self) -> None:
|
||||||
# the total count of lines for each index letter, used to distribute
|
# the total count of lines for each index letter, used to distribute
|
||||||
# the entries into two columns
|
# the entries into two columns
|
||||||
@ -749,7 +744,7 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
def copy_static_files(self) -> None:
|
def copy_static_files(self) -> None:
|
||||||
try:
|
try:
|
||||||
# copy static files
|
# copy static files
|
||||||
logger.info(bold(__('copying static files... ')), nonl=True)
|
with progress_message(__('copying static files... ')):
|
||||||
ensuredir(path.join(self.outdir, '_static'))
|
ensuredir(path.join(self.outdir, '_static'))
|
||||||
# first, create pygments style file
|
# first, create pygments style file
|
||||||
with open(path.join(self.outdir, '_static', 'pygments.css'), 'w') as f:
|
with open(path.join(self.outdir, '_static', 'pygments.css'), 'w') as f:
|
||||||
@ -792,20 +787,17 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
if self.config.html_favicon:
|
if self.config.html_favicon:
|
||||||
entry = path.join(self.confdir, self.config.html_favicon)
|
entry = path.join(self.confdir, self.config.html_favicon)
|
||||||
copy_asset(entry, path.join(self.outdir, '_static'))
|
copy_asset(entry, path.join(self.outdir, '_static'))
|
||||||
logger.info(__('done'))
|
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
logger.warning(__('cannot copy static file %r'), err)
|
logger.warning(__('cannot copy static file %r'), err)
|
||||||
|
|
||||||
def copy_extra_files(self) -> None:
|
def copy_extra_files(self) -> None:
|
||||||
|
"""copy html_extra_path files."""
|
||||||
try:
|
try:
|
||||||
# copy html_extra_path files
|
with progress_message(__('copying extra files')):
|
||||||
logger.info(bold(__('copying extra files... ')), nonl=True)
|
|
||||||
excluded = Matcher(self.config.exclude_patterns)
|
excluded = Matcher(self.config.exclude_patterns)
|
||||||
|
|
||||||
for extra_path in self.config.html_extra_path:
|
for extra_path in self.config.html_extra_path:
|
||||||
entry = path.join(self.confdir, extra_path)
|
entry = path.join(self.confdir, extra_path)
|
||||||
copy_asset(entry, self.outdir, excluded)
|
copy_asset(entry, self.outdir, excluded)
|
||||||
logger.info(__('done'))
|
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
logger.warning(__('cannot copy extra file %r'), err)
|
logger.warning(__('cannot copy extra file %r'), err)
|
||||||
|
|
||||||
@ -1049,15 +1041,12 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
self.finish_tasks.add_task(self.dump_search_index)
|
self.finish_tasks.add_task(self.dump_search_index)
|
||||||
self.finish_tasks.add_task(self.dump_inventory)
|
self.finish_tasks.add_task(self.dump_inventory)
|
||||||
|
|
||||||
|
@progress_message(__('dumping object inventory'))
|
||||||
def dump_inventory(self) -> None:
|
def dump_inventory(self) -> None:
|
||||||
logger.info(bold(__('dumping object inventory... ')), nonl=True)
|
|
||||||
InventoryFile.dump(path.join(self.outdir, INVENTORY_FILENAME), self.env, self)
|
InventoryFile.dump(path.join(self.outdir, INVENTORY_FILENAME), self.env, self)
|
||||||
logger.info(__('done'))
|
|
||||||
|
|
||||||
def dump_search_index(self) -> None:
|
def dump_search_index(self) -> None:
|
||||||
logger.info(
|
with progress_message(__('dumping search index in %s') % self.indexer.label()):
|
||||||
bold(__('dumping search index in %s ... ') % self.indexer.label()),
|
|
||||||
nonl=True)
|
|
||||||
self.indexer.prune(self.env.all_docs)
|
self.indexer.prune(self.env.all_docs)
|
||||||
searchindexfn = path.join(self.outdir, self.searchindex_filename)
|
searchindexfn = path.join(self.outdir, self.searchindex_filename)
|
||||||
# first write to a temporary file, so that if dumping fails,
|
# first write to a temporary file, so that if dumping fails,
|
||||||
@ -1069,7 +1058,6 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
with open(searchindexfn + '.tmp', 'wb') as fb:
|
with open(searchindexfn + '.tmp', 'wb') as fb:
|
||||||
self.indexer.dump(fb, self.indexer_format)
|
self.indexer.dump(fb, self.indexer_format)
|
||||||
movefile(searchindexfn + '.tmp', searchindexfn)
|
movefile(searchindexfn + '.tmp', searchindexfn)
|
||||||
logger.info(__('done'))
|
|
||||||
|
|
||||||
|
|
||||||
def convert_html_css_files(app: Sphinx, config: Config) -> None:
|
def convert_html_css_files(app: Sphinx, config: Config) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user