示例#1
0
def decode_text(text):
    import codecs
    encodings = {
        codecs.BOM_UTF8: "utf_8_sig",
        codecs.BOM_UTF16_BE: "utf_16_be",
        codecs.BOM_UTF16_LE: "utf_16_le",
        codecs.BOM_UTF32_BE: "utf_32_be",
        codecs.BOM_UTF32_LE: "utf_32_le",
        b'\x2b\x2f\x76\x38': "utf_7",
        b'\x2b\x2f\x76\x39': "utf_7",
        b'\x2b\x2f\x76\x2b': "utf_7",
        b'\x2b\x2f\x76\x2f': "utf_7",
        b'\x2b\x2f\x76\x38\x2d': "utf_7"
    }
    for bom in sorted(encodings, key=len, reverse=True):
        if text.startswith(bom):
            try:
                return text[len(bom):].decode(encodings[bom])
            except UnicodeDecodeError:
                continue
    decoders = ["utf-8", "Windows-1252"]
    for decoder in decoders:
        try:
            return text.decode(decoder)
        except UnicodeDecodeError:
            continue
    logger.warning("can't decode %s" % str(text))
    return text.decode("utf-8", "ignore")  # Ignore not compatible characters
示例#2
0
def get_generator(conanfile):
    # Returns the name of the generator to be used by CMake
    if "CONAN_CMAKE_GENERATOR" in os.environ:
        return os.environ["CONAN_CMAKE_GENERATOR"]

    compiler = conanfile.settings.get_safe("compiler")
    arch = conanfile.settings.get_safe("arch")
    compiler_version =conanfile. settings.get_safe("compiler.version")
    os_build, _, _, _ = get_cross_building_settings(conanfile)

    if not compiler or not compiler_version or not arch:
        if os_build == "Windows":
            logger.warning("CMake generator could not be deduced from settings")
            return None
        return "Unix Makefiles"

    if compiler == "Visual Studio":
        _visuals = {'8': '8 2005',
                    '9': '9 2008',
                    '10': '10 2010',
                    '11': '11 2012',
                    '12': '12 2013',
                    '14': '14 2015',
                    '15': '15 2017',
                    '16': '16 2019'}.get(compiler_version, "UnknownVersion %s" % compiler_version)
        base = "Visual Studio %s" % _visuals
        return base

    # The generator depends on the build machine, not the target
    if os_build == "Windows" and compiler != "qcc":
        return "MinGW Makefiles"  # it is valid only under Windows

    return "Unix Makefiles"
示例#3
0
文件: files.py 项目: manuelbcd/conan
def decode_text(text, encoding="auto"):
    bom_length = 0
    if encoding == "auto":
        encoding, bom_length = _detect_encoding(text)
        if encoding is None:
            logger.warning("can't decode %s" % str(text))
            return text.decode("utf-8", "ignore")  # Ignore not compatible characters
    return text[bom_length:].decode(encoding)
示例#4
0
文件: files.py 项目: yochju/conan
def decode_text(text):
    decoders = ["utf-8", "Windows-1252"]
    for decoder in decoders:
        try:
            return text.decode(decoder)
        except UnicodeDecodeError:
            continue
    logger.warning("can't decode %s" % str(text))
    return text.decode("utf-8", "ignore")  # Ignore not compatible characters
示例#5
0
def path_shortener(path, short_paths):
    """ short_paths is 4-state:
    False: Never shorten the path
    True: Always shorten the path, create link if not existing
    None: Use shorten path only if already exists, not create
    """
    use_always_short_paths = get_env("CONAN_USE_ALWAYS_SHORT_PATHS", False)
    short_paths = use_always_short_paths or short_paths

    if short_paths is False or os.getenv("CONAN_USER_HOME_SHORT") == "None":
        return path
    link = os.path.join(path, CONAN_LINK)
    if os.path.exists(link):
        return load(link)
    elif short_paths is None:
        return path

    if os.path.exists(path):
        rmdir(path)

    short_home = os.getenv("CONAN_USER_HOME_SHORT")
    if not short_home:
        drive = os.path.splitdrive(path)[0]
        short_home = os.path.join(drive, os.sep, ".conan")
    mkdir(short_home)

    # Workaround for short_home living in NTFS file systems. Give full control permission
    # to current user to avoid
    # access problems in cygwin/msys2 windows subsystems when using short_home folder
    try:
        userdomain, username = os.getenv("USERDOMAIN"), os.environ["USERNAME"]
        domainname = "%s\%s" % (userdomain,
                                username) if userdomain else username
        cmd = r'cacls %s /E /G "%s":F' % (short_home, domainname)
        subprocess.check_output(
            cmd,
            stderr=subprocess.STDOUT)  # Ignoring any returned output, quiet
    except subprocess.CalledProcessError:
        # cmd can fail if trying to set ACL in non NTFS drives, ignoring it.
        pass

    redirect = hashed_redirect(short_home, path)
    if not redirect:
        logger.warning("Failed to create a deterministic short path in %s",
                       short_home)
        redirect = tempfile.mkdtemp(dir=short_home, prefix="")

    # Save the full path of the local cache directory where the redirect is from.
    # This file is for debugging purposes and not used by Conan.
    save(os.path.join(redirect, CONAN_REAL_PATH), path)

    # This "1" is the way to have a non-existing directory, so commands like
    # shutil.copytree() to it, works. It can be removed without compromising the
    # temp folder generator and conan-links consistency
    redirect = os.path.join(redirect, "1")
    save(link, redirect)
    return redirect
示例#6
0
    def remove_packages(self, ref, package_ids):
        """ Remove any packages specified by package_ids"""
        self.check_credentials()

        if ref.revision is None:
            # Remove the packages from all the RREVs
            revisions = self.get_recipe_revisions(ref)
            refs = [ref.copy_with_rev(rev["revision"]) for rev in revisions]
        else:
            refs = [ref]

        for ref in refs:
            assert ref.revision is not None, "remove_packages needs RREV"
            if not package_ids:
                url = self.router.remove_all_packages(ref)
                response = self.requester.delete(url,
                                                 auth=self.auth,
                                                 verify=self.verify_ssl,
                                                 headers=self.custom_headers)
                if response.status_code == 404:
                    # Double check if it is a 404 because there are no packages
                    try:
                        package_search_url = self.router.search_packages(ref)
                        if not self.get_json(package_search_url):
                            return
                    except Exception as e:
                        logger.warning("Unexpected error searching {} packages"
                                       " in remote {}: {}".format(
                                           ref, self.remote_url, e))
                if response.status_code != 200:  # Error message is text
                    # To be able to access ret.text (ret.content are bytes)
                    response.charset = "utf-8"
                    raise get_exception_from_error(response.status_code)(
                        response.text)
            else:
                for pid in package_ids:
                    pref = PackageReference(ref, pid)
                    revisions = self.get_package_revisions(pref)
                    prefs = [
                        pref.copy_with_revs(ref.revision, rev["revision"])
                        for rev in revisions
                    ]
                    for pref in prefs:
                        url = self.router.remove_package(pref)
                        response = self.requester.delete(
                            url,
                            auth=self.auth,
                            headers=self.custom_headers,
                            verify=self.verify_ssl)
                        if response.status_code == 404:
                            raise PackageNotFoundException(pref)
                        if response.status_code != 200:  # Error message is text
                            # To be able to access ret.text (ret.content are bytes)
                            response.charset = "utf-8"
                            raise get_exception_from_error(
                                response.status_code)(response.text)
示例#7
0
文件: files.py 项目: manuelbcd/conan
    def safemembers(members):
        base = realpath(abspath(destination_dir))

        for finfo in members:
            if badpath(finfo.name, base) or finfo.islnk():
                logger.warning("file:%s is skipped since it's not safe." % str(finfo.name))
                continue
            else:
                # Fixes unzip a windows zipped file in linux
                finfo.name = finfo.name.replace("\\", "/")
                yield finfo
示例#8
0
def get_generator(conanfile):
    # Returns the name of the generator to be used by CMake
    if "CONAN_CMAKE_GENERATOR" in os.environ:
        return os.environ["CONAN_CMAKE_GENERATOR"]

    compiler = conanfile.settings.get_safe("compiler")
    compiler_base = conanfile.settings.get_safe("compiler.base")
    arch = conanfile.settings.get_safe("arch")
    compiler_version = conanfile.settings.get_safe("compiler.version")
    compiler_base_version = conanfile.settings.get_safe(
        "compiler.base.version")
    os_build, _, _, _ = get_cross_building_settings(conanfile)

    if not compiler or not compiler_version or not arch:
        if os_build == "Windows":
            logger.warning(
                "CMake generator could not be deduced from settings")
            return None
        return "Unix Makefiles"

    cmake_years = {
        '8': '8 2005',
        '9': '9 2008',
        '10': '10 2010',
        '11': '11 2012',
        '12': '12 2013',
        '14': '14 2015',
        '15': '15 2017',
        '16': '16 2019',
        '17': '17 2022'
    }

    if compiler == "msvc":
        if compiler_version is None:
            raise ConanException("compiler.version must be defined")
        from conan.tools.microsoft.visual import vs_ide_version
        vs_version = vs_ide_version(conanfile)
        return "Visual Studio %s" % cmake_years[vs_version]

    if compiler == "Visual Studio" or compiler_base == "Visual Studio":
        version = compiler_base_version or compiler_version
        major_version = version.split('.', 1)[0]
        _visuals = cmake_years.get(major_version,
                                   "UnknownVersion %s" % version)
        base = "Visual Studio %s" % _visuals
        return base

    # The generator depends on the build machine, not the target
    if os_build == "Windows" and compiler != "qcc":
        return "MinGW Makefiles"  # it is valid only under Windows

    return "Unix Makefiles"
示例#9
0
 def remove_packages(self, ref, package_ids):
     """ Remove any packages specified by package_ids"""
     self.check_credentials()
     payload = {"package_ids": package_ids}
     url = self.router.remove_packages(ref)
     ret = self._post_json(url, payload)
     if not package_ids and ret.status_code == 404:
         # Double check if it is a 404 because there are no packages
         try:
             if not self.search_packages(ref, query=None):
                 return namedtuple("_", ['status_code', 'content'])(200,
                                                                    b'')
         except Exception as e:
             logger.warning("Unexpected error searching {} packages"
                            " in remote {}: {}".format(
                                ref, self.remote_url, e))
     return ret
示例#10
0
    def update(self, dep_env_info, pkg_name):
        self._dependencies_[pkg_name] = dep_env_info

        def merge_lists(seq1, seq2):
            return [s for s in seq1 if s not in seq2] + seq2

        # With vars if its set the keep the set value
        for varname, value in dep_env_info.vars.items():
            if varname not in self.vars:
                self.vars[varname] = value
            elif isinstance(self.vars[varname], list):
                if isinstance(value, list):
                    self.vars[varname] = merge_lists(self.vars[varname], value)
                else:
                    self.vars[varname] = merge_lists(self.vars[varname], [value])
            else:
                logger.warning("DISCARDED variable %s=%s from %s" % (varname, value, pkg_name))
示例#11
0
def get_generator(conanfile):
    # Returns the name of the generator to be used by CMake
    if "CONAN_CMAKE_GENERATOR" in os.environ:
        return os.environ["CONAN_CMAKE_GENERATOR"]

    compiler = conanfile.settings.get_safe("compiler")
    compiler_base = conanfile.settings.get_safe("compiler.base")
    arch = conanfile.settings.get_safe("arch")
    compiler_version = conanfile.settings.get_safe("compiler.version")
    compiler_base_version = conanfile.settings.get_safe(
        "compiler.base.version")
    if hasattr(conanfile, 'settings_build'):
        os_build = conanfile.settings_build.get_safe('os')
    else:
        os_build = conanfile.settings.get_safe('os_build')
    if os_build is None:  # Assume is the same specified in host settings, not cross-building
        os_build = conanfile.settings.get_safe("os")

    if not compiler or not compiler_version or not arch:
        if os_build == "Windows":
            logger.warning(
                "CMake generator could not be deduced from settings")
            return None
        return "Unix Makefiles"

    if compiler == "Visual Studio" or compiler_base == "Visual Studio":
        version = compiler_base_version or compiler_version
        _visuals = {
            '8': '8 2005',
            '9': '9 2008',
            '10': '10 2010',
            '11': '11 2012',
            '12': '12 2013',
            '14': '14 2015',
            '15': '15 2017',
            '16': '16 2019'
        }.get(version, "UnknownVersion %s" % version)
        base = "Visual Studio %s" % _visuals
        return base

    # The generator depends on the build machine, not the target
    if os_build == "Windows" and compiler != "qcc":
        return "MinGW Makefiles"  # it is valid only under Windows

    return "Unix Makefiles"
示例#12
0
def get_generator(settings):
    if "CONAN_CMAKE_GENERATOR" in os.environ:
        return os.environ["CONAN_CMAKE_GENERATOR"]

    compiler = settings.get_safe("compiler")
    arch = settings.get_safe("arch")
    compiler_version = settings.get_safe("compiler.version")
    os_build, _, _, _ = get_cross_building_settings(settings)
    os_host = settings.get_safe("os")

    if not compiler or not compiler_version or not arch:
        if os_build == "Windows":
            logger.warning(
                "CMake generator could not be deduced from settings")
            return None
        return "Unix Makefiles"

    if compiler == "Visual Studio":
        _visuals = {
            '8': '8 2005',
            '9': '9 2008',
            '10': '10 2010',
            '11': '11 2012',
            '12': '12 2013',
            '14': '14 2015',
            '15': '15 2017',
            '16': '16 2019'
        }
        base = "Visual Studio %s" % _visuals.get(
            compiler_version, "UnknownVersion %s" % compiler_version)
        if os_host != "WindowsCE" and Version(compiler_version) < "16":
            if arch == "x86_64":
                base += " Win64"
            elif "arm" in arch:
                base += " ARM"
        return base

    # The generator depends on the build machine, not the target
    if os_build == "Windows" and compiler != "qcc":
        return "MinGW Makefiles"  # it is valid only under Windows

    return "Unix Makefiles"
示例#13
0
def path_shortener(path, short_paths):
    """ short_paths is 4-state:
    False: Never shorten the path
    True: Always shorten the path, create link if not existing
    None: Use shorten path only if already exists, not create
    """
    use_always_short_paths = get_env("CONAN_USE_ALWAYS_SHORT_PATHS", False)
    short_paths = use_always_short_paths or short_paths

    if short_paths is False or os.getenv("CONAN_USER_HOME_SHORT") == "None":
        return path
    link = os.path.join(path, CONAN_LINK)
    if os.path.exists(link):
        return load(link)
    elif short_paths is None:
        return path

    if os.path.exists(path):
        rmdir(path)

    short_home = os.getenv("CONAN_USER_HOME_SHORT")
    if not short_home:
        if OSInfo().is_cygwin:
            try:
                cmd = ['cygpath', path, '--unix']
                out, _ = subprocess.Popen(cmd,
                                          stdout=subprocess.PIPE,
                                          shell=False).communicate()
                out = decode_text(out)
                if out.startswith('/cygdrive/'):  # It was a Windows 'path'
                    _, _, drive, _ = out.split('/', 3)
                    short_home = os.path.join('/cygdrive', drive, '.conan')
                else:  # It was a cygwin path, use a path inside the user home
                    short_home = os.path.join(os.path.expanduser("~"),
                                              '.conan_short')
            except Exception:
                raise ConanException(
                    "Conan failed to create the short_paths home for path '{}'"
                    " in Cygwin. Please report this issue. You can use environment"
                    " variable 'CONAN_USER_HOME_SHORT' to set the short_paths"
                    " home.".format(path))
        else:
            drive = os.path.splitdrive(path)[0]
            short_home = os.path.join(drive, os.sep, ".conan")
    mkdir(short_home)

    # Workaround for short_home living in NTFS file systems. Give full control permission
    # to current user to avoid
    # access problems in cygwin/msys2 windows subsystems when using short_home folder
    try:
        userdomain, username = os.getenv("USERDOMAIN"), os.environ["USERNAME"]
        domainname = "%s\%s" % (userdomain,
                                username) if userdomain else username
        cmd = r'cacls %s /E /G "%s":F' % (short_home, domainname)
        subprocess.check_output(
            cmd,
            stderr=subprocess.STDOUT)  # Ignoring any returned output, quiet
    except (subprocess.CalledProcessError, EnvironmentError):
        # cmd can fail if trying to set ACL in non NTFS drives, ignoring it.
        pass

    redirect = hashed_redirect(short_home, path)
    if not redirect:
        logger.warning("Failed to create a deterministic short path in %s",
                       short_home)
        redirect = tempfile.mkdtemp(dir=short_home, prefix="")

    # Save the full path of the local cache directory where the redirect is from.
    # This file is for debugging purposes and not used by Conan.
    save(os.path.join(redirect, CONAN_REAL_PATH), path)

    # This "1" is the way to have a non-existing directory, so commands like
    # shutil.copytree() to it, works. It can be removed without compromising the
    # temp folder generator and conan-links consistency
    redirect = os.path.join(redirect, "1")
    save(link, redirect)
    return redirect
示例#14
0
def get_generator(conanfile):
    # Returns the name of the generator to be used by CMake
    if "CONAN_CMAKE_GENERATOR" in os.environ:
        return os.environ["CONAN_CMAKE_GENERATOR"]

    compiler = conanfile.settings.get_safe("compiler")
    compiler_version = conanfile.settings.get_safe("compiler.version")

    if compiler == "msvc":
        if compiler_version is None:
            raise ConanException("compiler.version must be defined")
        version = compiler_version[:
                                   4]  # Remove the latest version number 19.1X if existing
        try:
            _visuals = {
                '19.0': '14 2015',
                '19.1': '15 2017',
                '19.2': '16 2019'
            }[version]
        except KeyError:
            raise ConanException("compiler.version '{}' doesn't map "
                                 "to a known VS version".format(version))
        base = "Visual Studio %s" % _visuals
        return base

    compiler_base = conanfile.settings.get_safe("compiler.base")
    arch = conanfile.settings.get_safe("arch")

    compiler_base_version = conanfile.settings.get_safe(
        "compiler.base.version")
    if hasattr(conanfile, 'settings_build'):
        os_build = conanfile.settings_build.get_safe('os')
    else:
        os_build = conanfile.settings.get_safe('os_build')
    if os_build is None:  # Assume is the same specified in host settings, not cross-building
        os_build = conanfile.settings.get_safe("os")

    if not compiler or not compiler_version or not arch:
        if os_build == "Windows":
            logger.warning(
                "CMake generator could not be deduced from settings")
            return None
        return "Unix Makefiles"

    if compiler == "Visual Studio" or compiler_base == "Visual Studio":
        version = compiler_base_version or compiler_version
        major_version = version.split('.', 1)[0]
        _visuals = {
            '8': '8 2005',
            '9': '9 2008',
            '10': '10 2010',
            '11': '11 2012',
            '12': '12 2013',
            '14': '14 2015',
            '15': '15 2017',
            '16': '16 2019'
        }.get(major_version, "UnknownVersion %s" % version)
        base = "Visual Studio %s" % _visuals
        return base

    # The generator depends on the build machine, not the target
    if os_build == "Windows" and compiler != "qcc":
        return "MinGW Makefiles"  # it is valid only under Windows

    return "Unix Makefiles"