diff options
| author | Huayi Zhang <irachex@gmail.com> | 2014-10-05 23:06:42 +0800 |
|---|---|---|
| committer | Huayi Zhang <irachex@gmail.com> | 2014-10-05 23:18:48 +0800 |
| commit | 589e7006d59273dcc122d9d0bf2c73aa7190832d (patch) | |
| tree | 1b921037d1310bba0efd4f92db22ba25a38d00a9 /docker/utils | |
| parent | 7a462970852a2578c3869e581a57dd70eaa22217 (diff) | |
| download | docker-py-589e7006d59273dcc122d9d0bf2c73aa7190832d.tar.gz | |
Add support for filtering images and containers
[`filters` is a json encoded value of the filters (a map[string][string]) to process on the images list. ][1]
The tricky thing is that we must convert boolean value to string and any filter value to list to make a `map[string][string]` json format
[1]: https://docs.docker.com/reference/api/docker_remote_api_v1.14/#list-images
Diffstat (limited to 'docker/utils')
| -rw-r--r-- | docker/utils/__init__.py | 3 | ||||
| -rw-r--r-- | docker/utils/utils.py | 12 |
2 files changed, 14 insertions, 1 deletions
diff --git a/docker/utils/__init__.py b/docker/utils/__init__.py index 5d2c1b8..ade4f0b 100644 --- a/docker/utils/__init__.py +++ b/docker/utils/__init__.py @@ -1,4 +1,5 @@ from .utils import ( compare_version, convert_port_bindings, convert_volume_binds, - mkbuildcontext, ping, tar, parse_repository_tag, parse_host + mkbuildcontext, ping, tar, parse_repository_tag, parse_host, + convert_filters ) # flake8: noqa diff --git a/docker/utils/utils.py b/docker/utils/utils.py index fb05a1e..514a75b 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -14,6 +14,7 @@ import io import os +import json import tarfile import tempfile from distutils.version import StrictVersion @@ -233,3 +234,14 @@ def parse_host(addr): if proto == "http+unix": return "%s://%s" % (proto, host) return "%s://%s:%d" % (proto, host, port) + + +def convert_filters(filters): + result = {} + for k, v in six.iteritems(filters): + if isinstance(v, bool): + v = 'true' if v else 'false' + if not isinstance(v, list): + v = [v, ] + result[k] = v + return json.dumps(result) |
