Exemplo n.º 1
0
 def initial_processing(self, watch_directories, event_handler):
     for watch_directory in watch_directories:
         for root, dir_names, file_names in os.walk(watch_directory):
             for filename in file_names:
                 file_path = os.path.join(root, filename).decode('utf-8')
                 if file_path not in self.mfq or (
                         file_path in self.mfq
                         and self.mfq[file_path].status != MediaFileState.FAILED):
                     file_event = FileSystemEvent(file_path)
                     file_event.is_directory = False
                     file_event.event_type = EVENT_TYPE_CREATED
                     event_handler.on_any_event(file_event)
Exemplo n.º 2
0
def test_directory(database):
    session = database()
    study = Study()
    study.name = 'STUDY'
    session.add(study)
    session.commit()
    test_path = '/test/STUDY/dir'
    handler = FsEventHandler(database, '/test')
    event = FileSystemEvent(test_path)
    event.is_directory = True
    handler.on_created(event)
    f = session.query(ReceivedDir).filter_by(dirname=test_path).one()
    assert f.dirname == test_path
    assert f.study.name == 'STUDY'
Exemplo n.º 3
0
def test_directory(database):
    session = database()
    study = Study()
    study.name = "STUDY"
    session.add(study)
    session.commit()
    test_path = "/test/STUDY/dir"
    handler = FsEventHandler(database, "/test")
    event = FileSystemEvent(test_path)
    event.is_directory = True
    handler.on_created(event)
    f = session.query(ReceivedDir).filter_by(dirname=test_path).one()
    assert f.dirname == test_path
    assert f.study.name == "STUDY"
	def on_moved(self, event):
		"""
		File/Folder moved/renamed
		All changes are marked as moved even it was renamed
		Due to File moved, Folder moved events got trigger in an event of Folder renamed so we have to find a way to filter this noise
		:param event:
		:return:
		"""
		src_path, src_name = os.path.split(event.src_path)
		path, name = os.path.split(event.dest_path)

		pp, prev_parent_name = os.path.split(src_path)
		pp, parent_name = os.path.split(path)

		if prev_parent_name != parent_name:
			self.process(event)

		if src_name != name:
			renamedEvent = FileSystemEvent(event.src_path)
			renamedEvent.event_type = 'renamed'
			renamedEvent.is_directory = event.is_directory
			renamedEvent.dest_path = event.dest_path
			self.process(renamedEvent)