示例#1
0
    def build(self, project, process_data):
        Logger.i('Building repository: {0}...'.format(self.get_name()))

        sys_path = list(sys.path)
        original_cwd = os.getcwd()

        try:
            sys.path.insert(0, self.get_temp_dir())

            target_module = importlib.import_module(
                Constants.VENDOR_MODULE_NAME)
            do_build = getattr(target_module, 'do_build')

            do_build(params={
                'project': project,
                'process_data': process_data,
            })

            del sys.modules[Constants.VENDOR_MODULE_NAME]
            del target_module
            del do_build

            Logger.i('Build finished for repository: {0}'.format(
                self.get_name()))
        except Exception as e:
            Logger.e(
                "Error while call 'do_build' on repository {0}: {1}".format(
                    self.get_name(), e.message))
            raise

        sys.path = sys_path
        os.chdir(original_cwd)
示例#2
0
 def test_error(self):
     Logger.e('test_error')
     self.assertTrue(True)
示例#3
0
    def execute_command(self, target_command, target_name):
        from ezored.models.logger import Logger
        from ezored.models.project import Project
        import importlib
        import sys

        project = Project.create_from_project_file()

        if target_name:
            Logger.i('Execute command "{0}" only on target "{1}"'.format(
                target_command, target_name))
        else:
            Logger.i(
                'Execute command "{0}" on all targets'.format(target_command))

        target_found = False
        total_targets = len(project.targets)

        if total_targets > 0:
            for target in project.targets:
                process_data = ProcessData()
                process_data.reset()
                process_data.project_name = project.get_config_value('name')

                can_build = False

                if not target_name:
                    can_build = True
                elif target.get_name() == target_name:
                    can_build = True

                if can_build:
                    Logger.d(
                        'Getting target data by target name "{0}"...'.format(
                            target.get_name()))
                    target_found = True

                    # targets need be deleted to be always fresh with target data from dependencies
                    target.remove()

                    # build the target repository after download
                    target.prepare_from_process_data(process_data)
                    target.repository.download()
                    target.repository.build(project=project,
                                            process_data=process_data)

                    # get all target data from project dependencies
                    target_data = TargetData()
                    target_data.project_home = target.repository.get_vendor_dir(
                    )
                    target_data.project_config = project.config

                    for dependency in project.dependencies:
                        dependency.prepare_from_process_data(process_data)

                        new_target_data = dependency.get_target_data_by_target_name_and_parse(
                            target.get_name(), process_data)

                        target_data.merge(new_target_data)

                    # back to target data
                    target.prepare_from_process_data(process_data)

                    # process target data and execute required command
                    target_data_file = target.repository.load_target_data_file(
                    )

                    if 'target' in target_data_file:
                        target_project_data = target_data_file['target']

                        # target tasks
                        if 'tasks' in target_project_data:
                            target_tasks_data = target_project_data['tasks']

                            for target_task_data in target_tasks_data:
                                task = Task.from_dict(target_task_data)
                                task.parse(process_data)
                                target_data.tasks.append(task)

                        # run all tasks
                        Task.run_all_tasks(
                            tasks=target_data.tasks,
                            process_data=process_data,
                            template_data={'target': target_data},
                            working_dir=target.repository.get_vendor_dir())

                        # execute command on target
                        Logger.i('Executing command "{0}" on target "{1}"...'.
                                 format(target_command, target.get_name()))

                        sys_path = list(sys.path)
                        original_cwd = os.getcwd()

                        try:
                            sys.path.insert(0,
                                            target.repository.get_vendor_dir())

                            target_module = importlib.import_module(
                                Constants.TARGET_MODULE_NAME)
                            command = getattr(target_module,
                                              'do_' + target_command)

                            command(
                                params={
                                    'project': project,
                                    'target': target,
                                    'target_data': target_data,
                                    'process_data': process_data,
                                })

                            del sys.modules[Constants.TARGET_MODULE_NAME]
                            del target_module
                            del command

                            Logger.i('Command "{0}" finished for target "{1}"'.
                                     format(target_command, target.get_name()))
                        except Exception as e:
                            Logger.e(
                                'Error while call "{0}" on target "{1}": {2}'.
                                format(target_command, target.get_name(),
                                       e.message))
                            raise

                        sys.path = sys_path
                        os.chdir(original_cwd)

            if not target_found:
                Logger.f('Target not found: {0}'.format(target_name))
        else:
            Logger.i('Your project does not have targets')