Skip to content

Commit

Permalink
Merge pull request #1005 from sphinx-contrib/improve-progress-output-…
Browse files Browse the repository at this point in the history
…in-cleanup-mode

builder: improve output experience for various logs
  • Loading branch information
jdknight committed Jun 29, 2024
2 parents 8d1e79f + 306be94 commit 22b9523
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions sphinxcontrib/confluencebuilder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from urllib.parse import quote
import os
import tempfile
import time


class ConfluenceBuilder(Builder):
Expand All @@ -69,6 +70,7 @@ def __init__(self, app, env=None):
self.metadata = defaultdict(dict)
self.nav_next = {}
self.nav_prev = {}
self.note = ConfluenceLogger.note
self.omitted_docnames = []
self.orphan_docnames = []
self.out_dir = Path(self.outdir)
Expand Down Expand Up @@ -532,6 +534,9 @@ def publish_doc(self, docname, output):
# if purging is enabled and we have yet to populate a list of legacy
# pages to cache, populate pages in our target scope now
if self.post_cleanup and self.legacy_pages is None:
# flag for newlining any note events needed for cleanup
extra_msg = False

if conf.confluence_publish_root:
baseid = conf.confluence_publish_root
elif conf.confluence_cleanup_from_root:
Expand All @@ -546,8 +551,17 @@ def publish_doc(self, docname, output):
conf.confluence_publish_dryrun and not baseid):
self.legacy_pages = []
else:
if not extra_msg and not self._verbose:
self.note('')

self.note('querying for descendants... ',
nonl=(not self._verbose))
self.legacy_pages = self.publisher.get_descendants(
baseid, conf.confluence_cleanup_search_mode)
if not self._verbose:
self.info('done')

extra_msg = True

# remove any configured orphan root id from a cleanup check
orphan_root_id = str(conf.confluence_publish_orphan_container)
Expand All @@ -558,11 +572,25 @@ def publish_doc(self, docname, output):
# only populate a list of possible legacy assets when a user is
# configured to check or push assets to the target space
asset_override = conf.confluence_asset_override
if asset_override is None or asset_override:
for legacy_page in self.legacy_pages:
if self.legacy_pages and (asset_override is None or asset_override):
if not extra_msg and not self._verbose:
self.note('')

for legacy_page in status_iterator(
sorted(self.legacy_pages),
'querying for attachments... ',
length=len(self.legacy_pages),
verbosity=self._verbose):
attachments = self.publisher.get_attachments(legacy_page)
self.legacy_assets[legacy_page] = attachments

# unknown cause but using a nested status_iterator appears
# to not flush log events to users standard output without
# sleeping -- not sure if its the logger, a threading/gil
# situation with this implementation or more -- although
# looks if we wait a moment, logging works as expected
time.sleep(0.1)

if self.post_cleanup:
if uploaded_id in self.legacy_pages:
self.legacy_pages.remove(uploaded_id)
Expand Down Expand Up @@ -647,7 +675,8 @@ def publish_finalize(self):
self.info('updating space\'s homepage... ',
nonl=(not self._verbose))
self.publisher.update_space_home(self.root_doc_page_id)
self.info('done')
if not self._verbose:
self.info('done')

if self.cloud:
point_url = '{0}spaces/{1}/pages/{2}'
Expand Down Expand Up @@ -771,7 +800,8 @@ def finish(self):

self.info('building intersphinx... ', nonl=(not self._verbose))
build_intersphinx(self)
self.info('done')
if not self._verbose:
self.info('done')

if self.config.confluence_publish_intersphinx:
inventory_db = self.out_dir / 'objects.inv'
Expand Down

0 comments on commit 22b9523

Please sign in to comment.