def __init__(self): """ Watches file change events (creation, modification) in the watched project. """ from baboon.baboon.plugins.git.monitor_git import EventHandlerGit self.dancer = Dancer(sleeptime=1) # All monitor will be stored in this dict. The key is the project name, # the value is the monitor instance. self.monitors = {} try: # Avoid to use iteritems (python 2.x) or items (python 3.x) in # order to support both versions. for project in sorted(config['projects']): project_attrs = config['projects'][project] project_path = os.path.expanduser(project_attrs['path']) self.handler = EventHandlerGit(project_path) monitor = Observer() monitor.schedule(self.handler, project_path, recursive=True) self.monitors[project_path] = monitor except OSError as err: self.logger.error(err) raise BaboonException(err)
class Monitor(object): def __init__(self): """ Watches file change events (creation, modification) in the watched project. """ from baboon.baboon.plugins.git.monitor_git import EventHandlerGit self.dancer = Dancer(sleeptime=1) # All monitor will be stored in this dict. The key is the project name, # the value is the monitor instance. self.monitors = {} try: # Avoid to use iteritems (python 2.x) or items (python 3.x) in # order to support both versions. for project in sorted(config['projects']): project_attrs = config['projects'][project] project_path = os.path.expanduser(project_attrs['path']) self.handler = EventHandlerGit(project_path) monitor = Observer() monitor.schedule(self.handler, project_path, recursive=True) self.monitors[project_path] = monitor except OSError as err: self.logger.error(err) raise BaboonException(err) def watch(self): """ Starts to watch the watched project """ # Start all monitor instance. for project, monitor in self.monitors.iteritems(): monitor.start() self.logger.debug("Started to monitor the %s directory" % project) self.dancer.start() def startup_rsync(self, project, project_path): """ """ # Get the timestamp of the last rsync. register_timestamp = os.path.getmtime(join(project_path, '.baboon-timestamp')) for root, _, files in os.walk(project_path): for name in files: fullpath = join(root, name) rel_path = os.path.relpath(fullpath, project_path) # Get the timestamp of the current file cur_timestamp = os.path.getmtime(fullpath) # Register a FileEvent.MODIF if the file is not excluded # and the file is more recent than the last rsync. if not self.handler.exclude(rel_path) and \ cur_timestamp > register_timestamp: FileEvent(project, FileEvent.MODIF, rel_path).register() def close(self): """ Stops the monitoring on the watched project """ # Stop all monitor instance. for project, monitor in self.monitors.iteritems(): monitor.stop() monitor.join() self.dancer.close() self.dancer.join()
class Monitor(object): def __init__(self): """ Watches file change events (creation, modification) in the watched project. """ from baboon.baboon.plugins.git.monitor_git import EventHandlerGit self.dancer = Dancer(sleeptime=1) # All monitor will be stored in this dict. The key is the project name, # the value is the monitor instance. self.monitors = {} try: # Avoid to use iteritems (python 2.x) or items (python 3.x) in # order to support both versions. for project in sorted(config['projects']): project_attrs = config['projects'][project] project_path = os.path.expanduser(project_attrs['path']) self.handler = EventHandlerGit(project_path) monitor = Observer() monitor.schedule(self.handler, project_path, recursive=True) self.monitors[project_path] = monitor except OSError as err: self.logger.error(err) raise BaboonException(err) def watch(self): """ Starts to watch the watched project """ # Start all monitor instance. for project, monitor in self.monitors.iteritems(): monitor.start() self.logger.debug("Started to monitor the %s directory" % project) self.dancer.start() def startup_rsync(self, project, project_path): """ """ # Get the timestamp of the last rsync. register_timestamp = os.path.getmtime( join(project_path, '.baboon-timestamp')) for root, _, files in os.walk(project_path): for name in files: fullpath = join(root, name) rel_path = os.path.relpath(fullpath, project_path) # Get the timestamp of the current file cur_timestamp = os.path.getmtime(fullpath) # Register a FileEvent.MODIF if the file is not excluded # and the file is more recent than the last rsync. if not self.handler.exclude(rel_path) and \ cur_timestamp > register_timestamp: FileEvent(project, FileEvent.MODIF, rel_path).register() def close(self): """ Stops the monitoring on the watched project """ # Stop all monitor instance. for project, monitor in self.monitors.iteritems(): monitor.stop() monitor.join() self.dancer.close() self.dancer.join()