def decode_text(text): decoders = ["utf-8", "Windows-1252"] for decoder in decoders: try: return text.decode(decoder) except UnicodeDecodeError: continue logger.warn("can't decode %s" % str(text)) return text.decode("utf-8", "ignore") # Ignore not compatible characters
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.warn("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
def update(self, dep_env_info, conan_ref): self._dependencies_[conan_ref.name] = dep_env_info # With vars if its setted the keep the setted 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].extend(value) else: self.vars[varname].append(value) else: logger.warn("DISCARDED variable %s=%s from %s" % (varname, value, str(conan_ref)))
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 setted the keep the setted 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.warn("DISCARDED variable %s=%s from %s" % (varname, value, pkg_name))