Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
docker-py
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
docker-py
Commits
08803743
Unverified
Kaydet (Commit)
08803743
authored
Şub 15, 2018
tarafından
Joffrey F
Kaydeden (comit)
GitHub
Şub 15, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge pull request #1906 from docker/1352-data_stream_control
Add chunk_size parameter to data downloading methods
üst
dbcf0438
581ccc9f
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
53 additions
and
18 deletions
+53
-18
client.py
docker/api/client.py
+3
-3
container.py
docker/api/container.py
+11
-4
image.py
docker/api/image.py
+6
-2
constants.py
docker/constants.py
+1
-0
containers.py
docker/models/containers.py
+13
-4
images.py
docker/models/images.py
+8
-2
models_containers_test.py
tests/unit/models_containers_test.py
+7
-2
models_images_test.py
tests/unit/models_images_test.py
+4
-1
No files found.
docker/api/client.py
Dosyayı görüntüle @
08803743
...
...
@@ -350,10 +350,10 @@ class APIClient(
break
yield
data
def
_stream_raw_result
(
self
,
response
):
''' Stream result for TTY-enabled container '''
def
_stream_raw_result
(
self
,
response
,
chunk_size
=
1
,
decode
=
True
):
''' Stream result for TTY-enabled container
and raw binary data
'''
self
.
_raise_for_status
(
response
)
for
out
in
response
.
iter_content
(
chunk_size
=
1
,
decode_unicode
=
Tru
e
):
for
out
in
response
.
iter_content
(
chunk_size
,
decod
e
):
yield
out
def
_read_from_socket
(
self
,
response
,
stream
,
tty
=
False
):
...
...
docker/api/container.py
Dosyayı görüntüle @
08803743
...
...
@@ -3,6 +3,7 @@ from datetime import datetime
from
..
import
errors
from
..
import
utils
from
..constants
import
DEFAULT_DATA_CHUNK_SIZE
from
..types
import
(
ContainerConfig
,
EndpointConfig
,
HostConfig
,
NetworkingConfig
)
...
...
@@ -645,12 +646,15 @@ class ContainerApiMixin(object):
)
@utils.check_resource
(
'container'
)
def
export
(
self
,
container
):
def
export
(
self
,
container
,
chunk_size
=
DEFAULT_DATA_CHUNK_SIZE
):
"""
Export the contents of a filesystem as a tar archive.
Args:
container (str): The container to export
chunk_size (int): The number of bytes returned by each iteration
of the generator. If ``None``, data will be streamed as it is
received. Default: 2 MB
Returns:
(generator): The archived filesystem data stream
...
...
@@ -662,10 +666,10 @@ class ContainerApiMixin(object):
res
=
self
.
_get
(
self
.
_url
(
"/containers/{0}/export"
,
container
),
stream
=
True
)
return
self
.
_stream_raw_result
(
res
)
return
self
.
_stream_raw_result
(
res
,
chunk_size
,
False
)
@utils.check_resource
(
'container'
)
def
get_archive
(
self
,
container
,
path
):
def
get_archive
(
self
,
container
,
path
,
chunk_size
=
DEFAULT_DATA_CHUNK_SIZE
):
"""
Retrieve a file or folder from a container in the form of a tar
archive.
...
...
@@ -673,6 +677,9 @@ class ContainerApiMixin(object):
Args:
container (str): The container where the file is located
path (str): Path to the file or folder to retrieve
chunk_size (int): The number of bytes returned by each iteration
of the generator. If ``None``, data will be streamed as it is
received. Default: 2 MB
Returns:
(tuple): First element is a raw tar data stream. Second element is
...
...
@@ -690,7 +697,7 @@ class ContainerApiMixin(object):
self
.
_raise_for_status
(
res
)
encoded_stat
=
res
.
headers
.
get
(
'x-docker-container-path-stat'
)
return
(
self
.
_stream_raw_result
(
res
),
self
.
_stream_raw_result
(
res
,
chunk_size
,
False
),
utils
.
decode_json_header
(
encoded_stat
)
if
encoded_stat
else
None
)
...
...
docker/api/image.py
Dosyayı görüntüle @
08803743
...
...
@@ -4,6 +4,7 @@ import os
import
six
from
..
import
auth
,
errors
,
utils
from
..constants
import
DEFAULT_DATA_CHUNK_SIZE
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -11,12 +12,15 @@ log = logging.getLogger(__name__)
class
ImageApiMixin
(
object
):
@utils.check_resource
(
'image'
)
def
get_image
(
self
,
image
):
def
get_image
(
self
,
image
,
chunk_size
=
DEFAULT_DATA_CHUNK_SIZE
):
"""
Get a tarball of an image. Similar to the ``docker save`` command.
Args:
image (str): Image name to get
chunk_size (int): The number of bytes returned by each iteration
of the generator. If ``None``, data will be streamed as it is
received. Default: 2 MB
Returns:
(generator): A stream of raw archive data.
...
...
@@ -34,7 +38,7 @@ class ImageApiMixin(object):
>>> f.close()
"""
res
=
self
.
_get
(
self
.
_url
(
"/images/{0}/get"
,
image
),
stream
=
True
)
return
self
.
_stream_raw_result
(
res
)
return
self
.
_stream_raw_result
(
res
,
chunk_size
,
False
)
@utils.check_resource
(
'image'
)
def
history
(
self
,
image
):
...
...
docker/constants.py
Dosyayı görüntüle @
08803743
...
...
@@ -17,3 +17,4 @@ IS_WINDOWS_PLATFORM = (sys.platform == 'win32')
DEFAULT_USER_AGENT
=
"docker-sdk-python/{0}"
.
format
(
version
)
DEFAULT_NUM_POOLS
=
25
DEFAULT_DATA_CHUNK_SIZE
=
1024
*
2048
docker/models/containers.py
Dosyayı görüntüle @
08803743
...
...
@@ -3,6 +3,7 @@ import ntpath
from
collections
import
namedtuple
from
..api
import
APIClient
from
..constants
import
DEFAULT_DATA_CHUNK_SIZE
from
..errors
import
(
ContainerError
,
ImageNotFound
,
create_unexpected_kwargs_error
)
from
..types
import
HostConfig
...
...
@@ -181,10 +182,15 @@ class Container(Model):
exec_output
)
def
export
(
self
):
def
export
(
self
,
chunk_size
=
DEFAULT_DATA_CHUNK_SIZE
):
"""
Export the contents of the container's filesystem as a tar archive.
Args:
chunk_size (int): The number of bytes returned by each iteration
of the generator. If ``None``, data will be streamed as it is
received. Default: 2 MB
Returns:
(str): The filesystem tar archive
...
...
@@ -192,15 +198,18 @@ class Container(Model):
:py:class:`docker.errors.APIError`
If the server returns an error.
"""
return
self
.
client
.
api
.
export
(
self
.
id
)
return
self
.
client
.
api
.
export
(
self
.
id
,
chunk_size
)
def
get_archive
(
self
,
path
):
def
get_archive
(
self
,
path
,
chunk_size
=
DEFAULT_DATA_CHUNK_SIZE
):
"""
Retrieve a file or folder from the container in the form of a tar
archive.
Args:
path (str): Path to the file or folder to retrieve
chunk_size (int): The number of bytes returned by each iteration
of the generator. If ``None``, data will be streamed as it is
received. Default: 2 MB
Returns:
(tuple): First element is a raw tar data stream. Second element is
...
...
@@ -210,7 +219,7 @@ class Container(Model):
:py:class:`docker.errors.APIError`
If the server returns an error.
"""
return
self
.
client
.
api
.
get_archive
(
self
.
id
,
path
)
return
self
.
client
.
api
.
get_archive
(
self
.
id
,
path
,
chunk_size
)
def
kill
(
self
,
signal
=
None
):
"""
...
...
docker/models/images.py
Dosyayı görüntüle @
08803743
...
...
@@ -4,6 +4,7 @@ import re
import
six
from
..api
import
APIClient
from
..constants
import
DEFAULT_DATA_CHUNK_SIZE
from
..errors
import
BuildError
,
ImageLoadError
from
..utils
import
parse_repository_tag
from
..utils.json_stream
import
json_stream
...
...
@@ -58,10 +59,15 @@ class Image(Model):
"""
return
self
.
client
.
api
.
history
(
self
.
id
)
def
save
(
self
):
def
save
(
self
,
chunk_size
=
DEFAULT_DATA_CHUNK_SIZE
):
"""
Get a tarball of an image. Similar to the ``docker save`` command.
Args:
chunk_size (int): The number of bytes returned by each iteration
of the generator. If ``None``, data will be streamed as it is
received. Default: 2 MB
Returns:
(generator): A stream of raw archive data.
...
...
@@ -77,7 +83,7 @@ class Image(Model):
>>> f.write(chunk)
>>> f.close()
"""
return
self
.
client
.
api
.
get_image
(
self
.
id
)
return
self
.
client
.
api
.
get_image
(
self
.
id
,
chunk_size
)
def
tag
(
self
,
repository
,
tag
=
None
,
**
kwargs
):
"""
...
...
tests/unit/models_containers_test.py
Dosyayı görüntüle @
08803743
import
docker
from
docker.constants
import
DEFAULT_DATA_CHUNK_SIZE
from
docker.models.containers
import
Container
,
_create_container_args
from
docker.models.images
import
Image
import
unittest
...
...
@@ -422,13 +423,17 @@ class ContainerTest(unittest.TestCase):
client
=
make_fake_client
()
container
=
client
.
containers
.
get
(
FAKE_CONTAINER_ID
)
container
.
export
()
client
.
api
.
export
.
assert_called_with
(
FAKE_CONTAINER_ID
)
client
.
api
.
export
.
assert_called_with
(
FAKE_CONTAINER_ID
,
DEFAULT_DATA_CHUNK_SIZE
)
def
test_get_archive
(
self
):
client
=
make_fake_client
()
container
=
client
.
containers
.
get
(
FAKE_CONTAINER_ID
)
container
.
get_archive
(
'foo'
)
client
.
api
.
get_archive
.
assert_called_with
(
FAKE_CONTAINER_ID
,
'foo'
)
client
.
api
.
get_archive
.
assert_called_with
(
FAKE_CONTAINER_ID
,
'foo'
,
DEFAULT_DATA_CHUNK_SIZE
)
def
test_image
(
self
):
client
=
make_fake_client
()
...
...
tests/unit/models_images_test.py
Dosyayı görüntüle @
08803743
from
docker.constants
import
DEFAULT_DATA_CHUNK_SIZE
from
docker.models.images
import
Image
import
unittest
...
...
@@ -116,7 +117,9 @@ class ImageTest(unittest.TestCase):
client
=
make_fake_client
()
image
=
client
.
images
.
get
(
FAKE_IMAGE_ID
)
image
.
save
()
client
.
api
.
get_image
.
assert_called_with
(
FAKE_IMAGE_ID
)
client
.
api
.
get_image
.
assert_called_with
(
FAKE_IMAGE_ID
,
DEFAULT_DATA_CHUNK_SIZE
)
def
test_tag
(
self
):
client
=
make_fake_client
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment