Example #1
0
def cmd_profile_create(profile_name,
                       cache_profiles_path,
                       output,
                       detect=False):
    profile_path = get_profile_path(profile_name,
                                    cache_profiles_path,
                                    get_cwd(),
                                    exists=False)
    if os.path.exists(profile_path):
        raise ConanException("Profile already exists")

    profile = Profile()
    if detect:
        settings = detect_defaults_settings(output)
        for name, value in settings:
            profile.settings[name] = value

    contents = profile.dumps()
    save(profile_path, contents)

    if detect:
        output.info("Profile created with detected settings: %s" %
                    profile_path)
    else:
        output.info("Empty profile created: %s" % profile_path)
    return profile_path
Example #2
0
def cmd_profile_delete_key(profile_name, key, cache_profiles_path):
    first_key, rest_key = _get_profile_keys(key)
    profile, _ = read_profile(profile_name, get_cwd(), cache_profiles_path)

    try:
        package, name = rest_key.split(":")
    except ValueError:
        package = None
        name = rest_key

    try:
        if first_key == "settings":
            del profile.settings[rest_key]
        elif first_key == "options":
            profile.options.remove(name, package)
        elif first_key == "env":
            profile.env_values.remove(name, package)
        elif first_key == "build_requires":
            raise ConanException("Edit the profile manually to delete a build_require")
    except KeyError:
        raise ConanException("Profile key '%s' doesn't exist" % key)

    contents = profile.dumps()
    profile_path = get_profile_path(profile_name, cache_profiles_path, get_cwd())
    save(profile_path, contents)
Example #3
0
def cmd_profile_delete_key(profile_name, key, cache_profiles_path):
    first_key, rest_key = _get_profile_keys(key)
    profile, _ = read_profile(profile_name, get_cwd(), cache_profiles_path)

    try:
        package, name = rest_key.split(":")
    except ValueError:
        package = None
        name = rest_key

    try:
        if first_key == "settings":
            del profile.settings[rest_key]
        elif first_key == "options":
            profile.options.remove(name, package)
        elif first_key == "env":
            profile.env_values.remove(name, package)
        elif first_key == "build_requires":
            raise ConanException(
                "Edit the profile manually to delete a build_require")
    except KeyError:
        raise ConanException("Profile key '%s' doesn't exist" % key)

    contents = profile.dumps()
    profile_path = get_profile_path(profile_name, cache_profiles_path,
                                    get_cwd())
    save(profile_path, contents)
Example #4
0
    def delete_profile_key(self, profile_name, key):
        first_key, rest_key = self._get_profile_keys(key)
        profile, _ = read_profile(profile_name, os.getcwd(), self._client_cache.profiles_path)

        # For options, scopes, env vars
        try:
            package, name = rest_key.split(":")
        except ValueError:
            package = None
            name = rest_key

        try:
            if first_key == "settings":
                del profile.settings[rest_key]
            elif first_key == "options":
                profile.options.remove(name, package)
            elif first_key == "env":
                profile.env_values.remove(name, package)
            elif first_key == "scopes":
                profile.scopes.remove(name, package)
            elif first_key == "build_requires":
                raise ConanException("Edit the profile manually to delete a build_require")
        except KeyError:
            raise ConanException("Profile key '%s' doesn't exist" % key)

        contents = profile.dumps()
        profile_path = get_profile_path(profile_name, self._client_cache.profiles_path, os.getcwd())
        save(profile_path, contents)
Example #5
0
    def update_profile(self, profile_name, key, value):
        first_key, rest_key = self._get_profile_keys(key)

        profile, _ = read_profile(profile_name, os.getcwd(),
                                  self._client_cache.profiles_path)
        if first_key == "settings":
            profile.settings[rest_key] = value
        elif first_key == "options":
            tmp = OptionsValues([(rest_key, value)])
            profile.options.update(tmp)
        elif first_key == "env":
            profile.env_values.update(
                EnvValues.loads("%s=%s" % (rest_key, value)))
        elif first_key == "scopes":
            profile.update_scopes(
                Scopes.from_list(["%s=%s" % (rest_key, value)]))
        elif first_key == "build_requires":
            raise ConanException(
                "Edit the profile manually to change the build_requires")

        contents = profile.dumps()
        profile_path = get_profile_path(profile_name,
                                        self._client_cache.profiles_path,
                                        os.getcwd())
        save(profile_path, contents)
Example #6
0
    def create_profile(self, profile_name, detect=False):
        profile_path = get_profile_path(profile_name, self._client_cache.profiles_path, os.getcwd())
        if os.path.exists(profile_path):
            raise ConanException("Profile already exists")

        profile = Profile()
        if detect:
            settings = detect_defaults_settings(self._user_io.out)
            for name, value in settings:
                profile.settings[name] = value

        contents = profile.dumps()
        save(profile_path, contents)
        self._user_io.out.info("Empty profile created: %s" % profile_path)
        return profile_path
Example #7
0
def cmd_profile_update(profile_name, key, value, cache_profiles_path):
    first_key, rest_key = _get_profile_keys(key)

    profile, _ = read_profile(profile_name, get_cwd(), cache_profiles_path)
    if first_key == "settings":
        profile.settings[rest_key] = value
    elif first_key == "options":
        tmp = OptionsValues([(rest_key, value)])
        profile.options.update(tmp)
    elif first_key == "env":
        profile.env_values.update_replace(rest_key, value)
    elif first_key == "build_requires":
        raise ConanException("Edit the profile manually to change the build_requires")

    contents = profile.dumps()
    profile_path = get_profile_path(profile_name, cache_profiles_path, get_cwd())
    save(profile_path, contents)
Example #8
0
def cmd_profile_create(profile_name, cache_profiles_path, output, detect=False):
    profile_path = get_profile_path(profile_name, cache_profiles_path, get_cwd(),
                                    exists=False)
    if os.path.exists(profile_path):
        raise ConanException("Profile already exists")

    profile = Profile()
    if detect:
        settings = detect_defaults_settings(output)
        for name, value in settings:
            profile.settings[name] = value

    contents = profile.dumps()
    save(profile_path, contents)

    if detect:
        output.info("Profile created with detected settings: %s" % profile_path)
    else:
        output.info("Empty profile created: %s" % profile_path)
    return profile_path