def reset(environment, opts): """Resets a site to the default state. This will re-initialize the database and recreate the administrator account. Usage: datacats reset [-yn] [-s NAME] [ENVIRONMENT] Options: -s --site=NAME The site to reset [default: primary] -y --yes Respond yes to all questions -n --no-sysadmin Don't prompt for a sysadmin password""" # pylint: disable=unused-argument if not opts['--yes']: y_or_n_prompt('Reset will remove all data related to the ' 'site {} and recreate the database'.format(opts['--site'])) print 'Resetting...' environment.stop_supporting_containers() environment.stop_ckan() # Save the port. saved_port = environment.port environment.purge_data([opts['--site']], never_delete=True) init({ 'ENVIRONMENT_DIR': opts['ENVIRONMENT'], '--site': opts['--site'], 'PORT': saved_port, '--syslog': None, '--address': '127.0.0.1', '--image-only': False, '--no-sysadmin': opts['--no-sysadmin'], '--site-url': None }, no_install=True)
def reset(environment, opts): """Resets a site to the default state. This will re-initialize the database and recreate the administrator account. Usage: datacats reset [-yn] [-s NAME] [ENVIRONMENT] Options: -s --site=NAME The site to reset [default: primary] -y --yes Respond yes to all questions -n --no-sysadmin Don't prompt for a sysadmin password""" # pylint: disable=unused-argument if not opts['--yes']: y_or_n_prompt('Reset will remove all data related to the ' 'site {} and recreate the database'.format( opts['--site'])) print 'Resetting...' environment.stop_supporting_containers() environment.stop_ckan() # Save the port. saved_port = environment.port environment.purge_data([opts['--site']], never_delete=True) init( { 'ENVIRONMENT_DIR': opts['ENVIRONMENT'], '--site': opts['--site'], 'PORT': saved_port, '--syslog': None, '--address': '127.0.0.1', '--image-only': False, '--no-sysadmin': opts['--no-sysadmin'], '--site-url': None }, no_install=True)
def purge(opts): """Purge environment database and uploaded files Usage: datacats purge [-s NAME | --delete-environment] [-y] [ENVIRONMENT] Options: --delete-environment Delete environment directory as well as its data, as well as the data for **all** sites. -s --site=NAME Specify a site to be purge [default: primary] -y --yes Respond yes to all prompts (i.e. force) ENVIRONMENT may be an environment name or a path to an environment directory. Default: '.' """ old = False try: environment = Environment.load(opts['ENVIRONMENT'], opts['--site']) except DatacatsError: environment = Environment.load(opts['ENVIRONMENT'], opts['--site'], data_only=True) if get_format_version(environment.datadir) == 1: old = True environment = Environment.load(opts['ENVIRONMENT'], opts['--site'], allow_old=True) # We need a valid site if they don't want to blow away everything. if not opts['--delete-environment'] and not old: environment.require_valid_site() sites = [opts['--site'] ] if not opts['--delete-environment'] else environment.sites if not opts['--yes']: y_or_n_prompt('datacats purge will delete all stored data') environment.stop_ckan() environment.stop_supporting_containers() environment.purge_data(sites) if opts['--delete-environment']: if environment.target: rmtree(environment.target) else: DatacatsError( ("Unable to find the environment source" " directory so that it can be deleted.\n" "Chances are it's because it already does not exist"))
def purge(opts): """Purge environment database and uploaded files Usage: datacats purge [-s NAME | --delete-environment] [-y] [ENVIRONMENT] Options: --delete-environment Delete environment directory as well as its data, as well as the data for **all** sites. -s --site=NAME Specify a site to be purge [default: primary] -y --yes Respond yes to all prompts (i.e. force) ENVIRONMENT may be an environment name or a path to an environment directory. Default: '.' """ old = False try: environment = Environment.load(opts['ENVIRONMENT'], opts['--site']) except DatacatsError: environment = Environment.load(opts['ENVIRONMENT'], opts['--site'], data_only=True) if get_format_version(environment.datadir) == 1: old = True environment = Environment.load(opts['ENVIRONMENT'], opts['--site'], allow_old=True) # We need a valid site if they don't want to blow away everything. if not opts['--delete-environment'] and not old: environment.require_valid_site() sites = [opts['--site']] if not opts['--delete-environment'] else environment.sites if not opts['--yes']: y_or_n_prompt('datacats purge will delete all stored data') environment.stop_ckan() environment.stop_supporting_containers() environment.purge_data(sites) if opts['--delete-environment']: if environment.target: rmtree(environment.target) else: DatacatsError(("Unable to find the environment source" " directory so that it can be deleted.\n" "Chances are it's because it already does not exist"))