def process(self, event): flags_ = flags.from_mask(event.mask) if flags.ISDIR in flags_: if flags.DELETE in flags_: path = os.path.join(self.TRACKING_DIRS, event.directory.path) if os.path.exists(path): os.system('rm -r {}'.format(path)) else: # TODO: add proper exception logger_srv.error('Do not support "{}" type of operations ' .format(flags_)) raise NotImplementedError else: path = os.path.join(self.TRACKING_DIRS, event.directory.path, event.name) if flags.MODIFY in flags_: fc.patch(path, event.diff) elif flags.DELETE in flags_: if os.path.exists(path): os.system('rm {}'.format(path)) else: # TODO: add proper exception logger_srv.error('Do not support "{}" type of operations ' .format(flags_)) raise NotImplementedError
def test_compare_empty_and_non_empty_file_get_diff_patch_first_file(self): os.system('echo >' + self.file1) os.system('echo hello > ' + self.file2) diff = fc.diff(self.file1, self.file2) self.assertFalse(fc.is_equal(self.file1, self.file2)) self.assertEqual(len(diff), 1) os.system('echo world >> ' + self.file2) diff = fc.diff(self.file1, self.file2) self.assertFalse(fc.is_equal(self.file1, self.file2)) self.assertEqual(len(diff), 2) fc.patch(self.file1, diff) self.assertTrue(fc.is_equal(self.file1, self.file2))
def test_replace_and_delete_in_files_for_patch(self): os.system('echo hello >' + self.file1) os.system('echo awful >>' + self.file1) os.system('echo world >>' + self.file1) os.system('echo haaaa!! >> ' + self.file1) os.system('echo hello > ' + self.file2) os.system('echo great >> ' + self.file2) os.system('echo my >> ' + self.file2) os.system('echo world >> ' + self.file2) diff = fc.diff(self.file1, self.file2) self.assertFalse(fc.is_equal(self.file1, self.file2)) self.assertEqual(len(diff), 3) fc.patch(self.file1, diff) self.assertTrue(fc.is_equal(self.file1, self.file2))
def process(self, event): flags_ = flags.from_mask(event.mask) # Generate path to local copy for new object to have chance # get changes on object modify event later. ds_path_to_new_object = \ os.path.join(self.ds_path, event.directory.path[len(self.directory)+1:]) if flags.ISDIR in flags_: if flags.CREATE in flags_: copy_tree(event.directory.path, ds_path_to_new_object) self.sender.send_directory(event.directory.path) elif flags.DELETE in flags_: os.system('rm -r {}'.format(ds_path_to_new_object)) self.sender.send_event(event) else: logger_cl.error('Can not handle "{}" event'.format(flags_)) # TODO: add proper exception raise NotImplementedError else: file_path = os.path.join(event.directory.path, event.name) ds_file_path = os.path.join(ds_path_to_new_object, event.name) if flags.CREATE in flags_: if not os.path.exists(ds_path_to_new_object): os.mkdir(ds_path_to_new_object) os.system('cp {} {}'.format(file_path, ds_file_path)) self.sender.send_file(event.directory.path, event.name) elif flags.MODIFY in flags_: diff = fc.diff(ds_file_path, file_path) fc.patch(ds_file_path, diff) event.diff = diff self.sender.send_event(event) elif flags.DELETE in flags_: if os.path.exists(ds_file_path): os.system('rm -r {}'.format(ds_file_path)) self.sender.send_event(event) else: # TODO: add proper exception logger_cl.error('Can not handle "{}" event'.format(flags_)) raise NotImplementedError