示例#1
0
    def load(self, flow_name, prj_id=None):
        """
        加载流程源文件
        尝试从平台流程数据库和项目数据库中加载流程文件,优先加载项目目录中的流程文件
        :param flow_name: 流程名
        :param prj_id: 项目ID
        :return:
            成功 'ok', FlowSourceObject, 'no error'
            失败 'error', None, reason
        """
        fail_reason_stack = list()

        if prj_id:
            status, project_flow_source, reason = self._try_load_from_project_flow_database(
                prj_id, flow_name)
            if status != api.OK:
                fail_reason_stack.append(reason)

            if project_flow_source:
                return api.return_ok_payload(project_flow_source)

        status, platform_flow_source, reason = self._try_load_from_platform_flow_database(
            flow_name)
        if status != api.OK:
            fail_reason_stack.append(reason)

        if platform_flow_source:
            return api.return_ok_payload(platform_flow_source)

        fail_reason_set = '\n'.join(
            [str(reason) for reason in fail_reason_stack])
        return api.return_error_payload(fail_reason_set)
示例#2
0
    def _link(self, dev_type):
        """
        尝试将系统中的设备链接进来
        :return:
            成功 'ok', self, 'no error'
            失败 'error', None, reason
        """
        status, dev, fail_reason = api.device_get_profile(dev_type)

        if status != api.OK:
            return api.return_warning_payload(fail_reason)

        if dev is None:
            return api.return_warning_payload(
                "类型<{}>对应的设备驱动可能还没有启动!".format(dev_type))

        try:
            vendor = dev['vendor']
            model = dev['model']
            version = dev['version']
        except KeyError:
            return api.return_warning_payload(
                "类型<{}>对应的设备驱动参数内容错误!".format(dev_type))

        supported = self.is_device_supported(dev_type, vendor, model, version)
        if not supported:
            return api.return_warning_payload(
                "类型<{}/{}/{}/{}>对应的设备驱动不受支持!".format(dev_type, vendor, model,
                                                     version))
        else:
            return api.return_ok_payload(self)
示例#3
0
文件: ec.py 项目: bedreamer/plane-ui
def get_EC_device_pair_information():
    info = ["02-环境箱页面"]
    status, pr, reason = api.device_get_profile(dev_type)
    if status != api.OK:
        return api.return_error_payload(info)
    info.append(pr['vendor'])
    info.append(pr['model'])
    info.append(pr['version'])

    return api.return_ok_payload(info)
示例#4
0
    def load_source_from_abs_path(flow_name, full_file_path):
        """加载指定的文件"""
        if not os.path.exists(full_file_path):
            return api.return_warning_payload("流程文件{}({})没有找到!".format(
                flow_name, full_file_path))

        try:
            flow_as_dict_source = flowfile.FlowFileReader(
                full_file_path).as_dict()
        except (xlrd.XLRDError, xlrd.XLDateError):
            return api.return_error_payload("文件格式不符或内容错误!")

        source = FlowSource(flow_as_dict_source, flow_name, full_file_path)
        return api.return_ok_payload(source)
示例#5
0
    def compile(self):
        """
        将流程源文件编译成流程对象
        这里是获取流程对象的唯一接口
        :return:
            成功 'ok', FlowsObject, 'no error'
            失败 'error', None, reason
        """
        # 1. 最基本要求是需要有流程单元
        if not len(self):
            fail_reason = "流程文件没有具体有效的流程单元!"
            return api.return_error_payload(fail_reason)

        # 2. 链接流程单元
        fail_reason_set = list()

        a_list = self.get_flow_name_list()
        b_list = a_list[::]
        b_list.pop(0)
        b_list.extend([None])

        flow_route_net = dict()
        for this_name, next_name in zip(a_list, b_list):
            status, flow_unit, reason = self.compile_flow_as_object(
                this_name, next_name)
            if status != api.OK:
                fail_reason_set.append(reason)
            else:
                flow_route_net[this_name] = flow_unit

        if len(fail_reason_set):
            return api.return_error_payload(fail_reason_set)

        # build the reference net.
        for name in flow_route_net.keys():
            true_name = flow_route_net[name].true_flow
            false_name = flow_route_net[name].false_flow

            if true_name:
                flow_route_net[name].true_flow = flow_route_net[true_name]

            if false_name:
                flow_route_net[name].false_flow = flow_route_net[false_name]

        flow_object = FlowsObject(self, flow_route_net)
        return api.return_ok_payload(flow_object)
示例#6
0
    def compile_flow_as_object(self, name, next_name):
        """
        将字典对象编译为FlowUnitObject
        这一步里面将true_flow, false_flow编译为流程名
        """
        f = self.src['flows'][name]

        if len(f) == 0:
            reason = "流程<{}>是空内容.".format(name)
            return api.return_warning_payload(reason)

        try:
            inset_in = [
                Instruction(stage='switch-in', **ins) for ins in f['inset_in']
            ]
        except KeyError:
            inset_in = list()

        try:
            inset_running = [
                Instruction(stage='running', **ins)
                for ins in f['inset_running']
            ]
        except KeyError:
            inset_running = list()

        try:
            inset_out = [
                Instruction(stage='switch-out', **ins)
                for ins in f['inset_out']
            ]
        except KeyError:
            inset_out = list()

        try:
            conditions = f['conditions']
        except KeyError:
            conditions = list()

        try:
            timeout = f['timeout']
        except KeyError:
            timeout = -1

        auto_name = '$auto'
        try:
            true_flow = f['true']
        except KeyError:
            true_flow = next_name

        if true_flow == auto_name:
            true_flow = next_name

        try:
            false_flow = f['false']
        except KeyError:
            false_flow = name

        if false_flow == auto_name:
            false_flow = name

        flow_names_list = self.get_flow_name_list()
        if true_flow and true_flow not in flow_names_list:
            reason = "流程<{}>的true分支地址<{}>不可达.".format(name, true_flow)
            return api.return_warning_payload(reason)

        if true_flow and false_flow not in flow_names_list:
            reason = "流程<{}>的false分支地址<{}>不可达.".format(name, false_flow)
            return api.return_warning_payload(reason)

        flow_unit = FlowUnitObject(name, inset_in, inset_running, inset_out,
                                   conditions, timeout, true_flow, false_flow)
        return api.return_ok_payload(flow_unit)
示例#7
0
 def link(self):
     return api.return_ok_payload(None)