Skip to content

Commit

Permalink
hide added tool.is_compressed (#7902)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded committed Oct 19, 2020
1 parent 4f9822d commit a5c9941
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
19 changes: 16 additions & 3 deletions conans/client/conf/config_installer.py
Expand Up @@ -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
Expand Down Expand Up @@ -199,18 +199,31 @@ 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":
_process_git_repo(config, cache, output)
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)
Expand Down
13 changes: 0 additions & 13 deletions conans/client/tools/files.py
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions conans/test/functional/command/config_install_test.py
Expand Up @@ -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
Expand Down Expand Up @@ -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": ""
Expand Down Expand Up @@ -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),
])
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit a5c9941

Please sign in to comment.