text_prompt
stringlengths
157
13.1k
code_prompt
stringlengths
7
19.8k
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def load_clients(stream, configuration_class=ClientConfiguration): """ Loads client configurations from a YAML document stream. :param stream: YAML stream. :type...
client_dict = yaml.safe_load(stream) if isinstance(client_dict, dict): return {client_name: configuration_class(**client_config) for client_name, client_config in six.iteritems(client_dict)} raise ValueError("Valid configuration could not be decoded.")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def load_map_file(filename, name=None, check_integrity=True): """ Loads a ContainerMap configuration from a YAML file. :param filename: YAML file name. :type fil...
if name == '': base_name = os.path.basename(filename) map_name, __, __ = os.path.basename(base_name).rpartition(os.path.extsep) else: map_name = name with open(filename, 'r') as f: return load_map(f, name=map_name, check_integrity=check_integrity)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def load_clients_file(filename, configuration_class=ClientConfiguration): """ Loads client configurations from a YAML file. :param filename: YAML file name. :typ...
with open(filename, 'r') as f: return load_clients(f, configuration_class=configuration_class)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_state_generator(self, action_name, policy, kwargs): """ Returns the state generator to be used for the given action. :param action_name: Action identifie...
state_generator_cls = self.generators[action_name][0] state_generator = state_generator_cls(policy, kwargs) return state_generator
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_action_generator(self, action_name, policy, kwargs): """ Returns the action generator to be used for the given action. :param action_name: Action identif...
action_generator_cls = self.generators[action_name][1] action_generator = action_generator_cls(policy, kwargs) return action_generator
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_states(self, action_name, config_name, instances=None, map_name=None, **kwargs): """ Returns a generator of states in relation to the indicated action. :...
policy = self.get_policy() _set_forced_update_ids(kwargs, policy.container_maps, map_name or self._default_map, instances) state_generator = self.get_state_generator(action_name, policy, kwargs) log.debug("Remaining kwargs passed to client actions: %s", kwargs) config_ids = get_...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_actions(self, action_name, config_name, instances=None, map_name=None, **kwargs): """ Returns the entire set of actions performed for the indicated actio...
policy = self.get_policy() action_generator = self.get_action_generator(action_name, policy, kwargs) for state in self.get_states(action_name, config_name, instances=instances, map_name=map_name, **kwargs): log.debug("Evaluating state: %s.", state) actions = action_gener...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create(self, container, instances=None, map_name=None, **kwargs): """ Creates container instances for a container configuration. :param container: Container ...
return self.run_actions('create', container, instances=instances, map_name=map_name, **kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def start(self, container, instances=None, map_name=None, **kwargs): """ Starts instances for a container configuration. :param container: Container name. :type ...
return self.run_actions('start', container, instances=instances, map_name=map_name, **kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def restart(self, container, instances=None, map_name=None, **kwargs): """ Restarts instances for a container configuration. :param container: Container name. :t...
return self.run_actions('restart', container, instances=instances, map_name=map_name, **kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def stop(self, container, instances=None, map_name=None, **kwargs): """ Stops instances for a container configuration. :param container: Container name. :type co...
return self.run_actions('stop', container, instances=instances, map_name=map_name, **kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def remove(self, container, instances=None, map_name=None, **kwargs): """ Remove instances from a container configuration. :param container: Container name. :typ...
return self.run_actions('remove', container, instances=instances, map_name=map_name, **kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def startup(self, container, instances=None, map_name=None, **kwargs): """ Start up container instances from a container configuration. Typically this means crea...
return self.run_actions('startup', container, instances=instances, map_name=map_name, **kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def shutdown(self, container, instances=None, map_name=None, **kwargs): """ Shut down container instances from a container configuration. Typically this means st...
return self.run_actions('shutdown', container, instances=instances, map_name=map_name, **kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update(self, container, instances=None, map_name=None, **kwargs): """ Updates instances from a container configuration. Typically this means restarting or re...
return self.run_actions('update', container, instances=instances, map_name=map_name, **kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def call(self, action_name, container, instances=None, map_name=None, **kwargs): """ Generic function for running container actions based on a policy. :param act...
return self.run_actions(action_name, container, instances=instances, map_name=map_name, **kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def pull_images(self, container, instances=None, map_name=None, **kwargs): """ Pulls images for container configurations along their dependency path. :param cont...
return self.run_actions('pull_images', container, map_name=map_name, **kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def list_persistent_containers(self, map_name=None): """ Lists the names of all persistent containers on the specified map or all maps. Attached containers are a...
if map_name: maps = [self._maps[map_name].get_extended_map()] else: maps = [m.get_extended_map() for m in self._maps.values()] cname_func = self.policy_class.cname aname_func = self.policy_class.aname c_names = [] for c_map in maps: m_...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def rest(f): """Decorator for simple REST endpoints. Functions must return one of these values: - a dict to jsonify - nothing for an empty 204 response - a tuple...
@wraps(f) def wrapper(*args, **kwargs): ret = f(*args, **kwargs) if ret is None: response = '', 204 elif isinstance(ret, current_app.response_class): response = ret elif isinstance(ret, tuple): # code, result_dict|msg_string if is...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def login(self, action, registry, **kwargs): """ Logs in to a Docker registry. :param action: Action configuration. :type action: dockermap.map.runner.ActionConf...
log.info("Logging into registry %s.", registry) login_kwargs = {'registry': registry} auth_config = action.client_config.auth_configs.get(registry) if auth_config: log.debug("Registry auth config for %s found.", registry) login_kwargs.update(auth_config) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def pull(self, action, image_name, **kwargs): """ Pulls an image for a container configuration :param action: Action configuration. :type action: dockermap.map.r...
config_id = action.config_id registry, __, image = config_id.config_name.rpartition('/') if registry and '.' in registry and registry not in self._login_registries: self.login(action, registry, insecure_registry=kwargs.get('insecure_registry')) log.info("Pulling image %s:%s....
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def parse_networks_output(out): """ Parses the output of the Docker CLI 'docker network ls' and returns it in the format similar to the Docker API. :param out: C...
if not out: return [] line_iter = islice(out.splitlines(), 1, None) # Skip header return list(map(_network_info, line_iter))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def parse_volumes_output(out): """ Parses the output of the Docker CLI 'docker volume ls' and returns it in the format similar to the Docker API. :param out: CLI...
if not out: return [] line_iter = islice(out.splitlines(), 1, None) # Skip header return list(map(_volume_info, line_iter))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def parse_images_output(out): """ Parses the output of the Docker CLI 'docker images'. Note this is currently incomplete and only returns the ids and tags of ima...
line_iter = islice(out.splitlines(), 1, None) # Skip header split_lines = (line.split() for line in line_iter) return [ _summarize_tags(image_id, image_lines) for image_id, image_lines in groupby(sorted(split_lines, key=_get_image_id), key=_get_image_id) ]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def refresh(self): """ Fetches image and their ids from the client. """
if not self._client: return current_images = self._client.images() self.clear() self._update(current_images) for image in current_images: tags = image.get('RepoTags') if tags: self.update({tag: image['Id'] for tag in tags})
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def refresh(self): """ Fetches all current container names from the client, along with their id. """
if not self._client: return current_containers = self._client.containers(all=True) self.clear() for container in current_containers: container_names = container.get('Names') if container_names: c_id = container['Id'] se...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def refresh(self): """ Fetches all current network names from the client, along with their id. """
if not self._client: return current_networks = self._client.networks() self.clear() self.update((net['Name'], net['Id']) for net in current_networks)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def refresh(self): """ Fetches all current network names from the client. """
if not self._client: return current_volumes = self._client.volumes()['Volumes'] self.clear() if current_volumes: self.update(vol['Name'] for vol in current_volumes)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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: DockerHo...
client = self._clients[item].get_client() self[item] = val = self.item_class(client) return val
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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 ...
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.repository) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_extended(self, config): """ Generates a configuration that includes all inherited values. :param config: Container configuration. :type config: Container...
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) ext_cfg =...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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. :rty...
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
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_state_actions(self, state, **kwargs): """ Creates all missing containers, networks, and volumes. :param state: Configuration state. :type state: dockerma...
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: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_state_actions(self, state, **kwargs): """ Generally starts containers that are not running. Attached containers are skipped unless they are initial. Atta...
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, VolumeUtilAction.PREPAR...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_state_actions(self, state, **kwargs): """ Restarts instance containers. :param state: Configuration state. :type state: dockermap.map.state.ConfigState :...
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: ac...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_state_actions(self, state, **kwargs): """ Stops containers that are running. Does not check attached containers. Considers using the pre-configured ``sto...
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)]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_state_actions(self, state, **kwargs): """ Removes containers that are stopped. Optionally skips persistent containers. Attached containers are skipped by...
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 (con...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_state_actions(self, state, **kwargs): """ A combination of CreateActionGenerator and StartActionGenerator - creates and starts containers where appropria...
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), ] eli...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_state_actions(self, state, **kwargs): """ A combination of StopActionGenerator and RemoveActionGenerator - stops and removes containers where appropriate...
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']) for c...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_state_actions(self, state, **kwargs): """ Sends kill signals to running containers. :param state: Configuration state. :type state: dockermap.map.state.C...
if state.config_id.config_type == ItemType.CONTAINER and state.base_state == State.RUNNING: return [ItemAction(state, Action.KILL, extra_data=kwargs)]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_distribution_paths(name): """Return target paths where the package content should be installed"""
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}', '...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def parse_response(response): """ Decodes the JSON response, simply ignoring syntax errors. Therefore it should be used for filtering visible output only. :param...
if isinstance(response, six.binary_type): response = response.decode('utf-8') try: obj = json.loads(response) except ValueError: return {} return obj
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def login(self, username, password=None, email=None, registry=None, reauth=False, **kwargs): """ Login to a Docker registry server. :param username: User name fo...
response = super(DockerClientWrapper, self).login(username, password, email, registry, reauth=reauth, **kwargs) return response.get('Status') == 'Login Succeeded' or response.get('username') == username
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def push(self, repository, stream=False, raise_on_error=True, **kwargs): """ Pushes an image repository to the registry. :param repository: Name of the repositor...
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) re...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def remove_container(self, container, raise_on_error=True, raise_not_found=False, **kwargs): """ Removes a container. For convenience optionally ignores API erro...
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: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def stop(self, container, raise_on_error=True, **kwargs): """ Stops a container. For convenience optionally ignores API errors. :param container: Container name....
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.reraise(*exc...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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...
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
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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 ...
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_kwargs['for...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def push_log(self, info, level, *args, **kwargs): """ Writes logs. To be fully implemented by subclasses. :param info: Log message content. :type info: unicode |...
log.log(level, info, *args, **kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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 instanc...
return self.build(fileobj=ctx.fileobj, tag=tag, custom_context=True, encoding=ctx.stream_encoding, **kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def cleanup_containers(self, include_initial=False, exclude=None, raise_on_error=False, list_only=False): """ Finds all stopped containers and removes them; by d...
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_initial and ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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...
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 ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_container_names(self): """ Fetches names of all present containers from Docker. :return: All container names. :rtype: set """
current_containers = self.containers(all=True) return set(c_name[1:] for c in current_containers for c_name in c['Names'])
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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...
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
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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. :p...
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 {reso...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get(self): """ Resolves and returns the object value. Re-uses an existing previous evaluation, if applicable. :return: The result of evaluating the object. "...
if not self._evaluated: self._val = self._func(*self._args, **self._kwargs) self._evaluated = True return self._val
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def merge_dependency_paths(item_paths): """ Utility function that merges multiple dependency paths, as far as they share dependencies. Paths are evaluated and me...
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 path_...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update_from_dict(self, dct): """ Updates this configuration object from a dictionary. See :meth:`ConfigurationObject.update` for details. :param dct: Values ...
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_dict(ke...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update_from_obj(self, obj, copy=False): """ Updates this configuration object from another. See :meth:`ConfigurationObject.update` for details. :param obj: V...
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_type ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def merge_from_dict(self, dct, lists_only=False): """ Merges a dictionary into this configuration object. See :meth:`ConfigurationObject.merge` for details. :par...
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] ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def merge_from_obj(self, obj, lists_only=False): """ Merges a configuration object into this one. See :meth:`ConfigurationObject.merge` for details. :param obj: ...
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_func is not...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update(self, values, copy_instance=False): """ Updates the configuration with the contents of the given configuration object or dictionary. In case of a dict...
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__, ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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 t...
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.__class_...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def clean(self): """ Cleans the input values of this configuration object. Fields that have gotten updated through properties are converted to configuration valu...
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._modified.clear(...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def as_dict(self): """ Returns a copy of the configuration dictionary. Changes in this should not reflect on the original object. :return: Configuration dictiona...
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: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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...
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) return e....
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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 ...
e = self._deps.get(item) if e is None: return self.get_default() return e.parent
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def merge_dependency(self, item, resolve_parent, parents): """ Merge dependencies of element with further dependencies. First parent dependencies are checked, an...
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_dep) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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...
for item, parents in _iterate_dependencies(items): dep = self._deps[item] merge_list(dep.parent, parents)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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 t...
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: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def preprocess_matches(input_items): """ Converts, as far as possible, Go filepath.Match patterns into Python regular expression patterns. Blank lines are ignore...
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.com...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_exclusions(path): """ Generates exclusion patterns from a ``.dockerignore`` file located in the given path. Returns ``None`` if the file does not exist. ...
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()))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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 :...
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, **kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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 ...
with open(name, 'wb+') as f: while True: buf = self._fileobj.read() if not buf: break f.write(buf)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_volumes(container_map, config, default_volume_paths, include_named): """ Generates volume paths for the ``volumes`` argument during container creation. :...
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)) d...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_volumes_from(container_map, config_name, config, policy, include_volumes): """ Generates volume paths for the host config ``volumes_from`` argument durin...
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_container_na...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_port_bindings(container_config, client_config): """ Generates the input dictionary contents for the ``port_bindings`` argument. :param container_config: ...
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, if...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_preparation_cmd(user, permissions, path): """ Generates the command lines for adjusting a volume's ownership and permission flags. Returns an empty list ...
r_user = resolve_value(user) r_permissions = resolve_value(permissions) if user: yield chown(r_user, path) if permissions: yield chmod(r_permissions, path)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_urlhash(self, url, fmt): """Returns the hash of the file of an internal url """
with self.open(os.path.basename(url)) as f: return {'url': fmt(url), 'sha256': filehash(f, 'sha256')}
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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 a...
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()]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def inspect(self): """ Fetches information about the container from the client. """
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) else: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def inspect(self): """ Fetches image information from the client. """
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 inspecting the im...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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 exp...
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_state(cli...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_states(self, config_ids): """ Generates state information for the selected containers. :param config_ids: List of MapConfigId tuples. :type config_ids: l...
return itertools.chain.from_iterable(self.generate_config_states(config_id) for config_id in config_ids)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_attached_preparation_wait_kwargs(self, action, container_name, kwargs=None): """ Generates keyword arguments for waiting for a container when preparing a...
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_kwargs, k...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _prepare_container(self, client, action, volume_container, volume_alias): """ Runs a temporary container for preparing an attached volume for a container con...
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_containe...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def prepare_attached(self, action, a_name, **kwargs): """ Prepares an attached volume for a container configuration. :param action: Action configuration. :type a...
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 = policy.volum...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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 c...
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.", ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_instance_volumes(instance_detail, check_names): """ Extracts the mount points and mapped directories or names of a Docker container. :param instance_deta...
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('Volume...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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 n...
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))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def disconnect_all_containers(self, action, network_name, containers, **kwargs): """ Disconnects all containers from a network. :param action: Action configurati...
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)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def connect_networks(self, action, container_name, endpoints, skip_first=False, **kwargs): """ Connects a container to a set of configured networks. By default t...
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: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def disconnect_networks(self, action, container_name, networks, **kwargs): """ Disconnects a container from a set of networks. :param action: Action configuratio...
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)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def connect_all_networks(self, action, container_name, **kwargs): """ Connects a container to all of its configured networks. Assuming that this is typically use...
kwargs.setdefault('skip_first', True) self.connect_networks(action, container_name, action.config.networks, **kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def save(self, name): """ Save the string buffer to a file. Finalizes prior to saving. :param name: File path. :type name: unicode | str """
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'))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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 ""...
self.finalize() with open(name, 'wb+') as f: buf = self._fileobj.read() while buf: f.write(buf) buf = self._fileobj.read()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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 val...
return value and isinstance(value, six.string_types) and (value[0] == posixpath.sep or value[:2] == CURRENT_DIR)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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 t...
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; expected a ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: 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 c...
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: retur...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_type_item(self, value): """ Converts the given value to a ``UsedVolume`` or ``SharedVolume`` tuple for attached volumes. It accepts strings, lists, tuple...
if isinstance(value, (UsedVolume, SharedVolume)): if value.readonly: raise ValueError("Attached volumes should not be read-only.") return value elif isinstance(value, six.string_types): return SharedVolume(value) elif isinstance(value, (list, ...