示例#1
0
    def runImportStepFromProfile(self,
                                 profile_id,
                                 step_id,
                                 run_dependencies=True,
                                 purge_old=None):
        """ See ISetupTool.
        """
        context = self._getImportContext(profile_id, purge_old)

        self.applyContext(context)

        info = self.getImportStepMetadata(step_id)

        if info is None:
            generic_logger.error(
                "No such import step: '%s' Maybe you meant one of %s", step_id,
                str(self.listImportSteps()))
            raise ValueError('No such import step: %s' % step_id)

        dependencies = info.get('dependencies', ())

        messages = {}
        steps = []

        if run_dependencies:
            for dependency in dependencies:
                if dependency not in steps:
                    steps.append(dependency)
        steps.append(step_id)

        full_import = (set(steps) == set(self.getSortedImportSteps()))
        event.notify(
            BeforeProfileImportEvent(self, profile_id, steps, full_import))

        for step in steps:
            message = self._doRunImportStep(step, context)
            messages[step] = message or ''

        message_list = filter(None, [message])
        message_list.extend(['%s: %s' % x[1:] for x in context.listNotes()])
        messages[step_id] = '\n'.join(message_list)

        event.notify(ProfileImportedEvent(self, profile_id, steps,
                                          full_import))

        return {'steps': steps, 'messages': messages}
示例#2
0
        results = []

        detect_steps = steps is None

        for profile_id in chain:
            context = self._getImportContext(profile_id, purge_old, archive)
            self.applyContext(context)

            if detect_steps:
                steps = self.getSortedImportSteps()

            messages = {}

            event.notify(
                BeforeProfileImportEvent(self, profile_id, steps, True))
            for step in steps:
                if blacklisted_steps and step in blacklisted_steps:
                    message = 'step skipped'
                else:
                    message = self._doRunImportStep(step, context)
                message_list = filter(None, [message])
                message_list.extend(
                    ['%s: %s' % x[1:] for x in context.listNotes()])
                messages[step] = '\n'.join(message_list)
                context.clearNotes()

            event.notify(ProfileImportedEvent(self, profile_id, steps, True))

            results.append({'steps': steps, 'messages': messages})