Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_task_fallback(self, files, options={}, name=None, progress_callback=None):
# Pre chunked API create task implementation, used as fallback
if len(files) == 0:
raise NodeResponseError("Not enough images")
# Equivalent as passing the open file descriptor, since requests
# eventually calls read(), but this way we make sure to close
# the file prior to reading the next, so we don't run into open file OS limits
def read_file(file_path):
with open(file_path, 'rb') as f:
return f.read()
fields = {
'name': name,
'options': options_to_json(options),
'images': [(os.path.basename(f), read_file(f), (mimetypes.guess_type(f)[0] or "image/jpg")) for
f in files]
}
def create_callback(mpe):
total_bytes = mpe.len
def callback(monitor):
if progress_callback is not None and total_bytes > 0:
progress_callback(100.0 * monitor.bytes_read / total_bytes)
return callback
e = MultipartEncoder(fields=fields)
m = encoder.MultipartEncoderMonitor(e, create_callback(e))
def restart(self, options=None):
"""Restart this task.
Args:
options (dict): options to use, for example {'orthophoto-resolution': 3, ...}
Returns:
bool: task was restarted or not
"""
data = {'uuid': self.uuid}
if options is not None: data['options'] = options_to_json(options)
return self.post('/task/restart', data).get('success', False)