Rewrite imagebuilder unpack_http_archive using python modules
This commit is contained in:
parent
19425cece9
commit
de6b5e81ac
@ -1,10 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import requests
|
||||
import shutil
|
||||
import stat
|
||||
import subprocess
|
||||
import tarfile
|
||||
import tempfile
|
||||
import zipfile
|
||||
|
||||
from .container import Container
|
||||
from .image import Image
|
||||
@ -121,16 +123,21 @@ class ImageBuilder:
|
||||
|
||||
def unpack_http_archive(src, dst):
|
||||
# Decompress an archive downloaded via http(s)
|
||||
# TODO: Rewrite to python (requests, tarfile)
|
||||
xf = 'xzf'
|
||||
if src.endswith('.bz2'):
|
||||
xf = 'xjf'
|
||||
elif src.endswith('.xz'):
|
||||
xf = 'xJf'
|
||||
with subprocess.Popen(['wget', src, '-O', '-'], stdout=subprocess.PIPE) as wget:
|
||||
with subprocess.Popen(['tar', xf, '-', '-C', dst], stdin=wget.stdout) as tar:
|
||||
wget.stdout.close()
|
||||
tar.wait()
|
||||
with tempfile.TemporaryFile() as tmp_archive:
|
||||
with requests.Session() as session:
|
||||
resource = session.get(src, stream=True)
|
||||
for chunk in resource.iter_content(chunk_size=None):
|
||||
if chunk:
|
||||
tmp_archive.write(chunk)
|
||||
tmp_archive.seek(0)
|
||||
is_zip = zipfile.is_zipfile(tmp_archive)
|
||||
tmp_archive.seek(0)
|
||||
if is_zip:
|
||||
with zipfile.ZipFile(tmp_archive) as zip:
|
||||
zip.extractall(dst)
|
||||
else:
|
||||
with tarfile.open(fileobj=tmp_archive) as tar:
|
||||
tar.extractall(dst, numeric_owner=True)
|
||||
|
||||
def copy_tree(src, dst):
|
||||
# Copies files from the host
|
||||
|
Loading…
Reference in New Issue
Block a user