def dispatch(source, destinations): """Dispatch source file to destinations.""" any_error = False # check that file actually exists if not os.path.exists(source): message = "Source file for dispatching does not exist:{}".format( str(source)) logger.error(message) any_error = True success = {} # rename and send file with right protocol for url, params, client in destinations: # Multiple destinations for one client isn't implemented if client in success: raise NotImplementedError( "Only one destination allowed per client") try: logger.debug("Dispatching %s to %s", source, str(clean_url(url))) move_it(source, url, params) success[client] = True except Exception as err: message = "Could not dispatch to {}: {}".format( str(clean_url(url)), str(err)) logger.error(message) any_error = True success[client] = False if not any_error: logger.info("Dispatched all files.") return success
def _move_file(self, pathname, message, rel_path): error_message = None try: move_it(pathname, message.data['destination'], self._attrs, rel_path=rel_path) except Exception as err: error_message = Message(message.subject, "err", data=str(err)) else: self._add_to_deleter(pathname) return error_message
def dispatch(source, destinations): """Dispatch source file to destinations.""" any_error = False # check that file actually exists if not os.path.exists(source): message = "Source file for dispatching does not exist:{}".format( str(source)) logger.error(message) any_error = True # rename and send file with right protocol for url, params in destinations: try: logger.debug("Dispatching %s to %s", source, str(clean_url(url))) move_it(source, url, params) except Exception as err: message = "Could not dispatch to {}: {}".format( str(clean_url(url)), str(err)) logger.error(message) any_error = True if not any_error: logger.info("Dispatched all files.")
def push(self, message): """Reply to push request """ for the_dict in gen_dict_contains(message.data, 'uri'): uri = urlparse(the_dict['uri']) rel_path = the_dict.get('path', None) pathname = uri.path # FIXME: check against file_cache if 'origin' in self._attrs and not fnmatch.fnmatch( os.path.basename(pathname), os.path.basename(globify(self._attrs["origin"]))): LOGGER.warning('Client trying to get invalid file: %s', pathname) return Message(message.subject, "err", data="{0:s} not reachable".format(pathname)) try: move_it(pathname, message.data['destination'], self._attrs, rel_path=rel_path) except Exception as err: return Message(message.subject, "err", data=str(err)) else: if (self._attrs.get('compression') or self._attrs.get( 'delete', 'False').lower() in ["1", "yes", "true", "on"]): self._deleter.add(pathname) if 'dataset' in message.data: mtype = 'dataset' elif 'collection' in message.data: mtype = 'collection' elif 'uid' in message.data: mtype = 'file' else: raise KeyError('No known metadata in message.') new_msg = Message(message.subject, mtype, data=message.data.copy()) new_msg.data['destination'] = clean_url(new_msg.data[ 'destination']) return new_msg