Skip to content

Commit

Permalink
Search index rebuild, replace prints with click.echo
Browse files Browse the repository at this point in the history
  • Loading branch information
tino097 committed Sep 13, 2018
1 parent 0906085 commit f637976
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
22 changes: 12 additions & 10 deletions ckan/cli/db.py
Expand Up @@ -23,24 +23,24 @@ def initdb():
import ckan.model as model
model.repo.init_db()
except Exception as e:
print(e)
click.echo(e, err=True)
print(u'Initialising DB: SUCCESS')


prompt_msg = u'This will delete all of your data!\nDo you want to continue?'
PROMPT_MSG = u'This will delete all of your data!\nDo you want to continue?'


@db.command(u'clean', short_help=u'Clean the database')
@click.confirmation_option(prompt=prompt_msg)
@click.confirmation_option(prompt=PROMPT_MSG)
@click.help_option(u'-h', u'--help')
def cleandb():
u'''Cleaning the database'''
try:
import ckan.model as model
model.repo.clean_db()
except Exception as e:
print(e)
print(u'Cleaning DB: SUCCESS')
click.echo(e, err=True)
click.secho(u'Cleaning DB: SUCCESS', color="green", bold=True)


@db.command(u'upgrade', short_help=u'Upgrade the database')
Expand All @@ -52,8 +52,8 @@ def updatedb(version=None):
import ckan.model as model
model.repo.upgrade_db(version)
except Exception as e:
print(e)
print(u'Upgrading DB: SUCCESS')
click.echo(e, err=True)
click.secho(u'Upgrading DB: SUCCESS', fg='green', bold=True)


@db.command(u'version', short_help=u'Returns current version of data schema')
Expand All @@ -62,7 +62,9 @@ def version():
u'''Return current version'''
try:
from ckan.model import Session
print(Session.execute(u'select version from '
u'migrate_version;').fetchall())
ver = Session.execute(u'select version from '
u'migrate_version;').fetchall()
click.secho(u"Latest data schema version: {0}".format(ver[0][0]),
fg="green", bold=True)
except Exception as e:
print(e)
click.echo(e, err=True)
30 changes: 25 additions & 5 deletions ckan/cli/search_index.py
Expand Up @@ -16,12 +16,32 @@ def search_index():


@search_index.command(name=u'rebuild', short_help=u'Rebuild search index')
@click.help_option(u'-h', u'--help')
@click.option(u'-v', u'--verbose', is_flag=True)
@click.option(u'-i', u'--force', is_flag=True,
help=u'Ignore exceptions when rebuilding the index')
@click.option(u'-r', u'--refresh')
@click.option(u'-o', u'--only-missing')
def rebuild(force, only_missing):
@click.option(u'-r', u'--refresh', help=u'Refresh current index', is_flag=True)
@click.option(u'-o', u'--only-missing',
help=u'Index non indexed datasets only', is_flag=True)
@click.option(u'-q', u'--quiet', help=u'Do not output index rebuild progress',
is_flag=True)
@click.option(u'-e', u'--commit-each', is_flag=True,
help=u'Perform a commit after indexing each dataset. This'
u'ensures that changes are immediately available on the'
u'search, but slows significantly the process. Default'
u'is false.')
@click.pass_context
def rebuild(ctx, verbose, force, refresh, only_missing, quiet, commit_each):
u''' Rebuild search index '''
from ckan.lib.search import rebuild, commit
# if force:
# rebuild()
try:
with ctx.obj.app.apps.get('flask_app').app.app.app.test_request_context():
rebuild(only_missing=only_missing,
force=force,
refresh=refresh,
defer_commit=(not commit_each),
quiet=quiet)
except Exception as e:
click.echo(e, err=True)
if not commit_each:
commit()
1 change: 1 addition & 0 deletions ckan/cli/server.py
Expand Up @@ -18,4 +18,5 @@
@click.pass_context
def run(ctx, config, host, port, reloader):
u'''Runs development server'''
# click.secho(u"Starting CKAN", fg='yellow')
run_simple(host, port, ctx.obj.app, use_reloader=reloader, use_evalex=True)

0 comments on commit f637976

Please sign in to comment.