Skip to content

Commit

Permalink
Support other types of remote archives (#9530)
Browse files Browse the repository at this point in the history
* Support other types of remote archives

* Use tgz_with_contents() for test
  • Loading branch information
el-g-1 committed Sep 9, 2021
1 parent b93f661 commit c426910
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion conans/client/conf/config_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _process_folder(config, folder, cache, output):
def _process_download(config, cache, output, requester):
with tmp_config_install_folder(cache) as tmp_folder:
output.info("Trying to download %s" % _hide_password(config.uri))
zippath = os.path.join(tmp_folder, "config.zip")
zippath = os.path.join(tmp_folder, os.path.basename(config.uri))
try:
tools.download(config.uri, zippath, out=output, verify=config.verify_ssl,
requester=requester)
Expand Down
29 changes: 28 additions & 1 deletion conans/test/functional/command/config_install_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import shutil
import tarfile
import textwrap
import time
import unittest
Expand All @@ -16,7 +17,7 @@
from conans.client.downloaders.file_downloader import FileDownloader
from conans.errors import ConanException
from conans.test.assets.genconanfile import GenConanfile
from conans.test.utils.test_files import temp_folder
from conans.test.utils.test_files import scan_folder, temp_folder, tgz_with_contents
from conans.test.utils.tools import TestClient, StoppableThreadBottle, zipdir
from conans.util.files import load, mkdir, save, save_files, make_file_read_only

Expand Down Expand Up @@ -144,6 +145,21 @@ def _create_zip(self, zippath=None):
zipdir(folder, zippath)
return zippath

@staticmethod
def _get_files(folder):
relpaths = scan_folder(folder)
files = {}
for path in relpaths:
with open(os.path.join(folder, path), "r") as file_handle:
files[path] = file_handle.read()
return files

def _create_tgz(self, tgz_path=None):
folder = self._create_profile_folder()
tgz_path = tgz_path or os.path.join(folder, "myconfig.tar.gz")
files = self._get_files(folder)
return tgz_with_contents(files, tgz_path)

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))
Expand Down Expand Up @@ -362,6 +378,17 @@ def my_download(obj, url, file_path, **kwargs): # @UnusedVariable
self.client.run("config install http://myfakeurl.com/myconf.zip --verify-ssl=False")
self._check("url, http://myfakeurl.com/myconf.zip, False, None")

def test_install_url_tgz(self):
""" should install from a URL to tar.gz
"""

def my_download(obj, url, file_path, **kwargs): # @UnusedVariable
self._create_tgz(file_path)

with patch.object(FileDownloader, 'download', new=my_download):
self.client.run("config install http://myfakeurl.com/myconf.tar.gz")
self._check("url, http://myfakeurl.com/myconf.tar.gz, True, None")

def test_failed_install_repo(self):
""" should install from a git repo
"""
Expand Down
4 changes: 2 additions & 2 deletions conans/test/utils/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def scan_folder(folder):
return sorted(scanned_files)


def tgz_with_contents(files):
def tgz_with_contents(files, output_path=None):
folder = temp_folder()
file_path = os.path.join(folder, "myfile.tar.gz")
file_path = output_path or os.path.join(folder, "myfile.tar.gz")

with open(file_path, "wb") as tgz_handle:
tgz = gzopen_without_timestamps("myfile.tar.gz", mode="w", fileobj=tgz_handle)
Expand Down

0 comments on commit c426910

Please sign in to comment.