def send_repeated_creation(self, pathname, is_dir): # Check if it is in Solr if not solr.has_doc(pathname): file_info = solr.new_doc(pathname, is_dir) file_info.save() for signaler in self.signalers: signaler.raise_event("create", pathname, '', is_dir) else: file_info = solr.retrieve_doc(pathname) file_info.save() # Send repeat message via D-Bus for signaler in self.signalers: signaler.raise_event("repeat", pathname, '', is_dir)
def process_IN_MOVED_TO(self, event): try: if not hasattr(event, 'src_pathname'): # We come from a directory outside # so this is equivalent to a creation self.process_IN_CREATE(event) else: # The movement is in between watched folders # Change pathname in Solr if solr.has_doc(event.src_pathname): file_info = solr.retrieve_doc(event.src_pathname) file_info.set_new_pathname(event.pathname) file_info.save() self.raise_signal("move", event) else: # This is equivalent to creation self.create_or_send_modifications("move", event) # We are in a dir, change inner elements if event.dir: # We are in a folder dir_name = event.src_pathname new_dir_name = event.pathname # Change the path for inotify events self.change_watched_path(event.src_pathname, event.pathname) # Change in saved watched folders for signaler in self.signalers: signaler.replace_context(dir_name, new_dir_name, True) # Update files in Solr and send events for them for file_info in solr.retrieve_docs_in_dir(dir_name): file_path = file_info.get_pathname() new_file_path = file_path.replace(dir_name, new_dir_name, 1) file_info.set_new_pathname(new_file_path) file_info.save() if file_info.is_directory(): # It may be watched, so try to replace it for signaler in self.signalers: signaler.replace_context(file_path, new_file_path, True) except: sys.stderr.write('An exception ocurred at ' + str(datetime.now()) + ':\n') traceback.print_exc(file=sys.stderr) sys.stderr.write('\n\n')
def create_or_send_modifications(self, event_name, event): # If not file, check parent folder is in database if not event.dir: parent = os.path.dirname(event.pathname) if parent != '/var/nublic/data': # Not in top path if not solr.has_doc(parent): fake_event = FakeCreationEvent(parent, True) self.process_IN_CLOSE_WRITE(fake_event) # Check if it is itself in Solr file_info = solr.retrieve_doc(event.pathname) if file_info == None: # Create new Solr document file_info = solr.new_doc(event.pathname, event.dir) file_info.save() self.raise_signal("create", event) # Possibly at to watched list if event.dir: for signaler in self.signalers: signaler.add_context(event.pathname) else: # Recreate Solr info file_info.save() self.raise_signal(event_name, event)