def vocabularies(): """Create vocabularies fake records.""" cli = create_cli() runner = current_app.test_cli_runner() def run_command(command, catch_exceptions=False, verbose=True): click.secho("ils {}...".format(command), fg="green") res = runner.invoke(cli, command, catch_exceptions=catch_exceptions) if verbose: click.secho(res.output) vocabularies_dir = os.path.join( os.path.realpath("."), "cds_ils", "vocabularies", "data", ) json_files = " ".join( os.path.join(vocabularies_dir, name) for name in os.listdir(vocabularies_dir) if name.endswith(".json")) run_command("vocabulary index json --force {}".format(json_files)) run_command("vocabulary index opendefinition spdx --force") run_command("vocabulary index opendefinition opendefinition --force") # index languages run_command("vocabulary index languages --force")
def index_ldap_users(): """Index ldap users in ES.""" from invenio_base.app import create_cli cli = create_cli() runner = current_app.test_cli_runner() command = "ils patrons index" runner.invoke(cli, command, catch_exceptions=True) _log_info("command_executed", dict(command=command))
def index_ldap_users(): """Index ldap users in ES.""" from invenio_base.app import create_cli cli = create_cli() runner = current_app.test_cli_runner() command = "ils patrons index" click.secho('ils {}...'.format(command), fg='green') runner.invoke(cli, command, catch_exceptions=True)
def reindex_pidtype(pid_type): """Reindex records with the specified pid_type.""" click.echo('Indexing pid type "{}"...'.format(pid_type)) cli = create_cli() runner = current_app.test_cli_runner() runner.invoke(cli, 'index reindex --pid-type {} --yes-i-know'.format(pid_type), catch_exceptions=False) runner.invoke(cli, 'index run', catch_exceptions=False) click.echo('Indexing completed!')
def _build_local_assets(log_config, statics=True, webpack=True): """Build assets locally.""" cli = create_cli() runner = current_app.test_cli_runner() if statics: # Collect run_command(cli, runner, "collect -v", message="Collecting assets...", verbose=log_config.verbose) if webpack: # Build using webpack run_command(cli, runner, "webpack buildall", message="Building assets...", verbose=log_config.verbose)
def clean(user_email, given_date, verbose): """Remove loans of user.""" cli = create_cli() runner = current_app.test_cli_runner() def run_command(command, catch_exceptions=False): click.secho("cds-ils {}...".format(command), fg="green") res = runner.invoke(cli, command, catch_exceptions=catch_exceptions) if verbose: click.secho(res.output) if not given_date: given_date = arrow.utcnow().format("YYYY-MM-DD") run_command("user-testing clean-loans --user-email " + user_email + " --given-date " + given_date)
def prepare(user_email, verbose): """Create loans for user.""" cli = create_cli() runner = current_app.test_cli_runner() def run_command(command, catch_exceptions=False): click.secho("cds-ils {}...".format(command), fg="green") res = runner.invoke(cli, command, catch_exceptions=catch_exceptions) if verbose: click.secho(res.output) # create ongoing loan run_command("user-testing create-loan --user-email " + user_email) # create past loan run_command("user-testing create-loan --is-past-loan --user-email " + user_email)
def test_create_cli_with_app(): """Test create cli.""" app_name = 'mycmdtest' create_app = create_app_factory(app_name) cli = create_cli(create_app=create_app) @cli.command() def test_cmd(): click.echo('{0} {1}'.format(current_app.name, current_app.debug)) runner = CliRunner() result = runner.invoke(cli) assert result.exit_code == 0 result = runner.invoke(cli, ['test_cmd']) assert result.exit_code == 0 assert u'{0} False\n'.format(app_name) in result.output
def test_create_cli_with_app(): """Test create cli.""" app_name = 'mycmdtest' create_app = create_app_factory(app_name) cli = create_cli(create_app=create_app) @cli.command() def test_cmd(): click.echo('{0} {1}'.format(current_app.name, current_app.debug)) runner = CliRunner() result = runner.invoke(cli) assert result.exit_code == 0 result = runner.invoke(cli, ['test-cmd']) assert result.exit_code == 0 assert u'{0} False\n'.format(app_name) in result.output
def import_demo_data(path, are_docs, are_items, verbose): """Import real demo data.""" cli = create_cli() runner = current_app.test_cli_runner() def run_command(command, catch_exceptions=False): click.secho("cds-ils {}...".format(command), fg="green") res = runner.invoke(cli, command, catch_exceptions=catch_exceptions) if verbose: click.secho(res.output) if are_docs: command = "create-demo-docs" elif are_items: command = "create-demo-items" run_command("user-testing " + command + " --json-path " + path)
def setup(log_config, local=True, force=False, stop_containers=False, docker_helper=None, project_shortname='invenio-rdm'): """Bootstrap server.""" click.secho('Setting up server...', fg='green') click.secho("Starting containers...", fg="green") docker_helper.start_containers() time.sleep(60) # Give time to the containers to start properly if local: cli = create_cli() runner = current_app.test_cli_runner() _setup_local(force, cli, runner, log_config) else: _setup_containers(force, docker_helper, project_shortname, log_config) if stop_containers: click.secho("Stopping containers...", fg="green") docker_helper.stop_containers() time.sleep(30)
def demo_patrons(): """Create demo patrons.""" cli = create_cli() runner = current_app.test_cli_runner() def run_command(command, catch_exceptions=False, verbose=True): click.secho("ils {}...".format(command), fg="green") res = runner.invoke(cli, command, catch_exceptions=catch_exceptions) if verbose: click.secho(res.output) # Create roles to restrict access run_command("roles create admin") run_command("roles create librarian") # Create users run_command("users create [email protected] -a --password=123456") # ID 1 create_userprofile_for("*****@*****.**", "patron1", "Yannic Vilma") run_command("users create [email protected] -a --password=123456") # ID 2 create_userprofile_for("*****@*****.**", "patron2", "Diana Adi") run_command("users create [email protected] -a --password=123456") # ID 3 create_userprofile_for("*****@*****.**", "admin", "Zeki Ryoichi") run_command("users create [email protected] -a --password=123456") # ID 4 create_userprofile_for("*****@*****.**", "librarian", "Hector Nabu") run_command("users create [email protected] -a --password=123456") # ID 5 create_userprofile_for("*****@*****.**", "patron3", "Medrod Tara") run_command("users create [email protected] -a --password=123456") # ID 6 create_userprofile_for("*****@*****.**", "patron4", "Devi Cupid") # Assign roles run_command("roles add [email protected] admin") run_command("roles add [email protected] librarian") # Assign actions run_command("access allow superuser-access role admin") run_command("access allow ils-backoffice-access role librarian") run_command("patrons index")
def populate_demo_records(local, docker_helper, project_shortname, log_config, stop_containers=False): """Add demo records into the instance.""" click.secho('Setting up server...', fg='green') cli = create_cli() runner = current_app.test_cli_runner() click.secho("Starting containers...", fg="green") docker_helper.start_containers() time.sleep(60) # Give time to the containers to start properly if local: run_command(cli, runner, 'rdm-records demo', message="Populating instance with demo records...", verbose=log_config.verbose) else: click.secho("Populating instance with demo records...", fg="green") docker_helper.execute_cli_command(project_shortname, 'invenio rdm-records demo') if stop_containers: docker_helper.stop_containers() time.sleep(30)
# Copyright (C) 2015 CERN. # # Zenodo is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # Zenodo is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Zenodo; if not, write to the # Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307, USA. # # In applying this license, CERN does not # waive the privileges and immunities granted to it by virtue of its status # as an Intergovernmental Organization or submit itself to any jurisdiction. """Zenodo CLI module.""" from __future__ import absolute_import, print_function from invenio_base.app import create_cli from .factory import create_app cli = create_cli(create_app=create_app) """Zenodo Click CLI."""
# Zenodo is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Zenodo; if not, write to the # Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307, USA. # # In applying this license, CERN does not # waive the privileges and immunities granted to it by virtue of its status # as an Intergovernmental Organization or submit itself to any jurisdiction. """Zenodo CLI module.""" from __future__ import absolute_import, print_function from invenio_base.app import create_cli from .factory import create_app from .modules.auditor.cli import audit from .modules.github.cli import github from .modules.utils.cli import utils cli = create_cli(create_app=create_app) cli.add_command(audit) cli.add_command(github) cli.add_command(utils) """Zenodo Click CLI."""
def setup(admin_password, recreate_db, skip_demo_data, skip_file_location, drop_taxonomies, skip_taxonomy_import, verbose, taxonomies='./assets/taxonomy'): """OARepo setup command.""" from flask import current_app from invenio_base.app import create_cli click.secho("oarepo setup started...", fg="blue") # Clean redis redis.StrictRedis.from_url( current_app.config["CACHE_REDIS_URL"]).flushall() click.secho("redis cache cleared...", fg="red") cli = create_cli() # Important: force API app on CLI context for proper URL generation cli.create_app = create_api runner = create_api().test_cli_runner() def run_command(command, catch_exceptions=False): click.secho("oarepo {}...".format(command), fg="green") res = runner.invoke(cli, command, catch_exceptions=catch_exceptions) if verbose: click.secho(res.output) # Print all routes considered for URL generation run_command('routes') # Remove and create db and indexes if recreate_db: run_command("db destroy --yes-i-know", catch_exceptions=True) run_command("db init") else: run_command("db drop --yes-i-know") run_command("db create") run_command("index destroy --force --yes-i-know") run_command("index init --force") run_command("index queue init purge") # Create roles to restrict access run_command("roles create admin") # Create users run_command("users create [email protected] -a --password={}".format( admin_password)) # ID 1 create_userprofile_for("*****@*****.**", "admin", "OArepo Administrator") # Assign roles run_command("roles add [email protected] admin") # Assign actions run_command("access allow superuser-access role admin") # Create files location if not skip_file_location: run_command("files location --default oarepo /tmp/oarepo") # Create ACLs index for preferred SCHEMA run_command("invenio invenio_explicit_acls prepare {}".format( ACL_PREFERRED_SCHEMA)) # Drop taxonomy data if drop_taxonomies: taxo_list = runner.invoke(cli, 'taxonomies list', catch_exceptions=False) click.secho("oarepo dropping existing taxonomies {}".format( taxo_list.output), fg="yellow") for tax in [ t for t in taxo_list.output.splitlines() if t[0] not in [' ', '*'] ]: click.secho("oarepo deleting taxonomy {}".format(tax), fg="yellow") run_command('taxonomies delete {}'.format(tax)) # Import taxonomies if not skip_taxonomy_import: import os click.secho("oarepo importing taxonomies from {}".format(taxonomies), fg="green") for tax_file in os.listdir(taxonomies): if tax_file.endswith('xlsx'): tax_path = os.path.join(taxonomies, tax_file) click.secho("oarepo importing taxonomy {}".format(tax_path), fg="green") if tax_file.startswith('event'): run_command( 'taxonomies import {} --str web --str organizer --str startDate --str endDate --bool ' 'selectable --drop'.format(tax_path)) elif tax_file.startswith('format'): run_command( 'taxonomies import {} --str resolution --str spec --bool selectable --drop' .format(tax_path)) click.secho("oarepo setting all-read permission on taxonomies", fg="green") run_command('taxonomies all-read') # TODO: what about taxonomy modify? run_command('demo data') click.secho("oarepo setup finished successfully", fg="blue")
def setup(recreate_db, skip_demo_data, skip_file_location, skip_patrons, skip_vocabularies, verbose): """ILS setup command.""" from flask import current_app from invenio_base.app import create_cli import redis click.secho("ils setup started...", fg="blue") # Clean redis redis.StrictRedis.from_url( current_app.config["CACHE_REDIS_URL"]).flushall() click.secho("redis cache cleared...", fg="red") cli = create_cli() runner = current_app.test_cli_runner() def run_command(command, catch_exceptions=False): click.secho("ils {}...".format(command), fg="green") res = runner.invoke(cli, command, catch_exceptions=catch_exceptions) if verbose: click.secho(res.output) # Remove and create db and indexes if recreate_db: run_command("db destroy --yes-i-know", catch_exceptions=True) run_command("db init") else: run_command("db drop --yes-i-know") run_command("db create") run_command("index destroy --force --yes-i-know") run_command("index init --force") run_command("index queue init purge") # Create roles to restrict access run_command("roles create admin") run_command("roles create librarian") if not skip_patrons: # Create users run_command( "users create [email protected] -a --password=123456") # ID 1 create_userprofile_for("*****@*****.**", "patron1", "Yannic Vilma") run_command( "users create [email protected] -a --password=123456") # ID 2 create_userprofile_for("*****@*****.**", "patron2", "Diana Adi") run_command("users create [email protected] -a --password=123456") # ID 3 create_userprofile_for("*****@*****.**", "admin", "Zeki Ryoichi") run_command( "users create [email protected] -a --password=123456") # ID 4 create_userprofile_for("*****@*****.**", "librarian", "Hector Nabu") run_command( "users create [email protected] -a --password=123456") # ID 5 create_userprofile_for("*****@*****.**", "patron3", "Medrod Tara") run_command( "users create [email protected] -a --password=123456") # ID 6 create_userprofile_for("*****@*****.**", "patron4", "Devi Cupid") # Assign roles run_command("roles add [email protected] admin") run_command("roles add [email protected] librarian") if not skip_vocabularies: vocabularies_dir = os.path.join(os.path.realpath("."), "invenio_app_ils", "vocabularies", "data") json_files = " ".join( os.path.join(vocabularies_dir, name) for name in os.listdir(vocabularies_dir) if name.endswith(".json")) run_command("vocabulary index json --force {}".format(json_files)) run_command("vocabulary index opendefinition spdx --force") run_command("vocabulary index opendefinition opendefinition --force") # Assign actions run_command("access allow superuser-access role admin") run_command("access allow ils-backoffice-access role librarian") # Index patrons run_command("patrons index") # Create files location if not skip_file_location: run_command("files location --default ils /tmp/ils-files") # Generate demo data if not skip_demo_data: run_command("demo data") click.secho("ils setup finished successfully", fg="blue")
# -*- coding: utf-8 -*- """B2SHARE base Invenio configuration.""" from __future__ import absolute_import, print_function from invenio_base.app import create_cli from .factory import create_app as b2share_cli # B2SHARE CLI application. cli = create_cli(create_app=b2share_cli)
def setup(skip_db_destroy, skip_demo_data, skip_patrons, verbose): """ILS setup command.""" from flask import current_app from invenio_base.app import create_cli import redis click.secho('ils setup started...', fg='blue') # Clean redis redis.StrictRedis.from_url( current_app.config['CACHE_REDIS_URL']).flushall() click.secho('redis cache cleared...', fg='red') cli = create_cli() runner = current_app.test_cli_runner() def run_command(command, catch_exceptions=False): click.secho('ils {}...'.format(command), fg='green') res = runner.invoke(cli, command, catch_exceptions=catch_exceptions) if verbose: click.secho(res.output) # Remove and create db and indexes if not skip_db_destroy: run_command('db destroy --yes-i-know', catch_exceptions=True) run_command('db init create') run_command('index destroy --force --yes-i-know') run_command('index init --force') run_command('index queue init purge') # Create roles to restrict access run_command('roles create admin') run_command('roles create librarian') if not skip_patrons: # Create users run_command( 'users create [email protected] -a --password=123456') # ID 1 run_command( 'users create [email protected] -a --password=123456') # ID 2 run_command('users create [email protected] -a --password=123456') # ID 3 run_command( 'users create [email protected] -a --password=123456') # ID 4 run_command( 'users create [email protected] -a --password=123456') # ID 5 run_command( 'users create [email protected] -a --password=123456') # ID 6 # Assign roles run_command('roles add [email protected] admin') run_command('roles add [email protected] librarian') # Assign actions run_command('access allow superuser-access role admin') run_command('access allow ils-backoffice-access role librarian') # Index patrons run_command('patrons index') # Generate demo data if not skip_demo_data: run_command('demo data') click.secho('ils setup finished successfully', fg='blue')