text
stringlengths
0
828
m(name, count, elapsed)
return multi_metric"
1016,"def _is_orphan(scc, graph):
""""""
Return False iff the given scc is reachable from elsewhere.
""""""
return all(p in scc for v in scc for p in graph.parents(v))"
1017,"def key_cycles():
""""""
Collect cyclic garbage, and return the strongly connected
components that were keeping the garbage alive.
""""""
graph = garbage()
sccs = graph.strongly_connected_components()
return [scc for scc in sccs if _is_orphan(scc, graph)]"
1018,"def _run_command(self, command, **kwargs):
""""""Wrapper to pass command to plowshare.
:param command: The command to pass to plowshare.
:type command: str
:param **kwargs: Additional keywords passed into
:type **kwargs: dict
:returns: Object containing either output of plowshare command or an
error message.
:rtype: dict
:raises: Exception
""""""
try:
return {'output': subprocess.check_output(command, **kwargs)}
except Exception as e:
return {'error': str(e)}"
1019,"def _hosts_by_success(self, hosts=[]):
""""""Order hosts by most successful (least amount of errors) first.
:param hosts: List of hosts.
:type hosts: list
:returns: List of hosts sorted by successful connections.
:rtype: list
""""""
hosts = hosts if hosts else self.hosts
return sorted(hosts, key=lambda h: self._host_errors[h])"
1020,"def _filter_sources(self, sources):
""""""Remove sources with errors and return ordered by host success.
:param sources: List of potential sources to connect to.
:type sources: list
:returns: Sorted list of potential sources without errors.
:rtype: list
""""""
filtered, hosts = [], []
for source in sources:
if 'error' in source:
continue
filtered.append(source)
hosts.append(source['host_name'])
return sorted(filtered, key=lambda s:
self._hosts_by_success(hosts).index(s['host_name']))"
1021,"def upload(self, filename, number_of_hosts):
""""""Upload the given file to the specified number of hosts.
:param filename: The filename of the file to upload.
:type filename: str
:param number_of_hosts: The number of hosts to connect to.
:type number_of_hosts: int
:returns: A list of dicts with 'host_name' and 'url' keys for all
successful uploads or an empty list if all uploads failed.
:rtype: list
""""""
return self.multiupload(filename, self.random_hosts(number_of_hosts))"
1022,"def download(self, sources, output_directory, filename):
""""""Download a file from one of the provided sources
The sources will be ordered by least amount of errors, so most
successful hosts will be tried first. In case of failure, the next
source will be attempted, until the first successful download is
completed or all sources have been depleted.
:param sources: A list of dicts with 'host_name' and 'url' keys.
:type sources: list
:param output_directory: Directory to save the downloaded file in.
:type output_directory: str
:param filename: Filename assigned to the downloaded file.
:type filename: str
:returns: A dict with 'host_name' and 'filename' keys if the download
is successful, or an empty dict otherwise.
:rtype: dict
""""""
valid_sources = self._filter_sources(sources)
if not valid_sources:
return {'error': 'no valid sources'}
manager = Manager()
successful_downloads = manager.list([])
def f(source):
if not successful_downloads:
result = self.download_from_host(