当前位置: 首页>>代码示例>>Python>>正文


Python ValidationException.append方法代码示例

本文整理汇总了Python中task.ValidationException.append方法的典型用法代码示例。如果您正苦于以下问题:Python ValidationException.append方法的具体用法?Python ValidationException.append怎么用?Python ValidationException.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在task.ValidationException的用法示例。


在下文中一共展示了ValidationException.append方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: verify

# 需要导入模块: from task import ValidationException [as 别名]
# 或者: from task.ValidationException import append [as 别名]
    def verify(self, id, updated_fields, force=False):

        ntp = self.datastore.get_by_id('ntpservers', id)
        if ntp is None:
            raise VerifyException(errno.ENOENT, 'NTP Server with given ID does not exist')

        errors = ValidationException()

        try:
            if 'address' in updated_fields:
                system('ntpdate', '-q', updated_fields['address'])
        except SubprocessException:
            if not force:
                errors.append((
                    'address',
                    errno.EINVAL,
                    'Server could not be reached. Check "Force" to continue regardless.'))

        minpoll = updated_fields.get('minpoll', ntp.get('minpoll'))
        maxpoll = updated_fields.get('maxpoll', ntp.get('maxpoll'))

        if minpoll is not None and maxpoll is not None and not maxpoll > minpoll:
            errors.append(('maxpoll', errno.EINVAL, 'Max Poll should be higher than Min Poll'))

        if errors:
            raise ValidationException(errors)

        return ['system']
开发者ID:650elx,项目名称:middleware,代码行数:30,代码来源:NTPPlugin.py

示例2: verify

# 需要导入模块: from task import ValidationException [as 别名]
# 或者: from task.ValidationException import append [as 别名]
    def verify(self, params):
        errors = ValidationException()

        if self.datastore.get_one('users', ('username', '=', params.get('user'))) is None:
            raise VerifyException(
                errno.ENOENT, 'User {0} does not exist'.format(params.get('user'))
            )

        path = params.get('path')
        rmode = params.get('rsync_mode')
        remote_path = params.get('remote_path')
        remote_host = params.get('remote_host')
        remote_module = params.get('remote_module')

        if path in [None, ''] or path.isspace():
            errors.append(('path', errno.EINVAL, 'The Path is required'))
        elif not os.path.exists(path):
            raise VerifyException(
                errno.ENOENT,
                "The specified path: '{0}'' does not exist".format(params.get('path'))
            )
        if (
            params.get('remote_host') in ['127.0.0.1', 'localhost'] and
            rmode == 'SSH' and
            remote_path is not None and
            not os.path.exists(remote_path)
           ):
            raise VerifyException(
                errno.ENOENT,
                "The specified path: '{0}'' does not exist".format(remote_path)
            )

        if rmode == 'SSH' and (remote_path in [None, ''] or remote_path.isspace()):
            errors.append(('remote_path', errno.EINVAL, 'The Remote Path is required'))
        elif rmode == 'MODULE' and (remote_module in [None, ''] or remote_module.isspace()):
            errors.append(('remote_module', errno.EINVAL, 'The Remote Module is required'))

        if remote_host in [None, ''] or remote_host.isspace():
            errors.append(('remote_host', errno.EINVAL, 'A Remote Host needs to be specified'))
        if errors:
            raise ValidationException(errors)

        return []
开发者ID:jatinder-kumar-calsoft,项目名称:middleware,代码行数:45,代码来源:RsyncdPlugin.py


注:本文中的task.ValidationException.append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。