def load_profile(process=None, profile=None): """ Load the profile. This function is called by load_dbenv and SHOULD NOT be called by the user by hand. """ if settings.LOAD_PROFILE_CALLED: raise InvalidOperation("You cannot call load_profile multiple times!") settings.LOAD_PROFILE_CALLED = True # settings.CURRENT_AIIDADB_PROCESS should always be defined # by either verdi or the deamon if settings.CURRENT_AIIDADB_PROCESS is None and process is None: # This is for instance the case of a python script containing a # 'load_dbenv()' command and run with python settings.CURRENT_AIIDADB_PROCESS = DEFAULT_PROCESS elif (process is not None and process != settings.CURRENT_AIIDADB_PROCESS): ## The user specified a process that is different from the current one # I re-set the process settings.CURRENT_AIIDADB_PROCESS = process # I also remove the old profile settings.AIIDADB_PROFILE = None if settings.AIIDADB_PROFILE is not None: if profile is not None and profile != settings.AIIDADB_PROFILE: raise ValueError("Error in profile loading.") else: if profile is not None: the_profile = profile else: the_profile = get_default_profile( settings.CURRENT_AIIDADB_PROCESS) settings.AIIDADB_PROFILE = the_profile config = get_profile_config(settings.AIIDADB_PROFILE) # Check if AIIDADB_BACKEND is set and if not error (with message) # Migration script should put it in profile (config.json) settings.BACKEND = config.get("AIIDADB_BACKEND", BACKEND_DJANGO)
def profile_list(): """ Displays list of all available profiles. """ from aiida.common.setup import get_profiles_list, get_default_profile, AIIDA_CONFIG_FOLDER from aiida.common.exceptions import ConfigurationError echo.echo_info('Configuration folder: {}'.format(AIIDA_CONFIG_FOLDER)) try: default_profile = get_default_profile() except ConfigurationError as err: err_msg = ( "Stopping: {}\n" "Note: if no configuration file was found, it means that you have not run\n" "'verdi setup' yet to configure at least one AiiDA profile.". format(err.message)) echo.echo_critical(err_msg) if default_profile is None: echo.echo_critical( "### No default profile configured yet, run 'verdi install'! ###") else: echo.echo_info( 'The default profile is highlighted and marked by the * symbol') for profile in get_profiles_list(): color_id = '' if profile == default_profile: symbol = '*' color_id = 'green' else: symbol = ' ' click.secho('{} {}'.format(symbol, profile), fg=color_id)
def load_profile(profile=None): """ Load the profile. This function is called by load_dbenv and SHOULD NOT be called by the user by hand. """ if settings.LOAD_PROFILE_CALLED: raise InvalidOperation('You cannot call multiple times!') settings.LOAD_PROFILE_CALLED = True if settings.AIIDADB_PROFILE is not None: if profile is not None and profile != settings.AIIDADB_PROFILE: raise ValueError('Error in profile loading') else: if profile is None: profile = get_default_profile() settings.AIIDADB_PROFILE = profile config = get_profile_config(settings.AIIDADB_PROFILE) # Check if AIIDADB_BACKEND is set and if not error (with message) # Migration script should put it in profile (config.json) settings.BACKEND = config.get('AIIDADB_BACKEND', BACKEND_DJANGO)
import click from circus import logger, get_arbiter from circus.circusd import get_maxfd, daemonize, closerange from circus.arbiter import Arbiter from circus.pidfile import Pidfile from circus import __version__ from circus.util import configure_logger from circus.util import check_future_exception_and_log from circus.client import CircusClient from circus.exc import CallError from aiida import load_dbenv load_dbenv() from aiida.common.setup import get_config, get_default_profile, CIRCUS_PORT_KEY, generate_new_circus_port, update_profile DEFAULT_PROFILE = get_default_profile('verdi') PROFILE_OPT = click.option('--profile', required=True, default=DEFAULT_PROFILE) VERDI_BIN = os.path.abspath(os.path.join(sys.executable, '../verdi')) VIRTUALENV = os.path.abspath(os.path.join(sys.executable, '../../')) class ProfileConfig(object): _ENDPOINT_TPL = 'tcp://127.0.0.1:{port}' def __init__(self, profile): self.profile = profile self.config = get_config() self.profile_config = self.config['profiles'][self.profile] self.profile_config[CIRCUS_PORT_KEY] = self.profile_config.get( CIRCUS_PORT_KEY, generate_new_circus_port(self.profile)) update_profile(profile, self.profile_config)
def profile_list(self, *args): from aiida.common.setup import get_profiles_list, get_default_profile from aiida.backends import settings current_profile = settings.AIIDADB_PROFILE default_profile = get_default_profile(settings.CURRENT_AIIDADB_PROCESS) default_daemon_profile = get_default_profile("daemon") if current_profile is None: current_profile = default_profile use_colors = False if args: try: if len(args) != 1: raise ValueError if args[0] != "--color": raise ValueError use_colors = True except ValueError: print >> sys.stderr, ( "You can pass only one further argument, " "--color, to show the results with colors") sys.exit(1) if current_profile is not None: # print >> sys.stderr, "### The '>' symbol indicates the current default user ###" pass else: print >> sys.stderr, "### No default profile configured yet, "\ "run 'verdi install'! ###" for profile in get_profiles_list(): color_id = 39 # Default foreground color if profile == current_profile: symbol = ">" color_id = 31 else: symbol = "*" if profile == default_profile: color_id = 34 default_str = ' (DEFAULT)' else: default_str = '' if profile == default_daemon_profile: default_str += ' (DAEMON PROFILE)' if use_colors: start_color = "\x1b[{}m".format(color_id) end_color = "\x1b[0m" bold_sequence = "\x1b[1;{}m".format(color_id) nobold_sequence = "\x1b[0;{}m".format(color_id) else: start_color = "" end_color = "" bold_sequence = "" nobold_sequence = "" print "{}{} {}{}{} {}{}".format(start_color, symbol, bold_sequence, profile, default_str, nobold_sequence, end_color)
def get_current_profile_name(): """ Return the currently configured profile name or if not set, the default profile """ return settings.AIIDADB_PROFILE or setup.get_default_profile()
def profile_list(self, *args): from aiida.common.setup import get_profiles_list, get_default_profile, AIIDA_CONFIG_FOLDER from aiida.common.exceptions import ConfigurationError from aiida.backends import settings print('Configuration folder: {}'.format(AIIDA_CONFIG_FOLDER)) current_profile = settings.AIIDADB_PROFILE try: default_profile = get_default_profile( settings.CURRENT_AIIDADB_PROCESS) except ConfigurationError as e: err_msg = ( "Stopping: {}\n" "Note: if no configuration file was found, it means that you have not run\n" "'verdi setup' yet to configure at least one AiiDA profile.". format(e.message)) click.echo(err_msg, err=True) sys.exit(1) default_daemon_profile = get_default_profile("daemon") if current_profile is None: current_profile = default_profile use_colors = False if args: try: if len(args) != 1: raise ValueError if args[0] != "--color": raise ValueError use_colors = True except ValueError: print >> sys.stderr, ( "You can pass only one further argument, " "--color, to show the results with colors") sys.exit(1) if current_profile is not None: # print >> sys.stderr, "### The '>' symbol indicates the current default user ###" pass else: print >> sys.stderr, "### No default profile configured yet, "\ "run 'verdi install'! ###" for profile in get_profiles_list(): color_id = 39 # Default foreground color if profile == current_profile: symbol = ">" color_id = 31 else: symbol = "*" if profile == default_profile: color_id = 34 default_str = ' (DEFAULT)' else: default_str = '' if profile == default_daemon_profile: default_str += ' (DAEMON PROFILE)' if use_colors: start_color = "\x1b[{}m".format(color_id) end_color = "\x1b[0m" bold_sequence = "\x1b[1;{}m".format(color_id) nobold_sequence = "\x1b[0;{}m".format(color_id) else: start_color = "" end_color = "" bold_sequence = "" nobold_sequence = "" print "{}{} {}{}{} {}{}".format(start_color, symbol, bold_sequence, profile, default_str, nobold_sequence, end_color)