diff --git a/conans/client/conf/config_installer.py b/conans/client/conf/config_installer.py index 51b709271e1..7c0f4e48d5d 100644 --- a/conans/client/conf/config_installer.py +++ b/conans/client/conf/config_installer.py @@ -12,7 +12,7 @@ from conans.client import tools from conans.client.cache.remote_registry import load_registry_txt, migrate_registry_file from conans.client.tools import Git -from conans.client.tools.files import unzip, is_compressed_file +from conans.client.tools.files import unzip from conans.errors import ConanException from conans.util.files import mkdir, rmdir, walk, save, touch, remove from conans.client.cache.cache import ClientCache @@ -199,6 +199,19 @@ def from_item(uri, config_type, verify_ssl, args, source_folder, target_folder): return config +def _is_compressed_file(filename): + open(filename, "r") # Check if the file exist and can be opened + import zipfile + if zipfile.is_zipfile(filename): + return True + if (filename.endswith(".tar.gz") or filename.endswith(".tgz") or + filename.endswith(".tbz2") or filename.endswith(".tar.bz2") or + filename.endswith(".tar") or filename.endswith(".gz") or + filename.endswith(".tar.xz") or filename.endswith(".txz")): + return True + return False + + def _process_config(config, cache, output, requester): try: if config.type == "git": @@ -206,11 +219,11 @@ def _process_config(config, cache, output, requester): elif config.type == "dir": _process_folder(config, config.uri, cache, output) elif config.type == "file": - if is_compressed_file(config.uri): + if _is_compressed_file(config.uri): with tmp_config_install_folder(cache) as tmp_folder: _process_zip_file(config, config.uri, cache, output, tmp_folder) else: - dirname, filename = os.path.dirname(config.uri), os.path.basename(config.uri) + dirname, filename = os.path.split(config.uri) _process_file(dirname, filename, config, cache, output, dirname) elif config.type == "url": _process_download(config, cache, output, requester=requester) diff --git a/conans/client/tools/files.py b/conans/client/tools/files.py index 878158a9cec..01f0a327c7e 100644 --- a/conans/client/tools/files.py +++ b/conans/client/tools/files.py @@ -53,19 +53,6 @@ def human_size(size_bytes): return "%s%s" % (formatted_size, suffix) -def is_compressed_file(filename): - import zipfile - import tarfile - import binascii - # test gzip magic number - with open(filename, 'rb') as fd: - if binascii.hexlify(fd.read(2)) == b'1f8b': - return True - if zipfile.is_zipfile(filename) or tarfile.is_tarfile(filename): - return True - return False - - def unzip(filename, destination=".", keep_permissions=False, pattern=None, output=None): """ Unzip a zipped file diff --git a/conans/test/functional/command/config_install_test.py b/conans/test/functional/command/config_install_test.py index 935c9fcd583..92433851a76 100644 --- a/conans/test/functional/command/config_install_test.py +++ b/conans/test/functional/command/config_install_test.py @@ -41,7 +41,7 @@ arch: [x86, x86_64] """ -conan_conf = """ +cache_conan_conf = """ [log] run_to_output = False # environment CONAN_LOG_RUN_TO_OUTPUT level = 10 # environment CONAN_LOGGING_LEVEL @@ -99,7 +99,7 @@ def _create_profile_folder(folder=None): "hooks/custom/custom.py": "#hook custom", ".git/hooks/foo": "foo", "hooks/.git/hooks/before_push": "before_push", - "config/conan.conf": conan_conf, + "config/conan.conf": cache_conan_conf, "pylintrc": "#Custom pylint", "python/myfuncs.py": myfuncpy, "python/__init__.py": "" @@ -142,15 +142,15 @@ def _create_zip(self, zippath=None): def _check(self, params): typ, uri, verify, args = [p.strip() for p in params.split(",")] configs = json.loads(load(self.client.cache.config_install_file)) - config = _ConfigOrigin(configs[-1]) + config = _ConfigOrigin(configs[-1]) # Check the last one self.assertEqual(config.type, typ) self.assertEqual(config.uri, uri) self.assertEqual(str(config.verify_ssl), verify) self.assertEqual(str(config.args), args) settings_path = self.client.cache.settings_path self.assertEqual(load(settings_path).splitlines(), settings_yml.splitlines()) - remotes = self.client.cache.registry.load_remotes() - self.assertEqual(list(remotes.values()), [ + cache_remotes = self.client.cache.registry.load_remotes() + self.assertEqual(list(cache_remotes.values()), [ Remote("myrepo1", "https://myrepourl.net", False, False), Remote("my-repo-2", "https://myrepo2.com", True, False), ]) @@ -209,8 +209,8 @@ def test_install_file_test(self): """ should install from a file in current dir """ zippath = self._create_zip() - for type in ["", "--type=file"]: - self.client.run('config install "%s" %s' % (zippath, type)) + for filetype in ["", "--type=file"]: + self.client.run('config install "%s" %s' % (zippath, filetype)) self._check("file, %s, True, None" % zippath) self.assertTrue(os.path.exists(zippath)) @@ -244,8 +244,8 @@ def test_install_dir_test(self): """ folder = self._create_profile_folder() self.assertTrue(os.path.isdir(folder)) - for type in ["", "--type=dir"]: - self.client.run('config install "%s" %s' % (folder, type)) + for dirtype in ["", "--type=dir"]: + self.client.run('config install "%s" %s' % (folder, dirtype)) self._check("dir, %s, True, None" % folder) def install_source_target_folders_test(self): @@ -333,16 +333,16 @@ def test_install_url(self): """ should install from a URL """ - for type in ["", "--type=url"]: + for origin in ["", "--type=url"]: def my_download(obj, url, filename, **kwargs): # @UnusedVariable self._create_zip(filename) with patch.object(FileDownloader, 'download', new=my_download): - self.client.run("config install http://myfakeurl.com/myconf.zip %s" % type) + self.client.run("config install http://myfakeurl.com/myconf.zip %s" % origin) self._check("url, http://myfakeurl.com/myconf.zip, True, None") # repeat the process to check - self.client.run("config install http://myfakeurl.com/myconf.zip %s" % type) + self.client.run("config install http://myfakeurl.com/myconf.zip %s" % origin) self._check("url, http://myfakeurl.com/myconf.zip, True, None") def install_change_only_verify_ssl_test(self):