def __init__(self): self.started = False # ignore warnings from inotify in case we have duplicate addons paths. inotify.adapters._LOGGER.setLevel(logging.ERROR) # recreate a list as InotifyTrees' __init__ deletes the list's items paths_to_watch = [] for path in odoo.modules.module.ad_paths: paths_to_watch.append(path) _logger.info('Watching addons folder %s', path) self.watcher = InotifyTrees(paths_to_watch, mask=INOTIFY_LISTEN_EVENTS, block_duration_s=.5)
def __watch_paths(self): paths = [ repo.path for repo in self.repositories ] inotify = InotifyTrees(paths,mask=event_mask) # Watch events in repositories for event in inotify.event_gen(yield_nones=False): if self.__should_process_event(event): self.__handle_event(event)
def run(self): if self.repofile: # Parse repositories on every run to allow restarting to daemon to # update the repositories. self.__parse_repositories() paths = list(map(lambda x: x.path, self.repositories)) inotify = InotifyTrees(paths) for event in inotify.event_gen(yield_nones=False): if self.__should_process_event(event): self.__handle_event(event) else: # A client might end up in the case if they don't pass a repofile to # the constructor. Allowing the user to not pass a repofile, makes # it easier for the user to construct the daemon when they only want # to stop it. print >> self.stderr, ("run() called without providing a repofile") self.stop()
class FSWatcherInotify(FSWatcherBase): def __init__(self): self.started = False # ignore warnings from inotify in case we have duplicate addons paths. inotify.adapters._LOGGER.setLevel(logging.ERROR) # recreate a list as InotifyTrees' __init__ deletes the list's items paths_to_watch = [] for path in odoo.modules.module.ad_paths: paths_to_watch.append(path) _logger.info('Watching addons folder %s', path) self.watcher = InotifyTrees(paths_to_watch, mask=INOTIFY_LISTEN_EVENTS, block_duration_s=.5) def run(self): _logger.info('AutoReload watcher running with inotify') dir_creation_events = set(('IN_MOVED_TO', 'IN_CREATE')) while self.started: for event in self.watcher.event_gen(timeout_s=0, yield_nones=False): (_, type_names, path, filename) = event if 'IN_ISDIR' not in type_names: # despite not having IN_DELETE in the watcher's mask, the # watcher sends these events when a directory is deleted. if 'IN_DELETE' not in type_names: full_path = os.path.join(path, filename) if self.handle_file(full_path): return elif dir_creation_events.intersection(type_names): full_path = os.path.join(path, filename) for root, _, files in os.walk(full_path): for file in files: if self.handle_file(os.path.join(root, file)): return def start(self): self.started = True self.thread = threading.Thread(target=self.run, name="odoo.service.autoreload.watcher") self.thread.setDaemon(True) self.thread.start() def stop(self): self.started = False self.thread.join()