Ejemplo n.º 1
0
    def on_moved(self, event):
        self.logger.debug('MOVED event from %s to %s' %
                          (event.src_path, event.dest_path))

        with lock:
            project = self._get_project(event.src_path)
            src_rel_path = self._verify_exclude(event, event.src_path)
            dest_rel_path = self._verify_exclude(event, event.dest_path)

            if src_rel_path:
                FileEvent(project, FileEvent.DELETE, src_rel_path).register()

            if dest_rel_path:
                FileEvent(project, FileEvent.MODIF, dest_rel_path).register()
Ejemplo n.º 2
0
    def on_created(self, event):
        self.logger.debug('CREATED event %s' % event.src_path)

        with lock:
            project = self._get_project(event.src_path)
            rel_path = self._verify_exclude(event, event.src_path)
            if rel_path:
                FileEvent(project, FileEvent.CREATE, rel_path).register()
Ejemplo n.º 3
0
    def on_deleted(self, event):
        """ Trigered when a file is deleted in the watched project.
        """

        self.logger.debug('DELETED event %s' % event.src_path)

        with lock:
            project = self._get_project(event.src_path)
            rel_path = self._verify_exclude(event, event.src_path)
            if rel_path:
                FileEvent(project, FileEvent.DELETE, rel_path).register()
Ejemplo n.º 4
0
    def _startup_init(self):
        """
        """

        cur_files = []

        self.logger.info("[%s] startup initialization..." % self.project)
        for root, _, files in os.walk(self.project_path):
            for name in files:
                fullpath = join(root, name)
                rel_path = relpath(fullpath, self.project_path)

                # Add the current file to the cur_files list.
                cur_files.append(rel_path)

                # Get the last modification timestamp of the current file.
                cur_timestamp = getmtime(fullpath)

                # Get the last rsync timestamp of the current file.
                register_timestamp = self.index.get(rel_path)

                # If the file is not excluded...
                if not self.exclude_method or not \
                        self.exclude_method(rel_path):
                    # Verify if it's a new file...
                    if register_timestamp is None:
                        self.logger.info("Need to create: %s" % rel_path)
                        FileEvent(self.project, FileEvent.CREATE,
                                  rel_path).register()
                    elif (register_timestamp and cur_timestamp >
                          register_timestamp):
                        self.logger.info("Need to sync: %s" % rel_path)
                        FileEvent(self.project, FileEvent.MODIF,
                                  rel_path).register()

        # Verify if there's no file deleted since the last time.
        for del_file in [x for x in self.index.keys() if x not in cur_files]:
            self.logger.info("Need to delete: %s" % del_file)
            FileEvent(self.project, FileEvent.DELETE, del_file).register()

        self.logger.info("[%s] ready !" % self.project)
Ejemplo n.º 5
0
    def get_files(self):

        files = []

        for element in self.xml.getchildren():
            tag_name = element.tag.split('}', 1)[-1]
            file_event_type = None

            if tag_name == 'file':
                file_event_type = FileEvent.MODIF
            elif tag_name == 'create_file':
                file_event_type = FileEvent.CREATE
            elif tag_name == 'move_file':
                file_event_type = FileEvent.MOVE
            elif tag_name == 'delete_file':
                file_event_type = FileEvent.DELETE

            file_event = FileEvent(self['node'], file_event_type, element.text)
            files.append(file_event)

        return files
Ejemplo n.º 6
0
    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()
Ejemplo n.º 7
0
    def on_modified(self, event):
        """ Triggered when a file is modified in the watched project.
        @param event: the watchdog event
        @raise BaboonException: if cannot retrieve the relative project path
        """

        self.logger.debug('MODIFIED event %s' % event.src_path)

        with lock:
            project = self._get_project(event.src_path)
            rel_path = self._verify_exclude(event, event.src_path)
            if rel_path:
                # Here, we are sure that the rel_path is a file. The check is
                # done if the _verify_exclude method.

                # If the file was a file and is now a directory, we need to
                # delete absolutely the file. Otherwise, the server will not
                # create the directory (OSError).
                if os.path.isdir(event.src_path):
                    self.logger.debug('The file %s is now a directory.' %
                                      rel_path)

                FileEvent(project, FileEvent.MODIF, rel_path).register()