Beispiel #1
0
def get_profile_config(profile, conf_dict=None):
    """
    Return the profile specific configurations

    :param conf_dict: if passed, use the provided dictionary rather than reading
        it from file.
    """
    import sys
    import tempfile

    from aiida.common.exceptions import ConfigurationError, ProfileConfigurationError

    if conf_dict is None:
        confs = get_config()
    else:
        confs = conf_dict

    try:
        profile_info = confs['profiles'][profile]
    except KeyError:
        raise ProfileConfigurationError(
            "No profile configuration found for {}, allowed values are: {}.".format(
                profile, ', '.join(get_profiles_list())))

    return profile_info
Beispiel #2
0
def set_default_profile(process, profile, force_rewrite=False):
    """
    Set a default db profile to be used by a process (default for verdi,
    default for daemon, ...)

    :param process: A string identifying the process to modify (e.g. ``verdi``
      or ``daemon``).
    :param profile: A string specifying the profile that should be used
      as default.
    :param force_rewrite: if False, does not change the default profile
      if this was already set. Otherwise, forces the default profile to be
      the value specified as ``profile`` also if a default profile for the
      given ``process`` was already set.
    """
    from aiida.common.exceptions import ProfileConfigurationError

    if profile not in get_profiles_list():
        raise ProfileConfigurationError(
            'Profile {} has not been configured'.format(profile))
    confs = get_config()

    try:
        confs['default_profiles']
    except KeyError:
        confs['default_profiles'] = {}

    if force_rewrite:
        confs['default_profiles'][process] = profile
    else:
        confs['default_profiles'][process] = confs['default_profiles'].get(
            process, profile)
    backup_config()
    store_config(confs)
Beispiel #3
0
def set_default_profile(profile, force_rewrite=False):
    """
    Set the default profile

    :param profile: A string specifying the profile that should be used as default
    :param force_rewrite: if False, does not change the default profile if already set
    """
    from aiida.common.exceptions import ProfileConfigurationError

    if profile not in get_profiles_list():
        raise ProfileConfigurationError('Profile {} has not been configured'.format(profile))

    confs = get_config()
    current_default_profile = confs.get('default_profile', None)

    if current_default_profile is None or force_rewrite:
        confs['default_profile'] = profile

    backup_config()
    store_config(confs)
Beispiel #4
0
def get_profile_config(profile, conf_dict=None, set_test_location=True):
    """
    Return the profile specific configurations

    :param conf_dict: if passed, use the provided dictionary rather than reading
        it from file.
    :param set_test_location: if True, sets a new folder for storing repository
        files during testing (to avoid to replace/overwrite the real repository)
        Set to False for calls where the folder should not be changed (i.e., if
        you only want to get the profile
    """
    import sys
    import tempfile

    from aiida.common.exceptions import (ConfigurationError,
                                         ProfileConfigurationError)

    if conf_dict is None:
        confs = get_config()
    else:
        confs = conf_dict

    test_string = ""
    # is_test = False
    # test_prefix = "test_"
    # if profile.startswith(test_prefix):
    #     # Use the same profile
    #     profile = profile[len(test_prefix):]
    #     is_test = True
    #     test_string = "(test) "

    try:
        profile_info = confs['profiles'][profile]
    except KeyError:
        raise ProfileConfigurationError(
            "No {}profile configuration found for {}, "
            "allowed values are: {}.".format(test_string, profile,
                                             ", ".join(get_profiles_list())))

    # if is_test and set_test_location:
    #     # import traceback
    #     # traceback.print_stack()
    #     # Change the repository and print a message
    #     ###################################################################
    #     # IMPORTANT! Choose a different repository location, otherwise
    #     # real data will be destroyed during tests!!
    #     # The location is automatically created with the tempfile module
    #     # Typically, under linux this is created under /tmp
    #     # and is not deleted at the end of the run.
    #     global TEMP_TEST_REPO
    #     if TEMP_TEST_REPO is None:
    #         TEMP_TEST_REPO = tempfile.mkdtemp(prefix=TEMP_TEST_REPO_PREFIX)
    #         # We write the local repository on stderr, so that the user running
    #         # the tests knows where the files are being stored
    #         print >> sys.stderr, "############################################"
    #         print >> sys.stderr, "# Creating LOCAL AiiDA REPOSITORY FOR TESTS:"
    #         print >> sys.stderr, "# {}".format(TEMP_TEST_REPO)
    #         print >> sys.stderr, "############################################"
    #     if 'AIIDADB_REPOSITORY_URI' not in profile_info:
    #         raise ConfigurationError("Config file has not been found, run "
    #                                  "verdi install first")
    #     profile_info['AIIDADB_REPOSITORY_URI'] = 'file://' + TEMP_TEST_REPO

    return profile_info