• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python gettextutils._函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中murano.openstack.common.gettextutils._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: configure

    def configure(self, request, environment_id):
        LOG.debug('Session:Configure <EnvId: {0}>'.format(environment_id))

        unit = db_session.get_session()
        environment = unit.query(models.Environment).get(environment_id)

        if environment is None:
            msg = _('Environment <EnvId {0}>'
                    ' is not found').format(environment_id)
            LOG.error(msg)
            raise exc.HTTPNotFound(explanation=msg)

        if environment.tenant_id != request.context.tenant:
            msg = _('User is not authorized to access '
                    'this tenant resources.')
            LOG.error(msg)
            raise exc.HTTPUnauthorized(explanation=msg)

        # no new session can be opened if environment has deploying status
        env_status = envs.EnvironmentServices.get_status(environment_id)
        if env_status in (states.EnvironmentStatus.DEPLOYING,
                          states.EnvironmentStatus.DELETING):
            msg = _('Could not open session for environment <EnvId: {0}>,'
                    'environment has deploying status.').format(environment_id)
            LOG.error(msg)
            raise exc.HTTPForbidden(explanation=msg)

        user_id = request.context.user
        session = sessions.SessionServices.create(environment_id, user_id)

        return session.to_dict()
开发者ID:OndrejVojta,项目名称:murano,代码行数:31,代码来源:sessions.py


示例2: configure

    def configure(self, request, environment_id):
        LOG.debug("Session:Configure <EnvId: {0}>".format(environment_id))

        unit = db_session.get_session()
        environment = unit.query(models.Environment).get(environment_id)

        if environment is None:
            LOG.info(_("Environment <EnvId {0}> " "is not found").format(environment_id))
            raise exc.HTTPNotFound

        if environment.tenant_id != request.context.tenant:
            LOG.info(_("User is not authorized to access " "this tenant resources."))
            raise exc.HTTPUnauthorized

        # no new session can be opened if environment has deploying status
        env_status = envs.EnvironmentServices.get_status(environment_id)
        if env_status == envs.EnvironmentStatus.deploying:
            LOG.info(
                _("Could not open session for environment <EnvId: {0}>," "environment has deploying " "status.").format(
                    environment_id
                )
            )
            raise exc.HTTPForbidden()

        user_id = request.context.user
        session = sessions.SessionServices.create(environment_id, user_id)

        return session.to_dict()
开发者ID:nastya-kuz,项目名称:murano,代码行数:28,代码来源:sessions.py


示例3: _validate_change

    def _validate_change(self, change):
        change_path = change['path'][0]
        change_op = change['op']
        allowed_methods = self.allowed_operations.get(change_path)

        if not allowed_methods:
            msg = _("Attribute '{0}' is invalid").format(change_path)
            raise webob.exc.HTTPForbidden(explanation=unicode(msg))

        if change_op not in allowed_methods:
            msg = _("Method '{method}' is not allowed for a path with name "
                    "'{name}'. Allowed operations are: '{ops}'").format(
                    method=change_op,
                    name=change_path,
                    ops=', '.join(allowed_methods))

            raise webob.exc.HTTPForbidden(explanation=unicode(msg))

        property_to_update = {change_path: change['value']}

        try:
            jsonschema.validate(property_to_update, schemas.PKG_UPDATE_SCHEMA)
        except jsonschema.ValidationError as e:
            LOG.exception(e)
            raise webob.exc.HTTPBadRequest(explanation=e.message)
开发者ID:ativelkov,项目名称:murano-api,代码行数:25,代码来源:wsgi.py


示例4: ssh_execute

def ssh_execute(ssh, cmd, process_input=None,
                addl_env=None, check_exit_code=True):
    LOG.debug('Running cmd (SSH): %s', cmd)
    if addl_env:
        raise InvalidArgumentError(_('Environment not supported over SSH'))

    if process_input:
        # This is (probably) fixable if we need it...
        raise InvalidArgumentError(_('process_input not supported over SSH'))

    stdin_stream, stdout_stream, stderr_stream = ssh.exec_command(cmd)
    channel = stdout_stream.channel

    # NOTE(justinsb): This seems suspicious...
    # ...other SSH clients have buffering issues with this approach
    stdout = stdout_stream.read()
    stderr = stderr_stream.read()
    stdin_stream.close()

    exit_status = channel.recv_exit_status()

    # exit_status == -1 if no exit code was returned
    if exit_status != -1:
        LOG.debug('Result was %s' % exit_status)
        if check_exit_code and exit_status != 0:
            raise ProcessExecutionError(exit_code=exit_status,
                                        stdout=stdout,
                                        stderr=stderr,
                                        cmd=cmd)

    return (stdout, stderr)
开发者ID:alex-docker,项目名称:murano,代码行数:31,代码来源:processutils.py


示例5: show

    def show(self, request, environment_id, session_id):
        LOG.debug("Session:Show <SessionId: {0}>".format(session_id))

        unit = db_session.get_session()
        session = unit.query(models.Session).get(session_id)

        if session is None:
            LOG.error(_("Session <SessionId {0}> " "is not found").format(session_id))
            raise exc.HTTPNotFound()

        if session.environment_id != environment_id:
            LOG.error(
                _("Session <SessionId {0}> is not tied with Environment " "<EnvId {1}>").format(
                    session_id, environment_id
                )
            )
            raise exc.HTTPNotFound()

        user_id = request.context.user
        if session.user_id != user_id:
            LOG.error(
                _("User <UserId {0}> is not authorized to access session" "<SessionId {1}>.").format(
                    user_id, session_id
                )
            )
            raise exc.HTTPUnauthorized()

        if not sessions.SessionServices.validate(session):
            LOG.error(_("Session <SessionId {0}> " "is invalid").format(session_id))
            raise exc.HTTPForbidden()

        return session.to_dict()
开发者ID:nastya-kuz,项目名称:murano,代码行数:32,代码来源:sessions.py


示例6: deploy

    def deploy(self, request, environment_id, session_id):
        LOG.debug("Session:Deploy <SessionId: {0}>".format(session_id))

        unit = db_session.get_session()
        session = unit.query(models.Session).get(session_id)

        if session is None:
            LOG.error(_("Session <SessionId {0}> " "is not found").format(session_id))
            raise exc.HTTPNotFound()

        if session.environment_id != environment_id:
            LOG.error(
                _("Session <SessionId {0}> is not tied with Environment " "<EnvId {1}>").format(
                    session_id, environment_id
                )
            )
            raise exc.HTTPNotFound()

        if not sessions.SessionServices.validate(session):
            LOG.error(_("Session <SessionId {0}> " "is invalid").format(session_id))
            raise exc.HTTPForbidden()

        if session.state != sessions.SessionState.open:
            LOG.error(
                _("Session <SessionId {0}> is already deployed or " "deployment is in progress").format(session_id)
            )
            raise exc.HTTPForbidden()

        sessions.SessionServices.deploy(session, unit, request.context.auth_token)
开发者ID:nastya-kuz,项目名称:murano,代码行数:29,代码来源:sessions.py


示例7: update

    def update(self, request, environment_id, body):
        LOG.debug('Environments:Update <Id: {0}, '
                  'Body: {1}>'.format(environment_id, body))
        target = {"environment_id": environment_id}
        policy.check('update_environment', request.context, target)

        session = db_session.get_session()
        environment = session.query(models.Environment).get(environment_id)

        if environment is None:
            LOG.info(_('Environment <EnvId {0}> is not '
                       'found').format(environment_id))
            raise exc.HTTPNotFound

        if environment.tenant_id != request.context.tenant:
            LOG.info(_('User is not authorized to access '
                       'this tenant resources.'))
            raise exc.HTTPUnauthorized

        LOG.debug('ENV NAME: {0}>'.format(body['name']))
        if VALID_NAME_REGEX.match(str(body['name'])):
            environment.update(body)
            environment.save(session)
        else:
            msg = _('Environment name must contain only alphanumeric '
                    'or "_-." characters, must start with alpha')
            LOG.exception(msg)
            raise exc.HTTPClientError(msg)

        return environment.to_dict()
开发者ID:alex-docker,项目名称:murano,代码行数:30,代码来源:environments.py


示例8: show

    def show(self, request, environment_id):
        LOG.debug('Environments:Show <Id: {0}>'.format(environment_id))
        target = {"environment_id": environment_id}
        policy.check('show_environment', request.context, target)

        session = db_session.get_session()
        environment = session.query(models.Environment).get(environment_id)

        if environment is None:
            LOG.info(_('Environment <EnvId {0}> is not found').format(
                environment_id))
            raise exc.HTTPNotFound

        if environment.tenant_id != request.context.tenant:
            LOG.info(_('User is not authorized to access '
                       'this tenant resources.'))
            raise exc.HTTPUnauthorized

        env = environment.to_dict()
        env['status'] = envs.EnvironmentServices.get_status(env['id'])

        session_id = None
        if hasattr(request, 'context') and request.context.session:
            session_id = request.context.session

        #add services to env
        get_data = core_services.CoreServices.get_data
        env['services'] = get_data(environment_id, '/services', session_id)

        return env
开发者ID:alex-docker,项目名称:murano,代码行数:30,代码来源:environments.py


示例9: delete

    def delete(self, request, environment_id, session_id):
        LOG.debug('Session:Delete <SessionId: {0}>'.format(session_id))

        unit = db_session.get_session()
        session = unit.query(models.Session).get(session_id)

        self._check_session(environment_id, session, session_id)

        user_id = request.context.user
        if session.user_id != user_id:
            msg = _('User <UserId {0}> is not authorized to access session'
                    '<SessionId {1}>.').format(user_id, session_id)
            LOG.error(msg)
            raise exc.HTTPUnauthorized(explanation=msg)

        if session.state == states.SessionState.DEPLOYING:
            msg = _('Session <SessionId: {0}> is in deploying state and '
                    'could not be deleted').format(session_id)
            LOG.error(msg)
            raise exc.HTTPForbidden(explanation=msg)

        with unit.begin():
            unit.delete(session)

        return None
开发者ID:OndrejVojta,项目名称:murano,代码行数:25,代码来源:sessions.py


示例10: __inner

    def __inner(self, request, *args, **kwargs):
        if hasattr(request, 'context') and not request.context.session:
            LOG.info(_('Session is required for this call'))
            raise exc.HTTPForbidden()

        session_id = request.context.session

        unit = db_session.get_session()
        session = unit.query(models.Session).get(session_id)

        if session is None:
            LOG.info(_('Session <SessionId {0}> '
                       'is not found').format(session_id))
            raise exc.HTTPForbidden()

        if not sessions.SessionServices.validate(session):
            LOG.info(_('Session <SessionId {0}> '
                       'is invalid').format(session_id))
            raise exc.HTTPForbidden()

        if session.state == states.SessionState.DEPLOYING:
            LOG.info(_('Session <SessionId {0}> is already in '
                       'deployment state').format(session_id))
            raise exc.HTTPForbidden()
        return func(self, request, *args, **kwargs)
开发者ID:alex-docker,项目名称:murano,代码行数:25,代码来源:utils.py


示例11: _from_json

 def _from_json(self, datastring):
     value = datastring
     try:
         LOG.debug(_("Trying deserialize '{0}' to json".format(datastring)))
         value = jsonutils.loads(datastring)
     except ValueError:
         LOG.debug(_("Unable deserialize to json, using raw text"))
     return value
开发者ID:ativelkov,项目名称:murano-api,代码行数:8,代码来源:wsgi.py


示例12: verify_and_get_env

def verify_and_get_env(db_session, environment_id, request):
    environment = db_session.query(models.Environment).get(environment_id)
    if not environment:
        LOG.info(_('Environment with id {0} not found').format(environment_id))
        raise exc.HTTPNotFound

    if environment.tenant_id != request.context.tenant:
        LOG.info(_('User is not authorized to access this tenant resources.'))
        raise exc.HTTPUnauthorized
    return environment
开发者ID:alex-docker,项目名称:murano,代码行数:10,代码来源:deployments.py


示例13: _check_session

    def _check_session(self, environment_id, session, session_id):
        if session is None:
            msg = _('Session <SessionId {0}> is not found').format(session_id)
            LOG.error(msg)
            raise exc.HTTPNotFound(explanation=msg)

        if session.environment_id != environment_id:
            msg = _('Session <SessionId {0}> is not tied with Environment '
                    '<EnvId {1}>').format(session_id, environment_id)
            LOG.error(msg)
            raise exc.HTTPNotFound(explanation=msg)
开发者ID:OndrejVojta,项目名称:murano,代码行数:11,代码来源:sessions.py


示例14: upload

    def upload(self, req, body=None):
        """Upload new file archive for the new package
           together with package metadata.
        """
        policy.check("upload_package", req.context)

        _check_content_type(req, 'multipart/form-data')
        file_obj, package_meta = _validate_body(body)
        if package_meta:
            try:
                jsonschema.validate(package_meta, schemas.PKG_UPLOAD_SCHEMA)
            except jsonschema.ValidationError as e:
                LOG.exception(e)
                raise exc.HTTPBadRequest(explanation=e.message)
        else:
            package_meta = {}

        with tempfile.NamedTemporaryFile(delete=False) as tempf:
            LOG.debug("Storing package archive in a temporary file")
            content = file_obj.file.read()
            if not content:
                msg = _("Uploading file can't be empty")
                LOG.error(msg)
                raise exc.HTTPBadRequest(msg)
            tempf.write(content)
            package_meta['archive'] = content
        try:
            pkg_to_upload = load_utils.load_from_file(
                tempf.name, target_dir=None, drop_dir=True)
        except pkg_exc.PackageLoadError as e:
            LOG.exception(e)
            raise exc.HTTPBadRequest(e)
        finally:
            LOG.debug("Deleting package archive temporary file")
            os.remove(tempf.name)

        # extend dictionary for update db
        for k, v in PKG_PARAMS_MAP.iteritems():
            if hasattr(pkg_to_upload, k):
                package_meta[v] = getattr(pkg_to_upload, k)

        if req.params.get('is_public', '').lower() == 'true':
            policy.check('publicize_image', req.context)
            package_meta['is_public'] = True

        try:
            package = db_api.package_upload(package_meta, req.context.tenant)
        except db_exc.DBDuplicateEntry:
            msg = _('Package with specified full name is already registered')
            LOG.exception(msg)
            raise exc.HTTPServerError(msg)
        return package.to_dict()
开发者ID:OndrejVojta,项目名称:murano,代码行数:52,代码来源:catalog.py


示例15: verify_and_get_deployment

def verify_and_get_deployment(db_session, environment_id, deployment_id):
    deployment = db_session.query(models.Task).get(deployment_id)
    if not deployment:
        LOG.info(_('Deployment with id {0} not found').format(deployment_id))
        raise exc.HTTPNotFound
    if deployment.environment_id != environment_id:
        LOG.info(_('Deployment with id {0} not found'
                   ' in environment {1}').format(deployment_id,
                                                 environment_id))
        raise exc.HTTPBadRequest

    deployment.description = _patch_description(deployment.description)
    return deployment
开发者ID:alex-docker,项目名称:murano,代码行数:13,代码来源:deployments.py


示例16: _authorize_package

def _authorize_package(package, context, allow_public=False):
    if context.is_admin:
        return

    if package.owner_id != context.tenant:
        if not allow_public:
            msg = _("Package '{0}' is not owned by "
                    "tenant '{1}'").format(package.id, context.tenant)
            LOG.error(msg)
            raise exc.HTTPForbidden(msg)
        if not package.is_public:
            msg = _("Package '{0}' is not public and not owned by "
                    "tenant '{1}' ").format(package.id, context.tenant)
            LOG.error(msg)
            raise exc.HTTPForbidden(msg)
开发者ID:nastya-kuz,项目名称:murano,代码行数:15,代码来源:api.py


示例17: _get_not_supported_column

def _get_not_supported_column(col_name_col_instance, column_name):
    try:
        column = col_name_col_instance[column_name]
    except KeyError:
        msg = _("Please specify column %s in col_name_col_instance "
                "param. It is required because column has unsupported "
                "type by sqlite).")
        raise ColumnError(msg % column_name)

    if not isinstance(column, Column):
        msg = _("col_name_col_instance param has wrong type of "
                "column instance for column %s It should be instance "
                "of sqlalchemy.Column.")
        raise ColumnError(msg % column_name)
    return column
开发者ID:ativelkov,项目名称:murano-api,代码行数:15,代码来源:utils.py


示例18: _validate_limit

        def _validate_limit(value):
            if value is None:
                return
            try:
                value = int(value)
            except ValueError:
                msg = _("limit param must be an integer")
                LOG.error(msg)
                raise exc.HTTPBadRequest(explanation=msg)

            if value <= 0:
                msg = _("limit param must be positive")
                LOG.error(msg)
                raise exc.HTTPBadRequest(explanation=msg)

            return value
开发者ID:OndrejVojta,项目名称:murano,代码行数:16,代码来源:catalog.py


示例19: db_sync

def db_sync(engine, abs_path, version=None, init_version=0, sanity_check=True):
    """Upgrade or downgrade a database.

    Function runs the upgrade() or downgrade() functions in change scripts.

    :param engine:       SQLAlchemy engine instance for a given database
    :param abs_path:     Absolute path to migrate repository.
    :param version:      Database will upgrade/downgrade until this version.
                         If None - database will update to the latest
                         available version.
    :param init_version: Initial database version
    :param sanity_check: Require schema sanity checking for all tables
    """

    if version is not None:
        try:
            version = int(version)
        except ValueError:
            raise exception.DbMigrationError(
                message=_("version should be an integer"))

    current_version = db_version(engine, abs_path, init_version)
    repository = _find_migrate_repo(abs_path)
    if sanity_check:
        _db_schema_sanity_check(engine)
    if version is None or version > current_version:
        return versioning_api.upgrade(engine, repository, version)
    else:
        return versioning_api.downgrade(engine, repository,
                                        version)
开发者ID:ativelkov,项目名称:murano-api,代码行数:30,代码来源:migration.py


示例20: _db_schema_sanity_check

def _db_schema_sanity_check(engine):
    """Ensure all database tables were created with required parameters.

    :param engine:  SQLAlchemy engine instance for a given database

    """

    if engine.name == 'mysql':
        onlyutf8_sql = ('SELECT TABLE_NAME,TABLE_COLLATION '
                        'from information_schema.TABLES '
                        'where TABLE_SCHEMA=%s and '
                        'TABLE_COLLATION NOT LIKE "%%utf8%%"')

        # NOTE(morganfainberg): exclude the sqlalchemy-migrate and alembic
        # versioning tables from the tables we need to verify utf8 status on.
        # Non-standard table names are not supported.
        EXCLUDED_TABLES = ['migrate_version', 'alembic_version']

        table_names = [res[0] for res in
                       engine.execute(onlyutf8_sql, engine.url.database) if
                       res[0].lower() not in EXCLUDED_TABLES]

        if len(table_names) > 0:
            raise ValueError(_('Tables "%s" have non utf8 collation, '
                               'please make sure all tables are CHARSET=utf8'
                               ) % ','.join(table_names))
开发者ID:ativelkov,项目名称:murano-api,代码行数:26,代码来源:migration.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python log.getLogger函数代码示例发布时间:2022-05-27
下一篇:
Python helpers.get_type函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap