text
stringlengths
0
828
source, output_directory, filename)
if 'error' in result:
self._host_errors[source['host_name']] += 1
else:
successful_downloads.append(result)
multiprocessing.dummy.Pool(len(valid_sources)).map(f, valid_sources)
return successful_downloads[0] if successful_downloads else {}"
1023,"def download_from_host(self, source, output_directory, filename):
""""""Download a file from a given host.
This method renames the file to the given string.
:param source: Dictionary containing information about host.
:type source: dict
:param output_directory: Directory to place output in.
:type output_directory: str
:param filename: The filename to rename to.
:type filename: str
:returns: Dictionary with information about downloaded file.
:rtype: dict
""""""
result = self._run_command(
[""plowdown"", source[""url""], ""-o"",
output_directory, ""--temp-rename""],
stderr=open(""/dev/null"", ""w"")
)
result['host_name'] = source['host_name']
if 'error' in result:
return result
temporary_filename = self.parse_output(
result['host_name'], result['output'])
result['filename'] = os.path.join(output_directory, filename)
result.pop('output')
os.rename(temporary_filename, result['filename'])
return result"
1024,"def multiupload(self, filename, hosts):
""""""Upload file to multiple hosts simultaneously
The upload will be attempted for each host until the optimal file
redundancy is achieved (a percentage of successful uploads) or the host
list is depleted.
:param filename: The filename of the file to upload.
:type filename: str
:param hosts: A list of hosts as defined in the master host list.
:type hosts: list
: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
""""""
manager = Manager()
successful_uploads = manager.list([])
def f(host):
if len(successful_uploads) / float(len(hosts)) < \
settings.MIN_FILE_REDUNDANCY:
# Optimal redundancy not achieved, keep going
result = self.upload_to_host(filename, host)
if 'error' in result:
self._host_errors[host] += 1
else:
successful_uploads.append(result)
multiprocessing.dummy.Pool(len(hosts)).map(
f, self._hosts_by_success(hosts))
return list(successful_uploads)"
1025,"def upload_to_host(self, filename, hostname):
""""""Upload a file to the given host.
This method relies on 'plowup' being installed on the system.
If it succeeds, this method returns a dictionary with the host name,
and the final URL. Otherwise, it returns a dictionary with the
host name and an error flag.
:param filename: The filename of the file to upload.
:type filename: str
:param hostname: The host you are uploading the file to.
:type hostname: str
:returns: Dictionary containing information about upload to host.
:rtype: dict
""""""
result = self._run_command(
[""plowup"", hostname, filename],
stderr=open(""/dev/null"", ""w"")
)
result['host_name'] = hostname
if 'error' not in result:
result['url'] = self.parse_output(hostname, result.pop('output'))
return result"
1026,"def parse_output(self, hostname, output):