diff --git a/ckan/cli/db.py b/ckan/cli/db.py index 7b44b3a4823..ccf2d55541c 100644 --- a/ckan/cli/db.py +++ b/ckan/cli/db.py @@ -23,15 +23,15 @@ 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''' @@ -39,8 +39,8 @@ def cleandb(): 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') @@ -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') @@ -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) diff --git a/ckan/cli/search_index.py b/ckan/cli/search_index.py index a4123a33f4c..99f55255009 100644 --- a/ckan/cli/search_index.py +++ b/ckan/cli/search_index.py @@ -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() diff --git a/ckan/cli/server.py b/ckan/cli/server.py index 387bc301704..99ad914ce92 100644 --- a/ckan/cli/server.py +++ b/ckan/cli/server.py @@ -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)