Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support other types of remote archives #9530

Merged
merged 2 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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):
el-g-1 marked this conversation as resolved.
Show resolved Hide resolved
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