Exemple #1
0
    def _on_rsync_stanza(self, iq):
        """ Called when a Rsync stanza is received. This handler creates a
        new RsyncTask if permissions are good.
        """

        self.logger.info('Received a rsync stanza.')

        # Get the useful data.
        node = iq['rsync']['node']
        sid = iq['rsync']['sid']
        rid = iq['rsync']['rid']
        files = iq['rsync']['files']
        sfrom = iq['from']
        project_path = join(self.working_dir, node, sfrom.bare)

        # Verify if the user is a subscriber/owner of the node.
        is_subscribed = self._verify_subscription(iq, sfrom.bare, node)
        if not is_subscribed:
            eventbus.fire('rsync-finished-failure', rid=rid)
            return

        # The future reply iq.
        reply = iq.reply()

        # Create the new RsyncTask.
        from task import RsyncTask
        rsync_task = RsyncTask(sid, rid, sfrom, node, project_path, files)
        dispatcher.put(node, rsync_task)

        # Register the current rsync_task in the pending_rsyncs dict.
        self.pending_rsyncs[rid] = rsync_task

        # Reply to the IQ
        reply['rsync']
        reply.send()
Exemple #2
0
    def _on_merge_stanza(self, iq):
        """ Called when a MergeVerification stanza is received. This handler
        creates a new MergeTask if permissions are good.
        """

        # Get the useful data.
        sfrom = iq['from'].bare
        node = iq['merge']['node']
        project_path = join(self.working_dir, node, sfrom)

        # Verify if the user is a subscriber/owner of the node.
        is_subscribed = self._verify_subscription(iq, sfrom, node)
        if not is_subscribed:
            eventbus.fire("rsync-finished-failure")
            return

        # Verify if the server-side project is a git repository.
        is_git_repo = self._verify_git_repository(iq, node, project_path)
        if not is_git_repo:
            return

        # The future reply iq.
        reply = iq.reply()

        # Prepare the merge verification with this data.
        from task import MergeTask
        dispatcher.put(node, MergeTask(node, sfrom))

        # Reply to the request.
        reply.send()
Exemple #3
0
    def _on_failed_auth(self, event):
        """ Called when authentication failed.
        """

        self.logger.error("Authentication failed.")
        eventbus.fire('failed-auth')
        self.close()
Exemple #4
0
    def _on_git_init_stanza(self, iq):
        """ Called when a GitInit stanza is received. This handler creates a
        new GitInitTask if permissions are good.
        """

        self.logger.info("Received a git init stanza.")

        # Get the useful data.
        node = iq['git-init']['node']
        url = iq['git-init']['url']
        sfrom = iq['from'].bare

        # Ensure permissions.
        is_subscribed = self._verify_subscription(iq, sfrom, node)
        if not is_subscribed:
            eventbus.fire("rsync-finished-failure")
            return

        # Create a new GitInitTask
        from baboon.baboond.task import GitInitTask
        git_init_task = GitInitTask(node, url, sfrom)

        # Register the BaboonId of this GitInitTask in the
        # self.pending_git_init_tasks dict.
        self.pending_git_init_tasks[git_init_task.bid] = iq

        # Add the GitInitTask to the list of tasks to execute.
        dispatcher.put(node, git_init_task)
Exemple #5
0
    def _on_merge_stanza(self, iq):
        """ Called when a MergeVerification stanza is received. This handler
        creates a new MergeTask if permissions are good.
        """

        # Get the useful data.
        sfrom = iq['from'].bare
        node = iq['merge']['node']
        project_path = join(self.working_dir, node, sfrom)

        # Verify if the user is a subscriber/owner of the node.
        is_subscribed = self._verify_subscription(iq, sfrom, node)
        if not is_subscribed:
            eventbus.fire("rsync-finished-failure")
            return

        # Verify if the server-side project is a git repository.
        is_git_repo = self._verify_git_repository(iq, node, project_path)
        if not is_git_repo:
            return

        # The future reply iq.
        reply = iq.reply()

        # Prepare the merge verification with this data.
        from task import MergeTask
        dispatcher.put(node, MergeTask(node, sfrom))

        # Reply to the request.
        reply.send()
Exemple #6
0
    def _on_failed_auth(self, event):
        """ Called when authentication failed.
        """

        self.logger.error("Authentication failed.")
        eventbus.fire('failed-auth')
        self.close()
Exemple #7
0
    def _pubsub_event(self, msg):
        """ Called when a pubsub event is received.
        """

        if msg['type'] in ('normal', 'headline'):
            self.logger.debug("Received pubsub item(s): \n%s" %
                              msg['pubsub_event'])

            items = msg['pubsub_event']['items']['substanzas']
            for item in items:
                notif_msg = ""
                if isinstance(item, EventItem):
                    self.logger.info(item['payload'].get('status'))
                    notif_msg += item['payload'].get('status')

                    for err_f in item['payload']:
                        if err_f.text:
                            err = "> %s" % err_f.text
                            self.logger.warning(err)
                            notif_msg = "%s\n%s" % (notif_msg, err)
                    if item['payload'].get('type') == 'error':
                        eventbus.fire('conflict-result', notif_msg)
        else:
            self.logger.debug("Received pubsub event: \n%s" %
                              msg['pubsub_event'])
Exemple #8
0
    def _on_rsync_stanza(self, iq):
        """ Called when a Rsync stanza is received. This handler creates a
        new RsyncTask if permissions are good.
        """

        self.logger.info('Received a rsync stanza.')

        # Get the useful data.
        node = iq['rsync']['node']
        sid = iq['rsync']['sid']
        rid = iq['rsync']['rid']
        files = iq['rsync']['files']
        sfrom = iq['from']
        project_path = join(self.working_dir, node, sfrom.bare)

        # Verify if the user is a subscriber/owner of the node.
        is_subscribed = self._verify_subscription(iq, sfrom.bare, node)
        if not is_subscribed:
            eventbus.fire('rsync-finished-failure', rid=rid)
            return

        # The future reply iq.
        reply = iq.reply()

        # Create the new RsyncTask.
        from task import RsyncTask
        rsync_task = RsyncTask(sid, rid, sfrom, node, project_path, files)
        dispatcher.put(node, rsync_task)

        # Register the current rsync_task in the pending_rsyncs dict.
        self.pending_rsyncs[rid] = rsync_task

        # Reply to the IQ
        reply['rsync']
        reply.send()
Exemple #9
0
    def _on_git_init_stanza(self, iq):
        """ Called when a GitInit stanza is received. This handler creates a
        new GitInitTask if permissions are good.
        """

        self.logger.info("Received a git init stanza.")

        # Get the useful data.
        node = iq['git-init']['node']
        url = iq['git-init']['url']
        sfrom = iq['from'].bare

        # Ensure permissions.
        is_subscribed = self._verify_subscription(iq, sfrom, node)
        if not is_subscribed:
            eventbus.fire("rsync-finished-failure")
            return

        # Create a new GitInitTask
        from baboon.baboond.task import GitInitTask
        git_init_task = GitInitTask(node, url, sfrom)

        # Register the BaboonId of this GitInitTask in the
        # self.pending_git_init_tasks dict.
        self.pending_git_init_tasks[git_init_task.bid] = iq

        # Add the GitInitTask to the list of tasks to execute.
        dispatcher.put(node, git_init_task)
Exemple #10
0
    def _on_new_rsync(self, project, files, **kwargs):
        """ Called when a new rsync needs to be started.
        """

        self.connected.wait()

        self.rsync(project, files=files)
        eventbus.fire('rsync-finished-success', project, files)
Exemple #11
0
    def _on_new_rsync(self, project, files, **kwargs):
        """ Called when a new rsync needs to be started.
        """

        self.connected.wait()

        self.rsync(project, files=files)
        eventbus.fire('rsync-finished-success', project, files)
Exemple #12
0
    def run(self):
        self.logger.debug('A new git init task has been started.')

        # If the project directory already exists, delete it.
        if os.path.exists(self.user_cwd):
            shutil.rmtree(self.user_cwd)

        create_missing_dirs(self.project_cwd, isfile=False)
        ret_code, output, _ = exec_cmd('git clone %s %s' % (
            self.url, self.jid), self.project_cwd)
        if not ret_code:
            self.logger.debug('Git init task finished.')
            eventbus.fire('git-init-success', self.bid)
        else:
            eventbus.fire('git-init-failure', self.bid,
                          "Cannot initialize the git repository.")
Exemple #13
0
    def run(self):
        self.logger.debug('A new git init task has been started.')

        # If the project directory already exists, delete it.
        if os.path.exists(self.user_cwd):
            shutil.rmtree(self.user_cwd)

        create_missing_dirs(self.project_cwd, isfile=False)
        ret_code, output, _ = exec_cmd(
            'git clone %s %s' % (self.url, self.jid), self.project_cwd)
        if not ret_code:
            self.logger.debug('Git init task finished.')
            eventbus.fire('git-init-success', self.bid)
        else:
            eventbus.fire('git-init-failure', self.bid,
                          "Cannot initialize the git repository.")
Exemple #14
0
    def run(self):
        """ Runs the thread.
        """

        while not self.stop:
            # Sleeps during sleeptime secs.
            sleep(self.sleeptime)

            with lock:
                for project, files in pending.iteritems():
                    try:
                        eventbus.fire('new-rsync', project=project,
                                      files=files)

                    except BaboonException as e:
                        self.logger.error(e)

                # Clears the pending dict.
                pending.clear()
Exemple #15
0
    def run(self):

        self.logger.debug('RsyncTask %s started' % self.sid)

        # Lock the repository with a .baboon.lock file.
        lock_file = os.path.join(self.project_path, '.baboon.lock')
        create_missing_dirs(lock_file)
        open(lock_file, 'w').close()

        for f in self.files:
            # Verify if the file can be written in the self.project_path.
            path_valid = self._verify_paths(f)
            if not path_valid:
                self.logger.error("The file path cannot be written in %s." %
                                  self.project)
                eventbus.fire('rsync-finished-failure', rid=self.rid)
                return

            if f.event_type == FileEvent.CREATE:
                self.logger.debug('[%s] - Need to create %s.' %
                                 (self.project_path, f.src_path))
                self._create_file(f.src_path)
            elif f.event_type == FileEvent.MODIF:
                self.logger.debug('[%s] - Need to sync %s.' %
                                 (self.project_path, f.src_path))
                new_hash = self._get_hash(f.src_path)
                self._send_hash(new_hash)
            elif f.event_type == FileEvent.DELETE:
                self.logger.debug('[%s] - Need to delete %s.' %
                                 (self.project_path, f.src_path))
                self._delete_file(f.src_path)
            elif f.event_type == FileEvent.MOVE:
                self.logger.debug('[%s] - Need to move %s to %s.' %
                                 (self.project_path, f.src_path, f.dest_path))
                self._move_file(f.src_path, f.dest_path)

        # Remove the .baboon.lock file.
        os.remove(lock_file)

        # Fire the rsync-finished-success event.
        eventbus.fire('rsync-finished-success', rid=self.rid)

        self.logger.debug('Rsync task %s finished', self.sid)
Exemple #16
0
    def run(self):

        self.logger.debug('RsyncTask %s started' % self.sid)

        # Lock the repository with a .baboon.lock file.
        lock_file = os.path.join(self.project_path, '.baboon.lock')
        create_missing_dirs(lock_file)
        open(lock_file, 'w').close()

        for f in self.files:
            # Verify if the file can be written in the self.project_path.
            path_valid = self._verify_paths(f)
            if not path_valid:
                self.logger.error("The file path cannot be written in %s." %
                                  self.project)
                eventbus.fire('rsync-finished-failure', rid=self.rid)
                return

            if f.event_type == FileEvent.CREATE:
                self.logger.debug('[%s] - Need to create %s.' %
                                  (self.project_path, f.src_path))
                self._create_file(f.src_path)
            elif f.event_type == FileEvent.MODIF:
                self.logger.debug('[%s] - Need to sync %s.' %
                                  (self.project_path, f.src_path))
                new_hash = self._get_hash(f.src_path)
                self._send_hash(new_hash)
            elif f.event_type == FileEvent.DELETE:
                self.logger.debug('[%s] - Need to delete %s.' %
                                  (self.project_path, f.src_path))
                self._delete_file(f.src_path)
            elif f.event_type == FileEvent.MOVE:
                self.logger.debug('[%s] - Need to move %s to %s.' %
                                  (self.project_path, f.src_path, f.dest_path))
                self._move_file(f.src_path, f.dest_path)

        # Remove the .baboon.lock file.
        os.remove(lock_file)

        # Fire the rsync-finished-success event.
        eventbus.fire('rsync-finished-success', rid=self.rid)

        self.logger.debug('Rsync task %s finished', self.sid)
Exemple #17
0
    def run(self):
        """ Runs the thread.
        """

        while not self.stop:
            # Sleeps during sleeptime secs.
            sleep(self.sleeptime)

            with lock:
                for project, files in pending.iteritems():
                    try:
                        eventbus.fire('new-rsync',
                                      project=project,
                                      files=files)

                    except BaboonException as e:
                        self.logger.error(e)

                # Clears the pending dict.
                pending.clear()