Ejemplo n.º 1
0
    def __init__(self, text):
        self.vars = OrderedDict()  # Order matters, if user declares F=1 and then FOO=12,
        # and in profile MYVAR=$FOO, it will
        self.includes = []
        self.profile_text = ""

        for counter, line in enumerate(text.splitlines()):
            if not line.strip() or line.strip().startswith("#"):
                continue
            elif line.strip().startswith("["):
                self.profile_text = "\n".join(text.splitlines()[counter:])
                break
            elif line.strip().startswith("include("):
                include = line.split("include(", 1)[1]
                if not include.endswith(")"):
                    raise ConanException("Invalid include statement")
                include = include[:-1]
                self.includes.append(include)
            else:
                name, value = line.split("=", 1)
                name = name.strip()
                if " " in name:
                    raise ConanException("The names of the variables cannot contain spaces")
                value = unquote(value)
                self.vars[name] = value
Ejemplo n.º 2
0
 def _env_c(self, var_name, env_var_name, default_value):
     env = os.environ.get(env_var_name, None)
     if env is not None:
         return env
     try:
         return unquote(self.get_item(var_name))
     except ConanException:
         return default_value
Ejemplo n.º 3
0
 def _env_c(self, var_name, env_var_name, default_value):
     env = os.environ.get(env_var_name, None)
     if env is not None:
         return env
     try:
         return unquote(self.get_item(var_name))
     except ConanException:
         return default_value
Ejemplo n.º 4
0
    def get_package_name_value(item):
        """Parse items like package:name=value or name=value"""
        package_name = None
        if ":" in item:
            tmp = item.split(":", 1)
            package_name, item = tmp

        name, value = item.split("=", 1)
        name = name.strip()
        value = unquote(value)
        return package_name, name, value
Ejemplo n.º 5
0
 def _env_c(self, var_name, env_var_name, default_value):
     """ Returns the value Conan will use: first tries with environment variable,
         then value written in 'conan.conf' and fallback to 'default_value'
     """
     env = os.environ.get(env_var_name, None)
     if env is not None:
         return env
     try:
         return unquote(self.get_item(var_name))
     except ConanException:
         return default_value
Ejemplo n.º 6
0
    def get_package_name_value(item):
        """Parse items like package:name=value or name=value"""
        packagename = None
        if ":" in item:
            tmp = item.split(":", 1)
            packagename, item = tmp

        result_name, result_value = item.split("=", 1)
        result_name = result_name.strip()
        result_value = unquote(result_value)
        return packagename, result_name, result_value
Ejemplo n.º 7
0
    def get_package_name_value(item):
        """Parse items like package:name=value or name=value"""
        package_name = None
        if ":" in item:
            tmp = item.split(":", 1)
            package_name, item = tmp

        name, value = item.split("=", 1)
        name = name.strip()
        value = unquote(value)
        return package_name, name, value
Ejemplo n.º 8
0
    def default_profile(self):
        ret = os.environ.get("CONAN_DEFAULT_PROFILE_PATH", None)
        if ret:
            if not os.path.isabs(ret):
                from conans.client.cache.cache import PROFILES_FOLDER
                profiles_folder = os.path.join(os.path.dirname(self.filename), PROFILES_FOLDER)
                ret = os.path.abspath(os.path.join(profiles_folder, ret))

            if not os.path.exists(ret):
                raise ConanException("Environment variable 'CONAN_DEFAULT_PROFILE_PATH' "
                                     "must point to an existing profile file.")
            return ret
        else:
            try:
                return unquote(self.get_item("general.default_profile"))
            except ConanException:
                return DEFAULT_PROFILE_NAME
Ejemplo n.º 9
0
    def __init__(self, text):
        """ divides the text in 3 items:
        - self.vars: Dictionary with variable=value declarations
        - self.includes: List of other profiles to include
        - self.profile_text: the remaining, containing settings, options, env, etc
        """
        self.vars = OrderedDict(
        )  # Order matters, if user declares F=1 and then FOO=12,
        # and in profile MYVAR=$FOO, it will
        self.includes = []
        self.profile_text = ""

        for counter, line in enumerate(text.splitlines()):
            if not line.strip() or line.strip().startswith("#"):
                continue
            elif line.strip().startswith("["):
                self.profile_text = "\n".join(text.splitlines()[counter:])
                break
            elif line.strip().startswith("include("):
                include = line.split("include(", 1)[1]
                if not include.endswith(")"):
                    raise ConanException("Invalid include statement")
                include = include[:-1]
                self.includes.append(include)
            else:
                try:
                    name, value = line.split("=", 1)
                except ValueError:
                    raise ConanException("Error while parsing line %i: '%s'" %
                                         (counter, line))
                name = name.strip()
                if " " in name:
                    raise ConanException(
                        "The names of the variables cannot contain spaces")
                value = unquote(value)
                self.vars[name] = value