def delivery(self): """ Goal of delivery is checks if some delivery is configured for a context/receiver combo, and if is, just delivery the file in the requested way. If not, store in the DB and permit downloading. """ plugin_type = u'delivery' store = self.getStore() file_iface = File(store) receivertip_iface = ReceiverTip(store) receivercfg_iface = ReceiverConfs(store) profile_iface = PluginProfiles(store) ready_files = file_iface.get_file_by_marker(file_iface._marker[1]) # ready for single_file in ready_files: # from every file, we need to find the ReceiverTip with the same InternalTip.id # This permit to found effectively the receiver that need the file available print "Delivery management for", single_file['file_name'] #rtip_list = receivertip_iface.get_tips_by_itip(single_file['internaltip_id']) #for rtip in rtip_list: # -------------------------------------------------------------------- # This code is not yet executed until GPG delivery plugin is not ready # Ok, we had a valid an appropriate receiver configuration for the delivery task #related_profile = profile_iface.get_single(receiver_conf['profile_gus']) #settings_dict = { 'admin_settings' : related_profile['admin_settings'], # 'receiver_settings' : receiver_conf['receiver_settings']} #plugin = PluginManager.instance_plugin(related_profile['plugin_name']) # TODO Update delivery information #return_code = plugin.do_delivery(settings_dict, single_file) tempfpath = os.path.join(config.advanced.submissions_dir, single_file['file_gus']) file_iface.add_content_from_fs(single_file['file_gus'], tempfpath) file_iface.flip_mark(single_file['file_gus'], file_iface._marker[3]) # stored
def fileprocess(self): store = self.getStore() file_iface = File(store) not_processed_file = file_iface.get_file_by_marker(file_iface._marker[0]) associated_itip = {} new_files = {} for single_file in not_processed_file: itid = single_file['internaltip_id'] # if InternalTip.id is 0, mean that Submission is not finalized! # the file remain marked as 'not processed'. if not itid: continue # collect for logs/info/flow associated_itip.update({ itid : InternalTip(store).get_single(itid) }) # this file log do not contain hash nor path: it's fine anyway new_files.update({ single_file['file_gus'] : single_file }) try: tempfpath = os.path.join(config.advanced.submissions_dir, single_file['file_gus']) # XXX Access check + stats + length integrity except AttributeError: # XXX high level danger Log continue validate_file = self.do_fileprocess_validation(store,single_file['context_gus'], tempfpath) # compute hash, SHA256 in non blocking mode (from utils/random.py) filehash = get_file_checksum(tempfpath) print "Processed:", single_file['file_name'], filehash, "validator response:", validate_file if validate_file: file_iface.flip_mark(single_file['file_gus'], file_iface._marker[1], filehash) # ready else: file_iface.flip_mark(single_file['file_gus'], file_iface._marker[2], filehash) # blocked return (associated_itip, new_files)
def operation(self): """ Goal of this function is to check all the new files and validate thru the configured SystemSettings possible marker in the file are: 'not processed', 'ready', 'blocked', 'stored' defined in File._marker """ plugin_type = u'fileprocess' file_iface = File() profile_iface = PluginProfiles() not_processed_file = yield file_iface.get_file_by_marker(file_iface._marker[0]) print "FileProcess", not_processed_file for single_file in not_processed_file: profile_associated = yield profile_iface.get_profiles_by_contexts([ single_file['context_gus'] ] ) for p_cfg in profile_associated: if p_cfg['plugin_type'] != plugin_type: continue print "processing", single_file['file_name'], "using the profile", p_cfg['profile_gus'], "configured for", p_cfg['plugin_name'] plugin = PluginManager.instance_plugin(p_cfg['plugin_name']) try: tempfpath = os.path.join(config.advanced.submissions_dir, single_file['file_gus']) except AttributeError: # XXX hi level danger Log - no directory present to perform file analysis continue return_code = plugin.do_fileprocess(tempfpath, p_cfg['admin_settings']) # Todo Log/stats in both cases if return_code: yield file_iface.flip_mark(single_file['file_gus'], file_iface._marker[1]) # ready else: yield file_iface.flip_mark(single_file['file_gus'], file_iface._marker[2]) # blocked
def fileprocess(self): plugin_type = u'fileprocess' store = self.getStore() file_iface = File(store) profile_iface = PluginProfiles(store) not_processed_file = file_iface.get_file_by_marker(file_iface._marker[0]) for single_file in not_processed_file: profile_associated = profile_iface.get_profiles_by_contexts([ single_file['context_gus'] ] ) for p_cfg in profile_associated: if p_cfg['plugin_type'] != plugin_type: continue print "processing", single_file['file_name'], "using the profile", p_cfg['profile_gus'], "configured for", p_cfg['plugin_name'] plugin = PluginManager.instance_plugin(p_cfg['plugin_name']) try: tempfpath = os.path.join(config.advanced.submissions_dir, single_file['file_gus']) except AttributeError: # XXX hi level danger Log - no directory present to perform file analysis continue return_code = plugin.do_fileprocess(tempfpath, p_cfg['admin_settings']) # Todo Log/stats in both cases if return_code: file_iface.flip_mark(single_file['file_gus'], file_iface._marker[1]) # ready else: file_iface.flip_mark(single_file['file_gus'], file_iface._marker[2]) # blocked