def upload_bundle(self, path, info, worksheet_uuid, follow_symlinks, exclude_patterns, add_to_worksheet): # URLs can be directly passed to the local client. if path and not isinstance(path, list) and path_util.path_is_url(path): return self.upload_bundle_url(path, info, worksheet_uuid, follow_symlinks, exclude_patterns) # First, zip path up (temporary local zip file). if path: name = info['metadata']['name'] zip_path = zip_util.zip(path, follow_symlinks=follow_symlinks, exclude_patterns=exclude_patterns, file_name=name) # Copy it up to the server (temporary remote zip file) with open(zip_path, 'rb') as source: remote_file_uuid = self.open_temp_file() dest = RPCFileHandle(remote_file_uuid, self.proxy) # FileServer does not expose an API for forcibly flushing writes, so # we rely on closing the file to flush it. file_util.copy(source, dest, autoflush=False, print_status='Uploading %s%s to %s' % (zip_path, ' ('+info['uuid']+')' if 'uuid' in info else '', self.address)) dest.close() else: remote_file_uuid = None zip_path = None # Finally, install the zip file (this will be in charge of deleting that zip file). result = self.upload_bundle_zip(remote_file_uuid, info, worksheet_uuid, follow_symlinks, add_to_worksheet) if zip_path: path_util.remove(zip_path) # Remove local zip return result
def upload_bundle(self, path, info, worksheet_uuid, follow_symlinks): # URLs can be directly passed to the local client. if path and not isinstance(path, list) and path_util.path_is_url(path): return self.upload_bundle_url(path, info, worksheet_uuid, follow_symlinks) # First, zip path up (temporary local zip file). if path: zip_path, sub_path = zip_util.zip(path, follow_symlinks=follow_symlinks) # Copy it up to the server (temporary remote zip file) with open(zip_path, 'rb') as source: remote_file_uuid = self.open_temp_file() dest = RPCFileHandle(remote_file_uuid, self.proxy) # FileServer does not expose an API for forcibly flushing writes, so # we rely on closing the file to flush it. file_util.copy(source, dest, autoflush=False, print_status=True) dest.close() else: remote_file_uuid = None zip_path = None # Finally, install the zip file (this will be in charge of deleting that zip file). result = self.upload_bundle_zip(remote_file_uuid, info, worksheet_uuid, follow_symlinks) if zip_path: path_util.remove(zip_path) # Remove local zip return result
def open_target_zip(self, target, follow_symlinks): ''' Return a file uuid for the zip file and the name that the zip file contains. ''' bundle_uuid = target[0] path = self.client.get_target_path(target) name = self.client.get_bundle_info(bundle_uuid)['metadata']['name'] zip_path = zip_util.zip(path, follow_symlinks=follow_symlinks, exclude_patterns=[], file_name=name) # Create temporary zip file return self.open_file(zip_path, 'rb'), name
def upload(self, bundle_type, path, metadata, worksheet_uuid=None): zip_path = zip_util.zip(path) with open(zip_path, 'rb') as source: remote_file_uuid = self.open_temp_file() dest = RPCFileHandle(remote_file_uuid, self.proxy) with contextlib.closing(dest): # FileServer does not expose an API for forcibly flushing writes, so # we rely on closing the file to flush it. file_util.copy(source, dest, autoflush=False) return self.upload_zip(bundle_type, remote_file_uuid, metadata, worksheet_uuid)
def open_target_zip(self, target, follow_symlinks): ''' Return a file uuid for the zip file and the name that the zip file contains. ''' bundle_uuid = target[0] path = self.client.get_target_path(target) name = self.client.get_bundle_info(bundle_uuid)['metadata']['name'] zip_path = zip_util.zip(path, follow_symlinks=follow_symlinks, exclude_patterns=[], file_name=name) # Create temporary zip file return self.open_file(zip_path), name
def upload_bundle(self, path, info, worksheet_uuid, follow_symlinks, exclude_patterns, add_to_worksheet): # URLs can be directly passed to the local client. if path and not isinstance(path, list) and path_util.path_is_url(path): return self.upload_bundle_url(path, info, worksheet_uuid, follow_symlinks, exclude_patterns) # First, zip path up (temporary local zip file). if path: name = info['metadata']['name'] zip_path = zip_util.zip(path, follow_symlinks=follow_symlinks, exclude_patterns=exclude_patterns, file_name=name) # Copy it up to the server (temporary remote zip file) with open(zip_path, 'rb') as source: remote_file_uuid = self.open_temp_file() dest = RPCFileHandle(remote_file_uuid, self.proxy) # FileServer does not expose an API for forcibly flushing writes, so # we rely on closing the file to flush it. file_util.copy(source, dest, autoflush=False, print_status='Uploading %s%s to %s' % (zip_path, ' (' + info['uuid'] + ')' if 'uuid' in info else '', self.address)) dest.close() else: remote_file_uuid = None zip_path = None # Finally, install the zip file (this will be in charge of deleting that zip file). result = self.upload_bundle_zip(remote_file_uuid, info, worksheet_uuid, follow_symlinks, add_to_worksheet) if zip_path: path_util.remove(zip_path) # Remove local zip return result
def open_target_zip(self, target, follow_symlinks): bundle_uuid = target[0] path = self.client.get_target_path(target) name = self.client.get_bundle_info(bundle_uuid)['metadata']['name'] zip_path, sub_path = zip_util.zip(path, follow_symlinks=follow_symlinks, file_name=name) # Create temporary zip file return self.open_file(zip_path, 'rb'), sub_path