code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
client = self._clients[item].get_client()
self[item] = val = self.item_class(client)
return val | def refresh(self, item) | Forces a refresh of a cached item.
:param item: Client name.
:type item: unicode | str
:return: Items in the cache.
:rtype: DockerHostItemCache.item_class | 10.116533 | 9.666997 | 1.046502 |
if state.config_flags & ConfigFlags.DEPENDENT or state.config_id.config_type != ItemType.CONTAINER:
return super(ScriptActionGenerator, self).get_state_actions(state, **kwargs)
if state.base_state == State.ABSENT:
actions = []
else:
log.debug("Found ... | def get_state_actions(self, state, **kwargs) | For dependent items, inherits the behavior from :class:`dockermap.map.action.resume.ResumeActionGenerator`.
For other the main container, checks if containers exist, and depending on the ``remove_existing_before``
option either fails or removes them. Otherwise runs the script.
:param state: Con... | 4.22553 | 3.51822 | 1.201042 |
attached_items = [(container, ac)
for container, config in self
for ac in config.attaches]
persistent_containers = [(container, ci)
for container, config in self if config.persistent
... | def get_persistent_items(self) | Returns attached container items and container configurations that are marked as persistent. Each returned
item is in the format ``(config name, instance/attached name)``, where the instance name can also be ``None``.
:return: Lists of attached items.
:rtype: (list[(unicode | str, unicode | str... | 7.83685 | 6.759359 | 1.159407 |
name, __, tag = image.rpartition(':')
if not name:
name, tag = tag, name
if '/' in name:
if name[0] == '/':
repo_name = name[1:]
else:
repo_name = name
else:
default_prefix = resolve_value(self.repos... | def get_image(self, image) | Generates a tuple of the full image name and tag, that should be used when creating a new container.
This implementation applies the following rules:
* If the image name starts with ``/``, the following image name is returned.
* If ``/`` is found anywhere else in the image name, it is assumed ... | 2.740121 | 2.531171 | 1.082551 |
if not config.extends or self._extended:
return config
extended_config = ContainerConfiguration()
for ext_name in config.extends:
ext_cfg_base = self._containers.get(ext_name)
if not ext_cfg_base:
raise KeyError(ext_name)
e... | def get_extended(self, config) | Generates a configuration that includes all inherited values.
:param config: Container configuration.
:type config: ContainerConfiguration
:return: A merged (shallow) copy of all inherited configurations merged with the container configuration.
:rtype: ContainerConfiguration | 3.139946 | 2.799997 | 1.121411 |
map_copy = self.__class__(self.name)
map_copy.update_from_obj(self, copy=True, update_containers=False)
for c_name, c_config in self:
map_copy._containers[c_name] = self.get_extended(c_config)
map_copy._extended = True
return map_copy | def get_extended_map(self) | Creates a copy of this map which includes all non-abstract configurations in their extended form.
:return: Copy of this map.
:rtype: ContainerMap | 5.215678 | 4.788177 | 1.089282 |
if state.base_state == State.ABSENT:
if state.config_id.config_type == ItemType.IMAGE:
return [ItemAction(state, ImageAction.PULL)]
actions = [ItemAction(state, Action.CREATE, extra_data=kwargs)]
if state.config_id.config_type == ItemType.CONTAINER:
... | def get_state_actions(self, state, **kwargs) | Creates all missing containers, networks, and volumes.
:param state: Configuration state.
:type state: dockermap.map.state.ConfigState
:param kwargs: Additional keyword arguments.
:return: Actions on the client, map, and configurations.
:rtype: list[dockermap.map.action.ItemActi... | 6.415866 | 5.022832 | 1.27734 |
config_type = state.config_id.config_type
if (config_type == ItemType.VOLUME and state.base_state == State.PRESENT and
state.state_flags & StateFlags.INITIAL):
return [
ItemAction(state, Action.START),
ItemAction(state, VolumeUtilActio... | def get_state_actions(self, state, **kwargs) | Generally starts containers that are not running. Attached containers are skipped unless they are initial.
Attached containers are also prepared with permissions. Where applicable, exec commands are run in started
instance containers.
:param state: Configuration state.
:type state: dock... | 5.38418 | 4.434834 | 1.214066 |
if (state.config_id.config_type == ItemType.CONTAINER and state.base_state != State.ABSENT and
not state.state_flags & StateFlags.INITIAL):
actions = [ItemAction(state, DerivedAction.RESTART_CONTAINER, extra_data=kwargs)]
if self.restart_exec_commands:
... | def get_state_actions(self, state, **kwargs) | Restarts instance containers.
:param state: Configuration state.
:type state: dockermap.map.state.ConfigState
:param kwargs: Additional keyword arguments.
:return: Actions on the client, map, and configurations.
:rtype: list[dockermap.map.action.ItemAction] | 9.356859 | 7.523377 | 1.243705 |
if (state.config_id.config_type == ItemType.CONTAINER and state.base_state != State.ABSENT and
not state.state_flags & StateFlags.INITIAL):
return [ItemAction(state, ContainerUtilAction.SIGNAL_STOP, extra_data=kwargs)] | def get_state_actions(self, state, **kwargs) | Stops containers that are running. Does not check attached containers. Considers using the pre-configured
``stop_signal``.
:param state: Configuration state.
:type state: dockermap.map.state.ConfigState
:param kwargs: Additional keyword arguments.
:return: Actions on the client,... | 16.406471 | 11.791988 | 1.391324 |
config_type = state.config_id.config_type
if config_type == ItemType.CONTAINER:
extra_data = kwargs
else:
extra_data = None
if state.base_state == State.PRESENT:
if ((config_type == ItemType.VOLUME and self.remove_attached) or
... | def get_state_actions(self, state, **kwargs) | Removes containers that are stopped. Optionally skips persistent containers. Attached containers are skipped
by default from removal but can optionally be included.
:param state: Configuration state.
:type state: dockermap.map.state.ConfigState
:param kwargs: Additional keyword argument... | 4.398643 | 3.68575 | 1.193419 |
config_type = state.config_id.config_type
if config_type == ItemType.VOLUME:
if state.base_state == State.ABSENT:
return [
ItemAction(state, Action.CREATE),
ItemAction(state, VolumeUtilAction.PREPARE),
]
... | def get_state_actions(self, state, **kwargs) | A combination of CreateActionGenerator and StartActionGenerator - creates and starts containers where
appropriate.
:param state: Configuration state.
:type state: dockermap.map.state.ConfigState
:param kwargs: Additional keyword arguments.
:return: Actions on the client, map, an... | 2.798898 | 2.651434 | 1.055617 |
config_type = state.config_id.config_type
if config_type == ItemType.NETWORK:
if state.base_state == State.PRESENT:
connected_containers = state.extra_data.get('containers')
if connected_containers:
cc_names = [c.get('Name', c['Id'... | def get_state_actions(self, state, **kwargs) | A combination of StopActionGenerator and RemoveActionGenerator - stops and removes containers where
appropriate.
:param state: Configuration state.
:type state: dockermap.map.state.ConfigState
:param kwargs: Additional keyword arguments.
:return: Actions on the client, map, and ... | 3.457311 | 3.241378 | 1.066618 |
if state.config_id.config_type == ItemType.CONTAINER and state.base_state == State.RUNNING:
return [ItemAction(state, Action.KILL, extra_data=kwargs)] | def get_state_actions(self, state, **kwargs) | Sends kill signals to running containers.
:param state: Configuration state.
:type state: dockermap.map.state.ConfigState
:param kwargs: Additional keyword arguments.
:return: Actions on the client, map, and configurations.
:rtype: list[dockermap.map.action.ItemAction] | 13.470572 | 8.741591 | 1.540975 |
finder = VersionFinder()
finder.visit(ast.parse(local_file('curdling', 'version.py')))
return finder.version | def read_version() | Read version from curdling/version.py without loading any files | 12.728876 | 6.072621 | 2.096109 |
try:
requirements = map(str.strip, local_file(path).splitlines())
except IOError:
raise RuntimeError("Couldn't find the `requirements.txt' file :(")
links = []
pkgs = []
for req in requirements:
if not req:
continue
if 'http:' in req or 'https:' in r... | def parse_requirements(path) | Rudimentary parser for the `requirements.txt` file
We just want to separate regular packages from links to pass them to the
`install_requires` and `dependency_links` params of the `setup()`
function properly. | 3.338869 | 3.12128 | 1.069712 |
pyver = 'python' + sys.version[:3]
paths = {
'prefix' : '{prefix}',
'data' : '{prefix}/lib/{pyver}/site-packages',
'purelib': '{prefix}/lib/{pyver}/site-packages',
'platlib': '{prefix}/lib/{pyver}/site-packages',
'headers': '{prefix}/include/{pyver}/{name}',
... | def get_distribution_paths(name) | Return target paths where the package content should be installed | 3.419195 | 3.349941 | 1.020673 |
if isinstance(response, six.binary_type):
response = response.decode('utf-8')
try:
obj = json.loads(response)
except ValueError:
return {}
return obj | def parse_response(response) | Decodes the JSON response, simply ignoring syntax errors. Therefore it should be used for filtering visible output
only.
:param response: Server response as a JSON string.
:type response: unicode | str
:return: Decoded object from the JSON string. Returns an empty dictionary if input was invalid.
:... | 2.643939 | 2.573221 | 1.027482 |
response = super(DockerClientWrapper, self).build(tag=tag, **kwargs)
# It is not the kwargs alone that decide if we get a stream, so we have to check.
if isinstance(response, tuple):
image_id = response[0]
else:
last_log = self._docker_log_stream(response... | def build(self, tag, add_latest_tag=False, add_tags=None, raise_on_error=True, **kwargs) | Overrides the superclass `build()` and filters the output. Messages are deferred to `push_log`, whereas the
final message is checked for a success message. If the latter is found, only the new image id is returned.
:param tag: Tag of the new image to be built. Unlike in the superclass, this is obligato... | 4.521006 | 4.263302 | 1.060447 |
response = super(DockerClientWrapper, self).login(username, password, email, registry, reauth=reauth, **kwargs)
return response.get('Status') == 'Login Succeeded' or response.get('username') == username | def login(self, username, password=None, email=None, registry=None, reauth=False, **kwargs) | Login to a Docker registry server.
:param username: User name for login.
:type username: unicode | str
:param password: Login password; may be ``None`` if blank.
:type password: unicode | str
:param email: Optional; email address for login.
:type email: unicode | str
... | 3.756705 | 3.621666 | 1.037286 |
response = super(DockerClientWrapper, self).push(repository, stream=stream, **kwargs)
if stream:
result = self._docker_status_stream(response, raise_on_error)
else:
result = self._docker_status_stream(response.split('\r\n') if response else (), raise_on_error)
... | def push(self, repository, stream=False, raise_on_error=True, **kwargs) | Pushes an image repository to the registry.
:param repository: Name of the repository (can include a tag).
:type repository: unicode | str
:param stream: Use the stream output format with additional status information.
:type stream: bool
:param raise_on_error: Raises errors in t... | 3.644477 | 3.506401 | 1.039378 |
logs = self.logs(container).decode('utf-8')
log_lines = logs.split('\n')
if log_lines and not log_lines[-1]:
log_lines.pop()
for line in log_lines:
self.push_log(LOG_CONTAINER_FORMAT, logging.INFO, container, line) | def push_container_logs(self, container) | Reads the current container logs and passes them to :meth:`~push_log`. Removes a trailing empty line and
prefixes each log line with the container name.
:param container: Container name or id.
:type container: unicode | str | 3.191591 | 2.939046 | 1.085927 |
try:
super(DockerClientWrapper, self).remove_container(container, **kwargs)
except APIError as e:
exc_info = sys.exc_info()
if e.response.status_code == 404:
if raise_not_found:
six.reraise(*exc_info)
else:
... | def remove_container(self, container, raise_on_error=True, raise_not_found=False, **kwargs) | Removes a container. For convenience optionally ignores API errors.
:param container: Container name or id.
:type container: unicode | str
:param raise_on_error: Errors on stop and removal may result from Docker volume problems, that may not
affect further actions. Such errors are alw... | 2.429183 | 2.472682 | 0.982408 |
try:
super(DockerClientWrapper, self).stop(container, **kwargs)
except APIError as e:
exc_info = sys.exc_info()
self.push_log("Failed to stop container '%s': %s", logging.ERROR, container, e.explanation)
if raise_on_error:
six.rera... | def stop(self, container, raise_on_error=True, **kwargs) | Stops a container. For convenience optionally ignores API errors.
:param container: Container name.
:type container: unicode | str
:param raise_on_error: Errors on stop and removal may result from Docker volume problems, that may not
affect further actions. Such errors are always logg... | 3.264598 | 3.359456 | 0.971764 |
raw = self.copy(container, resource)
with open(local_filename, 'wb+') as f:
for buf in raw:
f.write(buf) | def copy_resource(self, container, resource, local_filename) | *Experimental:* Copies a resource from a Docker container to a local tar file. For details, see
:meth:`docker.client.Client.copy`.
:param container: Container name or id.
:type container: unicode | str
:param resource: Resource inside the container.
:type resource: unicode | str... | 3.638321 | 4.018695 | 0.905349 |
raw = self.get_image(image)
with open(local_filename, 'wb+') as f:
for buf in raw:
f.write(buf) | def save_image(self, image, local_filename) | *Experimental:* Copies an image from Docker to a local tar file. For details, see
:meth:`docker.client.Client.get_image`.
:param image: Image name or id.
:type image: unicode | str
:param local_filename: Local file to store image into. Will be overwritten if present.
:type local... | 3.469873 | 3.658258 | 0.948504 |
suffixes = [':{0}'.format(t) for t in tags]
def _check_image(image):
repo_tags = image['RepoTags']
if not repo_tags:
return False
return any(r_tag.endswith(s) for s in suffixes for r_tag in repo_tags)
return _check_image | def tag_check_function(tags) | Generates a function that checks whether the given image has any of the listed tags.
:param tags: Tags to check for.
:type tags: list[unicode | str] | set[unicode | str]
:return: Function that returns ``True`` if any of the given tags apply to the image, ``False`` otherwise.
:rtype: (unicode | str) -> ... | 3.51681 | 3.597419 | 0.977593 |
if strip_trailing_slash:
ex_names = [name[1:] for name in names if name.find('/', 2) == -1]
else:
ex_names = [name for name in names if name.find('/', 2) == -1]
if ex_names:
return ex_names[0]
return default | def primary_container_name(names, default=None, strip_trailing_slash=True) | From the list of names, finds the primary name of the container. Returns the defined default value (e.g. the
container id or ``None``) in case it cannot find any.
:param names: List with name and aliases of the container.
:type names: list[unicode | str]
:param default: Default value.
:param strip_... | 2.253402 | 2.597979 | 0.867367 |
repo, __, i_tag = main_tag.rpartition(':')
tag_set = set(extra_tags or ())
if add_latest:
tag_set.add('latest')
tag_set.discard(i_tag)
added_tags = []
tag_kwargs = {}
if str(self.api_version) < DEPRECATED_FORCE_TAG_VERSION:
tag_kwa... | def add_extra_tags(self, image_id, main_tag, extra_tags, add_latest) | Adds extra tags to an image after de-duplicating tag names.
:param image_id: Id of the image.
:type image_id: unicode | str
:param main_tag: Repo / tag specification that has been used to build the image. If present, the tag will be
removed from further arguments.
:type main_ta... | 3.484913 | 3.69743 | 0.942523 |
log.log(level, info, *args, **kwargs) | def push_log(self, info, level, *args, **kwargs) | Writes logs. To be fully implemented by subclasses.
:param info: Log message content.
:type info: unicode | str
:param level: Logging level.
:type level: int
:param args: Positional arguments to pass to logger.
:param kwargs: Keyword arguments to pass to logger. | 4.344921 | 5.635211 | 0.771031 |
return self.build(fileobj=ctx.fileobj, tag=tag, custom_context=True, encoding=ctx.stream_encoding, **kwargs) | def build_from_context(self, ctx, tag, **kwargs) | Builds a docker image from the given docker context with a `Dockerfile` file object.
:param ctx: An instance of :class:`~.context.DockerContext`.
:type ctx: dockermap.build.context.DockerContext
:param tag: New image tag.
:type tag: unicode | str
:param kwargs: See :meth:`docker... | 7.082242 | 6.357624 | 1.113976 |
with DockerContext(dockerfile, finalize=True) as ctx:
return self.build_from_context(ctx, tag, **kwargs) | def build_from_file(self, dockerfile, tag, **kwargs) | Builds a docker image from the given :class:`~dockermap.build.dockerfile.DockerFile`. Use this as a shortcut to
:meth:`build_from_context`, if no extra data is added to the context.
:param dockerfile: An instance of :class:`~dockermap.build.dockerfile.DockerFile`.
:type dockerfile: dockermap.bu... | 4.58965 | 6.171876 | 0.743639 |
exclude_names = set(exclude or ())
def _stopped_containers():
for container in self.containers(all=True):
c_names = [name[1:] for name in container['Names'] or () if name.find('/', 2)]
c_status = container['Status']
if (((include_init... | def cleanup_containers(self, include_initial=False, exclude=None, raise_on_error=False, list_only=False) | Finds all stopped containers and removes them; by default does not remove containers that have never been
started.
:param include_initial: Consider containers that have never been started.
:type include_initial: bool
:param exclude: Container names to exclude from the cleanup process.
... | 3.125354 | 3.132057 | 0.99786 |
used_images = set(self.inspect_container(container['Id'])['Image']
for container in self.containers(all=True))
all_images = self.images(all=True)
image_dependencies = [(image['Id'], image['ParentId'])
for image in all_images
... | def cleanup_images(self, remove_old=False, keep_tags=None, force=False, raise_on_error=False, list_only=False) | Finds all images that are neither used by any container nor another image, and removes them; by default does not
remove repository images.
:param remove_old: Also removes images that have repository names, but no `latest` tag.
:type remove_old: bool
:param keep_tags: List of tags to not... | 2.726595 | 2.626291 | 1.038193 |
containers = [(container['Id'], container['Status'])
for container in self.containers(all=True)]
running_containers = [c_id
for c_id, status in containers
if not (status.startswith('Exited') or status == 'Dead')]
... | def remove_all_containers(self, stop_timeout=10, list_only=False) | First stops (if necessary) and them removes all containers present on the Docker instance.
:param stop_timeout: Timeout to stopping each container.
:type stop_timeout: int
:param list_only: When set to ``True`` only lists containers, but does not actually stop or remove them.
:type list... | 2.347107 | 2.325517 | 1.009284 |
current_containers = self.containers(all=True)
return set(c_name[1:] for c in current_containers for c_name in c['Names']) | def get_container_names(self) | Fetches names of all present containers from Docker.
:return: All container names.
:rtype: set | 5.716409 | 5.780125 | 0.988977 |
current_images = self.images()
tags = {tag: i['Id'] for i in current_images for tag in i['RepoTags']}
return tags | def get_image_tags(self) | Fetches image labels (repository / tags) from Docker.
:return: A dictionary, with image name and tags as the key and the image id as value.
:rtype: dict | 5.999551 | 4.854521 | 1.235869 |
if value is None:
return None
elif isinstance(value, lazy_type):
return value.get()
elif types:
resolve_func = types.get(expand_type_name(type(value)))
if resolve_func:
return resolve_func(value)
return value | def resolve_value(value, types=type_registry) | Returns the actual value for the given object, if it is a late-resolving object type.
If not, the value itself is simply returned.
:param value: Lazy object, registered type in :attr:`type_registry`, or a simple value. In the
latter case, the value is returned as-is.
:type value: str | unicode | int |... | 3.374743 | 3.556694 | 0.948843 |
def _resolve_sub(v, level):
l1 = level + 1
res_val = resolve_value(v, all_types)
if l1 < max_depth:
if isinstance(res_val, (list, tuple)):
return [_resolve_sub(item, l1) for item in res_val]
elif isinstance(res_val, dict):
return {... | def resolve_deep(values, max_depth=5, types=None) | Resolves all late-resolving types into their current values to a certain depth in a dictionary or list.
:param values: Values to resolve of any type.
:param max_depth: Maximum depth to recurse into nested lists, tuples and dictionaries. Below that depth values are
returned as they are.
:type max_depth... | 2.542836 | 2.44609 | 1.039552 |
if not isinstance(resolve_type, type):
raise ValueError("Expected type, got {0}.".format(type(resolve_type).__name__))
if not callable(resolve_func):
raise ValueError("Function is not callable.")
type_registry[expand_type_name(resolve_type)] = resolve_func | def register_type(resolve_type, resolve_func) | Registers a type for lazy value resolution. Instances of AbstractLazyObject do not have to
be registered. The exact type must be provided in ``resolve_type``, not a superclass of it.
Types registered will be passed through the given function by :func:`resolve_value`.
:param resolve_type: Type to consider d... | 2.902467 | 3.644104 | 0.796483 |
if not self._evaluated:
self._val = self._func(*self._args, **self._kwargs)
self._evaluated = True
return self._val | def get(self) | Resolves and returns the object value. Re-uses an existing previous evaluation, if applicable.
:return: The result of evaluating the object. | 3.381181 | 3.067909 | 1.102113 |
merged_paths = []
for item, path in item_paths:
sub_path_idx = []
path_set = set(path)
for index, (merged_item, merged_path, merged_set) in enumerate(merged_paths):
if item in merged_set:
path = None
break
elif merged_item in p... | def merge_dependency_paths(item_paths) | Utility function that merges multiple dependency paths, as far as they share dependencies. Paths are evaluated
and merged in the incoming order. Later paths that are independent, but share some dependencies, are shortened
by these dependencies. Paths that are contained in another entirely are discarded.
:p... | 2.514645 | 2.569427 | 0.978679 |
if not dct:
return
all_props = self.__class__.CONFIG_PROPERTIES
for key, value in six.iteritems(dct):
attr_config = all_props.get(key)
if attr_config:
setattr(self, key, value)
else:
self.update_default_from... | def update_from_dict(self, dct) | Updates this configuration object from a dictionary.
See :meth:`ConfigurationObject.update` for details.
:param dct: Values to update the ConfigurationObject with.
:type dct: dict | 3.500294 | 3.872322 | 0.903926 |
obj.clean()
obj_config = obj._config
all_props = self.__class__.CONFIG_PROPERTIES
if copy:
for key, value in six.iteritems(obj_config):
attr_config = all_props.get(key)
if attr_config:
attr_type = attr_config.attr_t... | def update_from_obj(self, obj, copy=False) | Updates this configuration object from another.
See :meth:`ConfigurationObject.update` for details.
:param obj: Values to update the ConfigurationObject with.
:type obj: ConfigurationObject
:param copy: Copies lists and dictionaries.
:type copy: bool | 2.540652 | 2.656224 | 0.95649 |
if not dct:
return
self.clean()
all_props = self.__class__.CONFIG_PROPERTIES
for key, value in six.iteritems(dct):
attr_config = all_props.get(key)
if attr_config:
attr_type, default, input_func, merge_func = attr_config[:4]
... | def merge_from_dict(self, dct, lists_only=False) | Merges a dictionary into this configuration object.
See :meth:`ConfigurationObject.merge` for details.
:param dct: Values to update the ConfigurationObject with.
:type dct: dict
:param lists_only: Ignore single-value attributes and update dictionary options.
:type lists_only: b... | 3.506673 | 3.47623 | 1.008757 |
self.clean()
obj.clean()
obj_config = obj._config
all_props = self.__class__.CONFIG_PROPERTIES
for key, value in six.iteritems(obj_config):
attr_config = all_props[key]
attr_type, default, __, merge_func = attr_config[:4]
if (merge_fun... | def merge_from_obj(self, obj, lists_only=False) | Merges a configuration object into this one.
See :meth:`ConfigurationObject.merge` for details.
:param obj: Values to update the ConfigurationObject with.
:type obj: ConfigurationObject
:param lists_only: Ignore single-value attributes and update dictionary options.
:type lists... | 4.519648 | 4.612138 | 0.979946 |
if isinstance(values, self.__class__):
self.update_from_obj(values, copy=copy_instance)
elif isinstance(values, dict):
self.update_from_dict(values)
else:
raise ValueError("{0} or dictionary expected; found '{1}'.".format(self.__class__.__name__,
... | def update(self, values, copy_instance=False) | Updates the configuration with the contents of the given configuration object or dictionary.
In case of a dictionary, only valid attributes for this class are considered. Existing attributes are replaced
with the new values. The object is not cleaned before or after, i.e. may accept invalid input.
... | 3.094728 | 3.29577 | 0.939 |
if isinstance(values, self.__class__):
self.merge_from_obj(values, lists_only=lists_only)
elif isinstance(values, dict):
self.merge_from_dict(values, lists_only=lists_only)
else:
raise ValueError("{0} or dictionary expected; found '{1}'.".format(self.... | def merge(self, values, lists_only=False) | Merges list-based attributes into one list including unique elements from both lists. When ``lists_only`` is
set to ``False``, updates dictionaries and overwrites single-value attributes. The resulting configuration
is 'clean', i.e. input values converted and validated. If the conversion is not possible... | 2.842113 | 2.820123 | 1.007797 |
all_props = self.__class__.CONFIG_PROPERTIES
for prop_name in self._modified:
attr_config = all_props.get(prop_name)
if attr_config and attr_config.input_func:
self._config[prop_name] = attr_config.input_func(self._config[prop_name])
self._modifie... | def clean(self) | Cleans the input values of this configuration object.
Fields that have gotten updated through properties are converted to configuration values that match the
format needed by functions using them. For example, for list-like values it means that input of single strings
is transformed into a sing... | 3.84475 | 3.469723 | 1.108086 |
self.clean()
d = OrderedDict()
all_props = self.__class__.CONFIG_PROPERTIES
for attr_name, attr_config in six.iteritems(all_props):
value = self._config[attr_name]
attr_type = attr_config.attr_type
if attr_type:
if value:
... | def as_dict(self) | Returns a copy of the configuration dictionary. Changes in this should not reflect on the original
object.
:return: Configuration dictionary.
:rtype: dict | 3.056161 | 3.149351 | 0.97041 |
config_type = state.config_id.config_type
config_tuple = (state.client_name, state.config_id.map_name, state.config_id.config_name)
if config_type == ItemType.VOLUME:
if state.base_state == State.ABSENT:
action = Action.CREATE
self.recreated_v... | def get_state_actions(self, state, **kwargs) | Attached containers are created and prepared, if they are missing. They are re-created if they have terminated
with errors. Instance containers are created if missing, started if stopped, and re-created / started if an
attached container has been missing.
:param state: Configuration state.
... | 2.753412 | 2.600394 | 1.058844 |
def _get_sub_dependency(sub_item):
e = self._deps.get(sub_item)
if e is None:
return self.get_default()
if e.dependencies is NotInitialized:
e.dependencies = self.merge_dependency(sub_item, _get_sub_dependency, e.parent)
r... | def get_dependencies(self, item) | Performs a dependency check on the given item.
:param item: Node to start the dependency check with.
:return: The result on merged dependencies down the hierarchy. | 4.992532 | 4.913395 | 1.016106 |
e = self._deps.get(item)
if e is None:
return self.get_default()
return e.parent | def get(self, item) | Returns the direct dependencies or dependents of a single item. Does not follow the entire dependency path.
:param item: Node to return dependencies for.
:return: Immediate dependencies or dependents. | 7.443589 | 12.205534 | 0.609854 |
dep = []
for parent_key in parents:
if item == parent_key:
raise CircularDependency(item, True)
parent_dep = resolve_parent(parent_key)
if item in parent_dep:
raise CircularDependency(item)
merge_list(dep, parent_de... | def merge_dependency(self, item, resolve_parent, parents) | Merge dependencies of element with further dependencies. First parent dependencies are checked, and then
immediate dependencies of the current element should be added to the list, but without duplicating any entries.
:param item: Item.
:param resolve_parent: Function to resolve parent dependenc... | 3.404902 | 3.618415 | 0.940993 |
for parent, sub_item in _iterate_dependencies(items):
dep = self._deps[sub_item]
if parent not in dep.parent:
dep.parent.append(parent) | def update(self, items) | Updates the dependencies in the inverse relationship format, i.e. from an iterable or dict that is structured
as `(item, dependent_items)`. Note that this implementation is only valid for 1:1 relationships, i.e. that each
node has also exactly one dependent. For other cases, :class:`~MultiDependencyReso... | 7.187477 | 6.990726 | 1.028145 |
for item, parents in _iterate_dependencies(items):
dep = self._deps[item]
merge_list(dep.parent, parents) | def update(self, items) | Updates the dependencies with the given items. Note that this does not reset all previously-evaluated and cached
nodes.
:param items: Iterable or dictionary in the format `(dependent_item, dependencies)`.
:type items: collections.Iterable | 14.418538 | 15.103734 | 0.954634 |
for parent, sub_items in _iterate_dependencies(items):
for si in sub_items:
dep = self._deps[si]
if parent not in dep.parent:
dep.parent.append(parent) | def update(self, items) | Updates the dependencies in the inverse relationship format, i.e. from an iterable or dict that is structured
as `(item, dependent_items)`. The parent element `item` may occur multiple times.
:param items: Iterable or dictionary in the format `(item, dependent_items)`.
:type items: collections.... | 6.26053 | 5.458824 | 1.146864 |
client = action.client
sig = action.config.stop_signal
stop_kwargs = self.get_container_stop_kwargs(action, c_name, kwargs=kwargs)
if not sig or sig == 'SIGTERM' or sig == signal.SIGTERM:
try:
client.stop(**stop_kwargs)
except Timeout:
... | def signal_stop(self, action, c_name, **kwargs) | Stops a container, either using the default client stop method, or sending a custom signal and waiting
for the container to stop.
:param action: Action configuration.
:type action: dockermap.map.runner.ActionConfig
:param c_name: Container name.
:type c_name: unicode | str
... | 3.102688 | 2.953373 | 1.050557 |
for i in input_items:
s = i.strip()
if not s:
continue
if s[0] == '!':
is_negative = True
match_str = s[1:]
if not match_str:
continue
else:
is_negative = False
match_str = s
yield re... | def preprocess_matches(input_items) | Converts, as far as possible, Go filepath.Match patterns into Python regular expression patterns. Blank lines are
ignored.
This is a generator of two-element-tuples, with the first item as the compiled regular expression. Items prefixed
with an exclamation mark are considered negative exclusions, i.e. exem... | 3.346648 | 3.12589 | 1.070623 |
if not os.path.isdir(path):
return None
dockerignore_file = os.path.join(path, '.dockerignore')
if not os.path.isfile(dockerignore_file):
return None
with open(dockerignore_file, 'rb') as dif:
return list(preprocess_matches(dif.readlines())) | def get_exclusions(path) | Generates exclusion patterns from a ``.dockerignore`` file located in the given path. Returns ``None`` if the
file does not exist.
:param path: Path to look up the ``.dockerignore`` in.
:type path: unicode | str
:return: List of patterns, that can be passed into :func:`get_filter_func`.
:rtype: lis... | 3.061292 | 3.05472 | 1.002152 |
prefix_len = len(prefix.strip(os.path.sep)) + 1
if any(i[1] for i in patterns):
def _exclusion_func(tarinfo):
name = tarinfo.name[prefix_len:]
exclude = False
for match_str, is_negative in patterns:
if is_negative:
if not exclu... | def get_filter_func(patterns, prefix) | Provides a filter function that can be used as filter argument on ``tarfile.add``. Generates the filter based on
the patterns and prefix provided. Patterns should be a list of tuples. Each tuple consists of a compiled RegEx
pattern and a boolean, indicating if it is an ignore entry or a negative exclusion (i.e.... | 3.076582 | 2.717299 | 1.132221 |
if os.path.isdir(name):
exclusions = get_exclusions(name)
if exclusions:
target_prefix = os.path.abspath(arcname or name)
kwargs.setdefault('filter', get_filter_func(exclusions, target_prefix))
self.tarfile.add(name, arcname=arcname, **kwa... | def add(self, name, arcname=None, **kwargs) | Add a file or directory to the context tarball.
:param name: File or directory path.
:type name: unicode | str
:param args: Additional args for :meth:`tarfile.TarFile.add`.
:param kwargs: Additional kwargs for :meth:`tarfile.TarFile.add`. | 3.808441 | 3.791767 | 1.004397 |
with tarfile.open(name, 'r') as st:
for member in st.getmembers():
self.tarfile.addfile(member, st.extractfile(member.name)) | def addarchive(self, name) | Add (i.e. copy) the contents of another tarball to this one.
:param name: File path to the tar archive.
:type name: unicode | str | 3.510962 | 3.310809 | 1.060455 |
if isinstance(dockerfile, DockerFile):
dockerfile.finalize()
dockerfile_obj = dockerfile.fileobj
for path, arcname in dockerfile._files:
self.add(path, arcname=arcname)
for archive in dockerfile._archives:
self.addarchive(a... | def add_dockerfile(self, dockerfile) | Add a Dockerfile to the context. If it is a :class:`DockerFile` instance, files and archive contents added there
will automatically be copied to the tarball. The :class:`DockerFile` will be finalized.
:param dockerfile: :class:`DockerFile` instance or file path to a Dockerfile.
:type dockerfile... | 2.872177 | 2.565168 | 1.119684 |
with open(name, 'wb+') as f:
while True:
buf = self._fileobj.read()
if not buf:
break
f.write(buf) | def save(self, name) | Saves the entire Docker context tarball to a separate file.
:param name: File path to save the tarball into.
:type name: unicode | str | 3.377093 | 3.552831 | 0.950536 |
for update in updates:
if not update:
continue
for key, val in six.iteritems(update):
u_item = resolve_value(val)
if u_item is None:
continue
if key in ('command' or 'entrypoint'):
kwargs[key] = u_item
e... | def update_kwargs(kwargs, *updates) | Utility function for merging multiple keyword arguments, depending on their type:
* Non-existent keys are added.
* Existing lists or tuples are extended, but not duplicating entries.
The keywords ``command`` and ``entrypoint`` are however simply overwritten.
* Nested dictionaries are updated, overrid... | 2.020233 | 1.980592 | 1.020015 |
def _bind_volume_path(vol):
if isinstance(vol, HostVolume):
return resolve_value(vol.path)
v_path = resolve_value(default_volume_paths.get(vol.name))
if v_path:
return v_path
raise KeyError("No host-volume information found for alias {0}.".format(vol))
... | def get_volumes(container_map, config, default_volume_paths, include_named) | Generates volume paths for the ``volumes`` argument during container creation.
:param container_map: Container map.
:type container_map: dockermap.map.config.main.ContainerMap
:param config: Container configuration.
:type config: dockermap.map.config.container.ContainerConfiguration
:param default_... | 2.553736 | 2.407079 | 1.060928 |
aname = policy.aname
cname = policy.cname
map_name = container_map.name
volume_names = set(policy.default_volume_paths[map_name].keys())
def container_name(u_name):
uc_name, __, ui_name = u_name.partition('.')
return cname(map_name, uc_name, ui_name)
def volume_or_containe... | def get_volumes_from(container_map, config_name, config, policy, include_volumes) | Generates volume paths for the host config ``volumes_from`` argument during container creation.
:param container_map: Container map.
:type container_map: dockermap.map.config.main.ContainerMap
:param config_name: Container configuration name.
:type config_name: unicode | str
:param config: Containe... | 2.672793 | 2.661807 | 1.004127 |
def volume_str(paths, readonly):
return '{0[1]}:{0[0]}:{1}'.format(paths, 'ro' if readonly else 'rw')
def _attached_volume(vol):
parent_name = config_name if use_attached_parent_name else None
volume_name = aname(map_name, vol.name, parent_name=parent_name)
if isinstance(vo... | def get_host_binds(container_map, config_name, config, instance, policy, named_volumes) | Generates the list of host volumes and named volumes (where applicable) for the host config ``bind`` argument
during container creation.
:param container_map: Container map.
:type container_map: dockermap.map.config.main.ContainerMap
:param config: Container configuration.
:type config: dockermap.m... | 2.945326 | 2.809324 | 1.048411 |
port_bindings = {}
if_ipv4 = client_config.interfaces
if_ipv6 = client_config.interfaces_ipv6
for exposed_port, ex_port_bindings in itertools.groupby(
sorted(container_config.exposes, key=_get_ex_port), _get_ex_port):
bind_list = list(_get_port_bindings(ex_port_bindings, if_ipv4... | def get_port_bindings(container_config, client_config) | Generates the input dictionary contents for the ``port_bindings`` argument.
:param container_config: Container configuration.
:type container_config: dockermap.map.config.container.ContainerConfiguration
:param client_config: Client configuration.
:type client_config: dockermap.map.config.client.Client... | 3.198693 | 3.464747 | 0.923211 |
r_user = resolve_value(user)
r_permissions = resolve_value(permissions)
if user:
yield chown(r_user, path)
if permissions:
yield chmod(r_permissions, path) | def get_preparation_cmd(user, permissions, path) | Generates the command lines for adjusting a volume's ownership and permission flags. Returns an empty list if there
is nothing to adjust.
:param user: User to set ownership for on the path via ``chown``.
:type user: unicode | str | int | dockermap.functional.AbstractLazyObject
:param permissions: Permi... | 4.471608 | 3.954719 | 1.130702 |
with self.open(os.path.basename(url)) as f:
return {'url': fmt(url), 'sha256': filehash(f, 'sha256')} | def get_urlhash(self, url, fmt) | Returns the hash of the file of an internal url | 5.146224 | 4.885075 | 1.053458 |
return [{
'name': package,
'version': version,
'urls': [self.get_urlhash(f, url_fmt) for f in files]
} for version, files in self.storage.get(package, {}).items()] | def package_releases(self, package, url_fmt=lambda u: u) | List all versions of a package
Along with the version, the caller also receives the file list with all
the available formats. | 4.918855 | 4.693822 | 1.047942 |
policy = self.policy
config_id = self.config_id
if self.config_id.config_type == ItemType.VOLUME:
if self.container_map.use_attached_parent_name:
container_name = policy.aname(config_id.map_name, config_id.instance_name, config_id.config_name)
els... | def inspect(self) | Fetches information about the container from the client. | 3.617611 | 3.502898 | 1.032748 |
if not self.client_config.features['networks']:
raise ValueError("Client does not support network configuration.", self.client_name)
config_id = self.config_id
network_name = self.network_name = self.policy.nname(config_id.map_name, config_id.config_name)
if network_... | def inspect(self) | Inspects the network state. | 6.045386 | 5.701837 | 1.060252 |
if not self.client_config.features['volumes']:
raise ValueError("Client does not support volume configuration.", self.client_name)
config_id = self.config_id
parent_name = config_id.config_name if self.container_map.use_attached_parent_name else None
volume_name = se... | def inspect(self) | Inspects the network state. | 6.272913 | 6.149782 | 1.020022 |
policy = self.policy
image_name = format_image_tag((self.config_id.config_name, self.config_id.instance_name))
image_id = policy.images[self.client_name].get(image_name)
if image_id:
self.detail = {'Id': image_id} # Currently there is no need for actually inspectin... | def inspect(self) | Fetches image information from the client. | 7.376892 | 6.936529 | 1.063485 |
c_map = self._policy.container_maps[config_id.map_name]
clients = c_map.clients or [self._policy.default_client_name]
config_type = config_id.config_type
for client_name in clients:
if config_type == ItemType.CONTAINER:
c_state = self.get_container_s... | def generate_config_states(self, config_id, config_flags=ConfigFlags.NONE) | Generates the actions on a single item, which can be either a dependency or a explicitly selected
container.
:param config_id: Configuration id tuple.
:type config_id: dockermap.map.input.MapConfigId
:param config_flags: Optional configuration flags.
:type config_flags: dockerma... | 2.714393 | 2.519251 | 1.077461 |
return itertools.chain.from_iterable(self.generate_config_states(config_id)
for config_id in config_ids) | def get_states(self, config_ids) | Generates state information for the selected containers.
:param config_ids: List of MapConfigId tuples.
:type config_ids: list[dockermap.map.input.MapConfigId]
:return: Iterable of configuration states.
:rtype: collections.Iterable[dockermap.map.state.ConfigState] | 4.418161 | 3.891186 | 1.135428 |
input_paths = [
(config_id, list(self.get_dependency_path(config_id)))
for config_id in config_ids
]
log.debug("Dependency paths from input: %s", input_paths)
dependency_paths = merge_dependency_paths(input_paths)
log.debug("Merged dependency path... | def get_states(self, config_ids) | Generates state information for the selected container and its dependencies / dependents.
:param config_ids: MapConfigId tuples.
:type config_ids: list[dockermap.map.input.MapConfigId]
:return: Iterable of configuration states.
:rtype: collections.Iterable[dockermap.map.state.ConfigStat... | 3.023587 | 2.959569 | 1.021631 |
client_config = action.client_config
config_id = action.config_id
policy = self._policy
if client_config.features['volumes']:
path = PREPARATION_TMP_PATH
else:
path = resolve_value(policy.default_volume_paths[config_id.map_name][volume_alias])
... | def get_attached_preparation_create_kwargs(self, action, volume_container, volume_alias, kwargs=None) | Generates keyword arguments for the Docker client to prepare an attached container (i.e. adjust user and
permissions).
:param action: Action configuration.
:type action: dockermap.map.runner.ActionConfig
:param volume_container: Name of the container that shares the volume.
:typ... | 3.890207 | 3.584713 | 1.085221 |
if action.client_config.features['volumes']:
c_kwargs = dict(binds=['{0}:{1}'.format(volume_container, PREPARATION_TMP_PATH)])
else:
c_kwargs = dict(volumes_from=[volume_container])
if container_name:
c_kwargs['container'] = container_name
upd... | def get_attached_preparation_host_config_kwargs(self, action, container_name, volume_container, kwargs=None) | Generates keyword arguments for the Docker client to set up the HostConfig for preparing an attached container
(i.e. adjust user and permissions) or start the preparation.
:param action: Action configuration.
:type action: dockermap.map.runner.ActionConfig
:param container_name: Contain... | 4.26205 | 4.264695 | 0.99938 |
c_kwargs = dict(container=container_name)
client_config = action.client_config
c_kwargs = dict(container=container_name)
wait_timeout = client_config.get('wait_timeout')
if wait_timeout is not None:
c_kwargs['timeout'] = wait_timeout
update_kwargs(c_k... | def get_attached_preparation_wait_kwargs(self, action, container_name, kwargs=None) | Generates keyword arguments for waiting for a container when preparing a volume. The container name may be
the container being prepared, or the id of the container calling preparation commands.
:param action: Action configuration.
:type action: dockermap.map.runner.ActionConfig
:param c... | 3.183393 | 3.112178 | 1.022883 |
apc_kwargs = self.get_attached_preparation_create_kwargs(action, volume_container, volume_alias)
if not apc_kwargs:
return
a_wait_kwargs = self.get_attached_preparation_wait_kwargs(action, volume_container)
client.wait(volume_container, **a_wait_kwargs)
temp_... | def _prepare_container(self, client, action, volume_container, volume_alias) | Runs a temporary container for preparing an attached volume for a container configuration.
:param client: Docker client.
:type client: docker.Client
:param action: Action configuration.
:type action: dockermap.map.runner.ActionConfig
:param volume_container: Name of the containe... | 2.740013 | 2.684581 | 1.020648 |
client = action.client
config_id = action.config_id
policy = self._policy
if action.container_map.use_attached_parent_name:
v_alias = '{0.config_name}.{0.instance_name}'.format(config_id)
else:
v_alias = config_id.instance_name
user = poli... | def prepare_attached(self, action, a_name, **kwargs) | Prepares an attached volume for a container configuration.
:param action: Action configuration.
:type action: dockermap.map.runner.ActionConfig
:param a_name: The full name or id of the container sharing the volume.
:type a_name: unicode | str | 4.433481 | 4.157804 | 1.066303 |
user = resolve_value(user_value)
if not user and user != 0 and user != '0':
return None
if isinstance(user, tuple):
return user[0]
if isinstance(user, six.integer_types):
return six.text_type(user)
return user.partition(':')[0] | def extract_user(user_value) | Extract the user for running a container from the following possible input formats:
* Integer (UID)
* User name string
* Tuple of ``user, group``
* String in the format ``user:group``
:param user_value: User name, uid, user-group tuple, or user:group string.
:type user_value: int | tuple | uni... | 3.790082 | 3.602113 | 1.052183 |
if isinstance(vol, HostVolume):
c_path = resolve_value(vol.path)
if is_path(c_path):
return c_path, get_host_path(container_map.host.root, vol.host_path, instance)
raise ValueError("Host-container-binding must be described by two paths or one alias name.",
... | def get_shared_volume_path(container_map, vol, instance=None) | Resolves a volume alias of a container configuration or a tuple of two paths to the host and container paths.
:param container_map: Container map.
:type container_map: dockermap.map.config.main.ContainerMap
:param vol: SharedVolume or HostVolume tuple.
:type vol: dockermap.map.input.HostVolume | docker... | 5.596118 | 4.797345 | 1.166503 |
if 'Mounts' in instance_detail:
if check_names:
return {m['Destination']: m.get('Name') or m['Source']
for m in instance_detail['Mounts']}
return {m['Destination']: m['Source']
for m in instance_detail['Mounts']}
return instance_detail.get('Vo... | def get_instance_volumes(instance_detail, check_names) | Extracts the mount points and mapped directories or names of a Docker container.
:param instance_detail: Result from a container inspection.
:type instance_detail: dict
:param check_names: Whether to check for named volumes.
:type check_names: bool
:return: Dictionary of volumes, with the destinati... | 2.657751 | 2.332041 | 1.139667 |
pkg = request.files[package]
self.index.from_data(package, pkg.read())
return 'ok' | def web_upload(self, package) | * Smart enough to not save things we already have
* Idempotent, you can call as many times as you need
* The caller names the package (its basename) | 11.729616 | 12.158859 | 0.964697 |
if not items:
return
merged_set = set(merged_list)
merged_add = merged_set.add
merged_list.extend(item
for item in items
if item not in merged_set and not merged_add(item)) | def merge_list(merged_list, items) | Merges items into a list, appends ignoring duplicates but retaining the original order. This modifies the list and
does not return anything.
:param merged_list: List to append de-duplicated items to.
:type merged_list: list
:param items: Items to merge into the list.
:type items: collections.Iterab... | 3.314167 | 3.187794 | 1.039643 |
client = action.client
for c_name in containers:
disconnect_kwargs = self.get_network_disconnect_kwargs(action, network_name, c_name, kwargs=kwargs)
client.disconnect_container_from_network(**disconnect_kwargs) | def disconnect_all_containers(self, action, network_name, containers, **kwargs) | Disconnects all containers from a network.
:param action: Action configuration.
:type action: dockermap.map.runner.ActionConfig
:param network_name: Network name or id.
:type network_name: unicode | str
:param containers: Container names or ids.
:type containers: collect... | 3.713579 | 4.719422 | 0.786872 |
if not endpoints or (skip_first and len(endpoints) <= 1):
return
client = action.client
map_name = action.config_id.map_name
nname = self._policy.nname
if skip_first:
endpoints = islice(endpoints, 1, None)
for network_endpoint in endpoints... | def connect_networks(self, action, container_name, endpoints, skip_first=False, **kwargs) | Connects a container to a set of configured networks. By default this assumes the container has just been
created, so it will skip the first network that is already considered during creation.
:param action: Action configuration.
:type action: dockermap.map.runner.ActionConfig
:param co... | 3.887593 | 3.678686 | 1.056789 |
client = action.client
for n_name in networks:
disconnect_kwargs = self.get_network_disconnect_kwargs(action, n_name, container_name, kwargs=kwargs)
client.disconnect_container_from_network(**disconnect_kwargs) | def disconnect_networks(self, action, container_name, networks, **kwargs) | Disconnects a container from a set of networks.
:param action: Action configuration.
:type action: dockermap.map.runner.ActionConfig
:param container_name: Container names or id.
:type container_name: unicode | str
:param networks: List of network names or ids.
:type net... | 3.850599 | 4.874637 | 0.789925 |
kwargs.setdefault('skip_first', True)
self.connect_networks(action, container_name, action.config.networks, **kwargs) | def connect_all_networks(self, action, container_name, **kwargs) | Connects a container to all of its configured networks. Assuming that this is typically used after container
creation, where teh first endpoint is already defined, this skips the first configuration. Pass ``skip_first``
as ``False`` to change this.
:param action: Action configuration.
:... | 5.893879 | 4.561828 | 1.291999 |
self.finalize()
with open(name, 'wb+') as f:
if six.PY3:
f.write(self.fileobj.getbuffer())
else:
f.write(self.fileobj.getvalue().encode('utf-8')) | def save(self, name) | Save the string buffer to a file. Finalizes prior to saving.
:param name: File path.
:type name: unicode | str | 3.297875 | 3.333468 | 0.989323 |
self.finalize()
with open(name, 'wb+') as f:
buf = self._fileobj.read()
while buf:
f.write(buf)
buf = self._fileobj.read() | def save(self, name) | Copy the contents of the temporary file somewhere else. Finalizes prior to saving.
:param name: File path.
:type name: unicode | str | 3.621848 | 3.350029 | 1.081139 |
return value and isinstance(value, six.string_types) and (value[0] == posixpath.sep or value[:2] == CURRENT_DIR) | def is_path(value) | Checks whether the given value represents a path, i.e. a string which starts with an indicator for absolute or
relative paths.
:param value: Value to check.
:return: ``True``, if the value appears to be representing a path.
:rtype: bool | 6.500124 | 8.144202 | 0.798129 |
if value is None:
return []
elif value is NotSet:
return NotSet
elif isinstance(value, (list, tuple)):
return list(value)
elif isinstance(value, six.string_types + (lazy_type, )) or uses_type_registry(value):
return [value]
raise ValueError("Invalid type; expecte... | def get_list(value) | Wraps the given value in a list. ``None`` returns an empty list. Lists and tuples are returned as lists. Single
strings and registered types are wrapped in a list.
:param value: Value to return as a list.
:return: List with the provided value(s).
:rtype: list | 4.060387 | 3.684156 | 1.102121 |
if not value or value == 'disabled':
return 'none'
if isinstance(value, (tuple, list)):
if len(value) == 2:
return tuple(value)
return ValueError("Tuples or lists need to have length 2 for container network references.")
if value in DEFAULT_PRESET_NETWORKS:
r... | def get_network_mode(value) | Generates input for the ``network_mode`` of a Docker host configuration. If it points at a container, the
configuration of the container is returned.
:param value: Network mode input.
:type value: unicode | str | tuple | list | NoneType
:return: Network mode or container to re-use the network stack of.... | 4.873385 | 4.466455 | 1.091108 |
if isinstance(value, HealthCheck):
return value
elif isinstance(value, six.string_types + (lazy_type,)) or uses_type_registry(value):
return HealthCheck(value)
elif isinstance(value, (tuple, list)):
return HealthCheck(*value)
elif isinstance(value, dict):
return Heal... | def get_healthcheck(value) | Converts input into a :class:`HealthCheck` tuple. Input can be passed as string, tuple, list, or a dictionary. If
set to ``None``, the health check will be set to ``NONE``, i.e. override an existing configuration from the image.
:param value: Health check input.
:type value: unicode | str | tuple | list | ... | 3.45161 | 3.470618 | 0.994523 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.