def call_filecheck(self, my_q_event): while True: file_path, path_watch = my_q_event.get() logging.info("File found : {}".format(file_path)) try: ts_now = -1 while ts_now != os.stat(file_path).st_mtime: ts_now = os.stat(file_path).st_mtime time.sleep(2) except (OSError, ValueError, IOError) as e: time.sleep(5) logging.warning( 'File diseaper/rename - try to relaunch | msg : {}'.format( e)) self.init_launch(my_q_event, path_watch) continue except Exception as e: logging.error(e) continue path_normalize = parser_yaml.normalize_path(path_watch) val_file = parser_yaml.get_read_single_yaml(path_normalize) FileHandle(file_path, val_file['file_pattern'], val_file['min_size'], val_file['command'], val_file['timewait']) my_q_event.task_done()
def modify_path_watch(self): Config().check_config(path_watch=self.path_watch, file_pattern=self.file_pattern, min_size=self.min_size, timewait=self.timewait) list_file = parser_yaml.get_list_file_data() path_file_name = parser_yaml.normalize_path(self.path_watch) if path_file_name not in list_file: logging.error("Path already exists : {} | use ajouter".format( self.path_watch)) return False modif_val = parser_yaml.get_read_single_yaml(path_file_name) if self.file_pattern is not None: modif_val['file_pattern'] = self.file_pattern if self.min_size is not None: modif_val['min_size'] = self.min_size if self.command is not None: modif_val['command'] = self.command if self.timewait is not None: modif_val['timewait'] = self.timewait parser_yaml.set_write_yaml(path_file_name, modif_val) logging.info('Modify for path {}'.format(self.path_watch)) return True
def supp_val_yaml(self, **kwargs): list_file = parser_yaml.get_list_file_data() path_file_name = parser_yaml.normalize_path(self.path_watch) if path_file_name not in list_file: logging.error("Path not found : {}".format(self.path_watch)) return False os.remove(path_file_name) logging.info('Path is deleted in FileWatcher {}'.format( self.path_watch)) return True
def output_path_watch(self): list_file = parser_yaml.get_list_file_data() output_dataset = [] if self.list_path_watch is None: for path_file in list_file: output_dataset.append(self.order_append_dict(path_file)) else: data_path = parser_yaml.get_data_path_file() for path_in in self.list_path_watch: path_file_name = parser_yaml.normalize_path(path_in).replace( '.yaml', '') for path_file in list_file: if path_file_name.replace(data_path, '').replace( os.path.sep, '') in path_file.replace( data_path, '').replace(os.path.sep, ''): output_dataset.append( self.order_append_dict(path_file)) print(tabulate(output_dataset, headers='keys', tablefmt='psql'))
def add_val_yaml(self): Config().check_config(path_watch=self.path_watch, file_pattern=self.file_pattern, min_size=self.min_size, timewait=self.timewait) path_file_name = parser_yaml.normalize_path(self.path_watch) new_val = { 'path_watch': self.path_watch, 'file_pattern': self.file_pattern, 'min_size': self.min_size, 'command': self.command, 'timewait': self.timewait } parser_yaml.set_write_yaml(path_file_name, new_val) logging.info('Add new path to watch : {}'.format(self.path_watch)) return True