1.9.30 sync.
[gae.git] / python / google / appengine / api / client_deployinfo.py
blobfd3670183e42b90f42411d4fa899915d41fb035c
1 #!/usr/bin/env python
3 # Copyright 2007 Google Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 """Client deploy info.
19 Library for parsing client_deploy.yaml files and working with these in memory.
20 """
27 from google.appengine.api import appinfo
28 from google.appengine.api import validation
29 from google.appengine.api import yaml_builder
30 from google.appengine.api import yaml_listener
31 from google.appengine.api import yaml_object
33 RUNTIME = 'runtime'
34 START_TIME_USEC = 'start_time_usec'
35 END_TIME_USEC = 'end_time_usec'
36 REQUESTS = 'requests'
37 SUCCESS = 'success'
38 PATH = 'path'
39 RESPONSE_CODE = 'response_code'
40 REQUEST_SIZE_BYTES = 'request_size_bytes'
41 SDK_VERSION = 'sdk_version'
44 class Request(validation.Validated):
45 """A Request describes a single http request within a deployment attempt."""
46 ATTRIBUTES = {
47 PATH: validation.TYPE_STR,
48 RESPONSE_CODE: validation.Range(100, 599),
49 START_TIME_USEC: validation.TYPE_LONG,
50 END_TIME_USEC: validation.TYPE_LONG,
51 REQUEST_SIZE_BYTES: validation.TYPE_LONG,
55 class ClientDeployInfoExternal(validation.Validated):
56 """Describes the format of a client_deployinfo.yaml file."""
57 ATTRIBUTES = {
58 RUNTIME: appinfo.RUNTIME_RE_STRING,
59 START_TIME_USEC: validation.TYPE_LONG,
60 END_TIME_USEC: validation.TYPE_LONG,
61 REQUESTS: validation.Optional(validation.Repeated(Request)),
62 SUCCESS: validation.TYPE_BOOL,
63 SDK_VERSION: validation.Optional(validation.TYPE_STR)
67 class Error(Exception):
68 """Base ClientDeployInfo Exception type."""
71 class EmptyYaml(Error):
72 """Tried to load an empty yaml."""
75 class MultipleClientDeployInfo(Error):
76 """Tried to load a yaml containing multiple client deploy info definitions."""
79 def LoadSingleClientDeployInfo(client_deploy_info):
80 """Returns a ClientDeployInfoExternal from a deploy_info.yaml file or string.
82 Args:
83 client_deploy_info: The contents of a client_deploy_info.yaml file or
84 string, or an open file object.
86 Returns:
87 A ClientDeployInfoExternal instance which represents the contents of the
88 parsed yaml.
90 Raises:
91 EmptyYaml: when there are no documents in yaml.
92 MultipleClientDeployInfo: when there are multiple documents in yaml.
93 yaml_errors.EventError: when an error occurs while parsing the yaml.
94 """
95 builder = yaml_object.ObjectBuilder(ClientDeployInfoExternal)
96 handler = yaml_builder.BuilderHandler(builder)
97 listener = yaml_listener.EventListener(handler)
98 listener.Parse(client_deploy_info)
100 parsed_yaml = handler.GetResults()
101 if not parsed_yaml:
102 raise EmptyYaml()
103 if len(parsed_yaml) > 1:
104 raise MultipleClientDeployInfo()
105 return parsed_yaml[0]