Skip to content

Commit

Permalink
add --quiet option to paster search index rebuild progress meter
Browse files Browse the repository at this point in the history
  • Loading branch information
deniszgonjanin committed Sep 15, 2015
1 parent 03c1ce0 commit 35823d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
23 changes: 14 additions & 9 deletions ckan/lib/cli.py
Expand Up @@ -402,14 +402,14 @@ class SearchIndexCommand(CkanCommand):
'''Creates a search index for all datasets
Usage:
search-index [-i] [-o] [-r] [-e] rebuild [dataset_name] - reindex dataset_name if given, if not then rebuild
full search index (all datasets)
search-index rebuild_fast - reindex using multiprocessing using all cores.
This acts in the same way as rubuild -r [EXPERIMENTAL]
search-index check - checks for datasets not indexed
search-index show DATASET_NAME - shows index of a dataset
search-index clear [dataset_name] - clears the search index for the provided dataset or
for the whole ckan instance
search-index [-i] [-o] [-r] [-e] [-q] rebuild [dataset_name] - reindex dataset_name if given, if not then rebuild
full search index (all datasets)
search-index rebuild_fast - reindex using multiprocessing using all cores.
This acts in the same way as rubuild -r [EXPERIMENTAL]
search-index check - checks for datasets not indexed
search-index show DATASET_NAME - shows index of a dataset
search-index clear [dataset_name] - clears the search index for the provided dataset or
for the whole ckan instance
'''

summary = __doc__.split('\n')[0]
Expand All @@ -432,6 +432,10 @@ def __init__(self, name):
action='store_true', default=False,
help='Refresh current index (does not clear the existing one)')

self.parser.add_option('-q', '--quiet', dest='quiet',
action='store_true', default=False,
help='Do not output index rebuild progress')

self.parser.add_option('-e', '--commit-each', dest='commit_each',
action='store_true', default=False, help=
'''Perform a commit after indexing each dataset. This ensures that changes are
Expand Down Expand Up @@ -474,7 +478,8 @@ def rebuild(self):
rebuild(only_missing=self.options.only_missing,
force=self.options.force,
refresh=self.options.refresh,
defer_commit=(not self.options.commit_each))
defer_commit=(not self.options.commit_each),
quiet=self.options.quiet)

if not self.options.commit_each:
commit()
Expand Down
13 changes: 8 additions & 5 deletions ckan/lib/search/__init__.py
Expand Up @@ -135,7 +135,8 @@ def notify(self, entity, operation):
log.warn("Discarded Sync. indexing for: %s" % entity)


def rebuild(package_id=None, only_missing=False, force=False, refresh=False, defer_commit=False, package_ids=None):
def rebuild(package_id=None, only_missing=False, force=False, refresh=False,
defer_commit=False, package_ids=None, quiet=False):
'''
Rebuilds the search index.
Expand Down Expand Up @@ -185,10 +186,12 @@ def rebuild(package_id=None, only_missing=False, force=False, refresh=False, def

total_packages = len(package_ids)
for counter, pkg_id in enumerate(package_ids):
sys.stdout.write(
"\rIndexing dataset {0}/{1}".format(counter, total_packages)
)
sys.stdout.flush()
if not quiet:
sys.stdout.write(
"\rIndexing dataset {0}/{1}".format(
counter +1, total_packages)
)
sys.stdout.flush()
try:
package_index.update_dict(
logic.get_action('package_show')(context,
Expand Down

0 comments on commit 35823d8

Please sign in to comment.