gcloud 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +2 -3
- data/CHANGELOG +4 -0
- data/LICENSE +674 -0
- data/Manifest +111 -0
- data/README.md +4 -3
- data/bin/gcutil +53 -0
- data/gcloud.gemspec +4 -3
- data/packages/gcutil-1.7.1/CHANGELOG +197 -0
- data/packages/gcutil-1.7.1/LICENSE +202 -0
- data/packages/gcutil-1.7.1/VERSION +1 -0
- data/packages/gcutil-1.7.1/gcutil +53 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/LICENSE +23 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/__init__.py +1 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/discovery.py +743 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/errors.py +123 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/ext/__init__.py +0 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/http.py +1443 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/mimeparse.py +172 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/model.py +385 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/schema.py +303 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/__init__.py +1 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/anyjson.py +32 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/appengine.py +528 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/client.py +1139 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/clientsecrets.py +105 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/crypt.py +244 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/django_orm.py +124 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/file.py +107 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/locked_file.py +343 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.py +379 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/tools.py +174 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/uritemplate/__init__.py +147 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/LICENSE +202 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/__init__.py +3 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/__init__.py +3 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/app.py +356 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/appcommands.py +783 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/basetest.py +1260 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/datelib.py +421 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/debug.py +60 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/file_util.py +181 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/resources.py +67 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/run_script_module.py +217 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/setup_command.py +159 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/shellutil.py +49 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/stopwatch.py +204 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/__init__.py +0 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/auth_helper.py +140 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/auth_helper_test.py +149 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/auto_auth.py +130 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/auto_auth_test.py +75 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/basic_cmds.py +128 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/basic_cmds_test.py +111 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.py +1808 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base_test.py +1651 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/compute/v1beta13.json +2851 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/compute/v1beta14.json +3361 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/disk_cmds.py +342 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/disk_cmds_test.py +474 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/firewall_cmds.py +344 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/firewall_cmds_test.py +231 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/flags_cache.py +274 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/gcutil +89 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/gcutil_logging.py +69 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/image_cmds.py +262 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/image_cmds_test.py +172 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/instance_cmds.py +1506 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/instance_cmds_test.py +1904 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/kernel_cmds.py +91 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/kernel_cmds_test.py +56 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/machine_type_cmds.py +106 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/machine_type_cmds_test.py +59 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/metadata.py +96 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/metadata_lib.py +357 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/metadata_test.py +84 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/mock_api.py +420 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/mock_metadata.py +58 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/move_cmds.py +824 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/move_cmds_test.py +307 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/network_cmds.py +178 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/network_cmds_test.py +133 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/operation_cmds.py +181 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/operation_cmds_test.py +196 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/path_initializer.py +38 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/project_cmds.py +173 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/project_cmds_test.py +111 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/scopes.py +61 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/scopes_test.py +50 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/snapshot_cmds.py +276 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/snapshot_cmds_test.py +260 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/ssh_keys.py +266 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/ssh_keys_test.py +128 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/table_formatter.py +563 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.py +188 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool_test.py +88 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/utils.py +208 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/utils_test.py +193 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/version.py +17 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/version_checker.py +246 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/version_checker_test.py +271 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/zone_cmds.py +151 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/zone_cmds_test.py +60 -0
- data/packages/gcutil-1.7.1/lib/httplib2/LICENSE +21 -0
- data/packages/gcutil-1.7.1/lib/httplib2/httplib2/__init__.py +1630 -0
- data/packages/gcutil-1.7.1/lib/httplib2/httplib2/cacerts.txt +714 -0
- data/packages/gcutil-1.7.1/lib/httplib2/httplib2/iri2uri.py +110 -0
- data/packages/gcutil-1.7.1/lib/httplib2/httplib2/socks.py +438 -0
- data/packages/gcutil-1.7.1/lib/iso8601/LICENSE +20 -0
- data/packages/gcutil-1.7.1/lib/iso8601/iso8601/__init__.py +1 -0
- data/packages/gcutil-1.7.1/lib/iso8601/iso8601/iso8601.py +102 -0
- data/packages/gcutil-1.7.1/lib/iso8601/iso8601/test_iso8601.py +111 -0
- data/packages/gcutil-1.7.1/lib/python_gflags/AUTHORS +2 -0
- data/packages/gcutil-1.7.1/lib/python_gflags/LICENSE +28 -0
- data/packages/gcutil-1.7.1/lib/python_gflags/gflags.py +2862 -0
- data/packages/gcutil-1.7.1/lib/python_gflags/gflags2man.py +544 -0
- data/packages/gcutil-1.7.1/lib/python_gflags/gflags_validators.py +187 -0
- metadata +118 -5
- metadata.gz.sig +0 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Early, and incomplete implementation of -04.
|
|
2
|
+
#
|
|
3
|
+
import re
|
|
4
|
+
import urllib
|
|
5
|
+
|
|
6
|
+
RESERVED = ":/?#[]@!$&'()*+,;="
|
|
7
|
+
OPERATOR = "+./;?|!@"
|
|
8
|
+
EXPLODE = "*+"
|
|
9
|
+
MODIFIER = ":^"
|
|
10
|
+
TEMPLATE = re.compile(r"{(?P<operator>[\+\./;\?|!@])?(?P<varlist>[^}]+)}", re.UNICODE)
|
|
11
|
+
VAR = re.compile(r"^(?P<varname>[^=\+\*:\^]+)((?P<explode>[\+\*])|(?P<partial>[:\^]-?[0-9]+))?(=(?P<default>.*))?$", re.UNICODE)
|
|
12
|
+
|
|
13
|
+
def _tostring(varname, value, explode, operator, safe=""):
|
|
14
|
+
if type(value) == type([]):
|
|
15
|
+
if explode == "+":
|
|
16
|
+
return ",".join([varname + "." + urllib.quote(x, safe) for x in value])
|
|
17
|
+
else:
|
|
18
|
+
return ",".join([urllib.quote(x, safe) for x in value])
|
|
19
|
+
if type(value) == type({}):
|
|
20
|
+
keys = value.keys()
|
|
21
|
+
keys.sort()
|
|
22
|
+
if explode == "+":
|
|
23
|
+
return ",".join([varname + "." + urllib.quote(key, safe) + "," + urllib.quote(value[key], safe) for key in keys])
|
|
24
|
+
else:
|
|
25
|
+
return ",".join([urllib.quote(key, safe) + "," + urllib.quote(value[key], safe) for key in keys])
|
|
26
|
+
else:
|
|
27
|
+
return urllib.quote(value, safe)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _tostring_path(varname, value, explode, operator, safe=""):
|
|
31
|
+
joiner = operator
|
|
32
|
+
if type(value) == type([]):
|
|
33
|
+
if explode == "+":
|
|
34
|
+
return joiner.join([varname + "." + urllib.quote(x, safe) for x in value])
|
|
35
|
+
elif explode == "*":
|
|
36
|
+
return joiner.join([urllib.quote(x, safe) for x in value])
|
|
37
|
+
else:
|
|
38
|
+
return ",".join([urllib.quote(x, safe) for x in value])
|
|
39
|
+
elif type(value) == type({}):
|
|
40
|
+
keys = value.keys()
|
|
41
|
+
keys.sort()
|
|
42
|
+
if explode == "+":
|
|
43
|
+
return joiner.join([varname + "." + urllib.quote(key, safe) + joiner + urllib.quote(value[key], safe) for key in keys])
|
|
44
|
+
elif explode == "*":
|
|
45
|
+
return joiner.join([urllib.quote(key, safe) + joiner + urllib.quote(value[key], safe) for key in keys])
|
|
46
|
+
else:
|
|
47
|
+
return ",".join([urllib.quote(key, safe) + "," + urllib.quote(value[key], safe) for key in keys])
|
|
48
|
+
else:
|
|
49
|
+
if value:
|
|
50
|
+
return urllib.quote(value, safe)
|
|
51
|
+
else:
|
|
52
|
+
return ""
|
|
53
|
+
|
|
54
|
+
def _tostring_query(varname, value, explode, operator, safe=""):
|
|
55
|
+
joiner = operator
|
|
56
|
+
varprefix = ""
|
|
57
|
+
if operator == "?":
|
|
58
|
+
joiner = "&"
|
|
59
|
+
varprefix = varname + "="
|
|
60
|
+
if type(value) == type([]):
|
|
61
|
+
if 0 == len(value):
|
|
62
|
+
return ""
|
|
63
|
+
if explode == "+":
|
|
64
|
+
return joiner.join([varname + "=" + urllib.quote(x, safe) for x in value])
|
|
65
|
+
elif explode == "*":
|
|
66
|
+
return joiner.join([urllib.quote(x, safe) for x in value])
|
|
67
|
+
else:
|
|
68
|
+
return varprefix + ",".join([urllib.quote(x, safe) for x in value])
|
|
69
|
+
elif type(value) == type({}):
|
|
70
|
+
if 0 == len(value):
|
|
71
|
+
return ""
|
|
72
|
+
keys = value.keys()
|
|
73
|
+
keys.sort()
|
|
74
|
+
if explode == "+":
|
|
75
|
+
return joiner.join([varname + "." + urllib.quote(key, safe) + "=" + urllib.quote(value[key], safe) for key in keys])
|
|
76
|
+
elif explode == "*":
|
|
77
|
+
return joiner.join([urllib.quote(key, safe) + "=" + urllib.quote(value[key], safe) for key in keys])
|
|
78
|
+
else:
|
|
79
|
+
return varprefix + ",".join([urllib.quote(key, safe) + "," + urllib.quote(value[key], safe) for key in keys])
|
|
80
|
+
else:
|
|
81
|
+
if value:
|
|
82
|
+
return varname + "=" + urllib.quote(value, safe)
|
|
83
|
+
else:
|
|
84
|
+
return varname
|
|
85
|
+
|
|
86
|
+
TOSTRING = {
|
|
87
|
+
"" : _tostring,
|
|
88
|
+
"+": _tostring,
|
|
89
|
+
";": _tostring_query,
|
|
90
|
+
"?": _tostring_query,
|
|
91
|
+
"/": _tostring_path,
|
|
92
|
+
".": _tostring_path,
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def expand(template, vars):
|
|
97
|
+
def _sub(match):
|
|
98
|
+
groupdict = match.groupdict()
|
|
99
|
+
operator = groupdict.get('operator')
|
|
100
|
+
if operator is None:
|
|
101
|
+
operator = ''
|
|
102
|
+
varlist = groupdict.get('varlist')
|
|
103
|
+
|
|
104
|
+
safe = "@"
|
|
105
|
+
if operator == '+':
|
|
106
|
+
safe = RESERVED
|
|
107
|
+
varspecs = varlist.split(",")
|
|
108
|
+
varnames = []
|
|
109
|
+
defaults = {}
|
|
110
|
+
for varspec in varspecs:
|
|
111
|
+
m = VAR.search(varspec)
|
|
112
|
+
groupdict = m.groupdict()
|
|
113
|
+
varname = groupdict.get('varname')
|
|
114
|
+
explode = groupdict.get('explode')
|
|
115
|
+
partial = groupdict.get('partial')
|
|
116
|
+
default = groupdict.get('default')
|
|
117
|
+
if default:
|
|
118
|
+
defaults[varname] = default
|
|
119
|
+
varnames.append((varname, explode, partial))
|
|
120
|
+
|
|
121
|
+
retval = []
|
|
122
|
+
joiner = operator
|
|
123
|
+
prefix = operator
|
|
124
|
+
if operator == "+":
|
|
125
|
+
prefix = ""
|
|
126
|
+
joiner = ","
|
|
127
|
+
if operator == "?":
|
|
128
|
+
joiner = "&"
|
|
129
|
+
if operator == "":
|
|
130
|
+
joiner = ","
|
|
131
|
+
for varname, explode, partial in varnames:
|
|
132
|
+
if varname in vars:
|
|
133
|
+
value = vars[varname]
|
|
134
|
+
#if not value and (type(value) == type({}) or type(value) == type([])) and varname in defaults:
|
|
135
|
+
if not value and value != "" and varname in defaults:
|
|
136
|
+
value = defaults[varname]
|
|
137
|
+
elif varname in defaults:
|
|
138
|
+
value = defaults[varname]
|
|
139
|
+
else:
|
|
140
|
+
continue
|
|
141
|
+
retval.append(TOSTRING[operator](varname, value, explode, operator, safe=safe))
|
|
142
|
+
if "".join(retval):
|
|
143
|
+
return prefix + joiner.join(retval)
|
|
144
|
+
else:
|
|
145
|
+
return ""
|
|
146
|
+
|
|
147
|
+
return TEMPLATE.sub(_sub, template)
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# Copyright 2003 Google Inc. All Rights Reserved.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS-IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
"""Generic entry point for Google applications.
|
|
17
|
+
|
|
18
|
+
To use this module, simply define a 'main' function with a single
|
|
19
|
+
'argv' argument and add the following to the end of your source file:
|
|
20
|
+
|
|
21
|
+
if __name__ == '__main__':
|
|
22
|
+
app.run()
|
|
23
|
+
|
|
24
|
+
TODO(user): Remove silly main-detection logic, and force all clients
|
|
25
|
+
of this module to check __name__ explicitly. Fix all current clients
|
|
26
|
+
that don't check __name__.
|
|
27
|
+
"""
|
|
28
|
+
import errno
|
|
29
|
+
import os
|
|
30
|
+
import pdb
|
|
31
|
+
import socket
|
|
32
|
+
import stat
|
|
33
|
+
import struct
|
|
34
|
+
import sys
|
|
35
|
+
import time
|
|
36
|
+
import traceback
|
|
37
|
+
import gflags as flags
|
|
38
|
+
FLAGS = flags.FLAGS
|
|
39
|
+
|
|
40
|
+
flags.DEFINE_boolean('run_with_pdb', 0, 'Set to true for PDB debug mode')
|
|
41
|
+
flags.DEFINE_boolean('run_with_profiling', 0,
|
|
42
|
+
'Set to true for profiling the script. '
|
|
43
|
+
'Execution will be slower, and the output format might '
|
|
44
|
+
'change over time.')
|
|
45
|
+
flags.DEFINE_boolean('use_cprofile_for_profiling', True,
|
|
46
|
+
'Use cProfile instead of the profile module for '
|
|
47
|
+
'profiling. This has no effect unless '
|
|
48
|
+
'--run_with_profiling is set.')
|
|
49
|
+
|
|
50
|
+
# If main() exits via an abnormal exception, call into these
|
|
51
|
+
# handlers before exiting.
|
|
52
|
+
|
|
53
|
+
EXCEPTION_HANDLERS = []
|
|
54
|
+
help_text_wrap = False # Whether to enable TextWrap in help output
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class Error(Exception):
|
|
58
|
+
pass
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class UsageError(Error):
|
|
62
|
+
"""The arguments supplied by the user are invalid.
|
|
63
|
+
|
|
64
|
+
Raise this when the arguments supplied are invalid from the point of
|
|
65
|
+
view of the application. For example when two mutually exclusive
|
|
66
|
+
flags have been supplied or when there are not enough non-flag
|
|
67
|
+
arguments. It is distinct from flags.FlagsError which covers the lower
|
|
68
|
+
level of parsing and validating individual flags.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
def __init__(self, message, exitcode=1):
|
|
72
|
+
Error.__init__(self, message)
|
|
73
|
+
self.exitcode = exitcode
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class HelpFlag(flags.BooleanFlag):
|
|
77
|
+
"""Special boolean flag that displays usage and raises SystemExit."""
|
|
78
|
+
|
|
79
|
+
def __init__(self):
|
|
80
|
+
flags.BooleanFlag.__init__(self, 'help', 0, 'show this help',
|
|
81
|
+
short_name='?', allow_override=1)
|
|
82
|
+
|
|
83
|
+
def Parse(self, arg):
|
|
84
|
+
if arg:
|
|
85
|
+
usage(writeto_stdout=1)
|
|
86
|
+
sys.exit(1)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class HelpXMLFlag(flags.BooleanFlag):
|
|
90
|
+
"""Similar to HelpFlag, but generates output in XML format."""
|
|
91
|
+
|
|
92
|
+
def __init__(self):
|
|
93
|
+
flags.BooleanFlag.__init__(self, 'helpxml', False,
|
|
94
|
+
'like --help, but generates XML output',
|
|
95
|
+
allow_override=1)
|
|
96
|
+
|
|
97
|
+
def Parse(self, arg):
|
|
98
|
+
if arg:
|
|
99
|
+
flags.FLAGS.WriteHelpInXMLFormat(sys.stdout)
|
|
100
|
+
sys.exit(1)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class HelpshortFlag(flags.BooleanFlag):
|
|
104
|
+
"""Special bool flag that calls usage(shorthelp=1) and raises SystemExit."""
|
|
105
|
+
|
|
106
|
+
def __init__(self):
|
|
107
|
+
flags.BooleanFlag.__init__(self, 'helpshort', 0,
|
|
108
|
+
'show usage only for this module',
|
|
109
|
+
allow_override=1)
|
|
110
|
+
|
|
111
|
+
def Parse(self, arg):
|
|
112
|
+
if arg:
|
|
113
|
+
usage(shorthelp=1, writeto_stdout=1)
|
|
114
|
+
sys.exit(1)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class BuildDataFlag(flags.BooleanFlag):
|
|
118
|
+
|
|
119
|
+
"""Boolean flag that writes build data to stdout and exits."""
|
|
120
|
+
|
|
121
|
+
def __init__(self):
|
|
122
|
+
flags.BooleanFlag.__init__(self, 'show_build_data', 0,
|
|
123
|
+
'show build data and exit')
|
|
124
|
+
|
|
125
|
+
def Parse(self, arg):
|
|
126
|
+
if arg:
|
|
127
|
+
sys.stdout.write(build_data.BuildData())
|
|
128
|
+
sys.exit(0)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def parse_flags_with_usage(args):
|
|
132
|
+
"""Try parsing the flags, printing usage and exiting if unparseable."""
|
|
133
|
+
try:
|
|
134
|
+
argv = FLAGS(args)
|
|
135
|
+
return argv
|
|
136
|
+
except flags.FlagsError, error:
|
|
137
|
+
sys.stderr.write('FATAL Flags parsing error: %s\n' % error)
|
|
138
|
+
sys.stderr.write('Pass --help or --helpshort to see help on flags.\n')
|
|
139
|
+
sys.exit(1)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
_define_help_flags_called = False
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def DefineHelpFlags():
|
|
146
|
+
"""Register help flags. Idempotent."""
|
|
147
|
+
# Use a global to ensure idempotence.
|
|
148
|
+
# pylint: disable-msg=W0603
|
|
149
|
+
global _define_help_flags_called
|
|
150
|
+
|
|
151
|
+
if not _define_help_flags_called:
|
|
152
|
+
flags.DEFINE_flag(HelpFlag())
|
|
153
|
+
flags.DEFINE_flag(HelpXMLFlag())
|
|
154
|
+
flags.DEFINE_flag(HelpshortFlag())
|
|
155
|
+
flags.DEFINE_flag(BuildDataFlag())
|
|
156
|
+
_define_help_flags_called = True
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def RegisterAndParseFlagsWithUsage():
|
|
160
|
+
"""Register help flags, parse arguments and show usage if appropriate.
|
|
161
|
+
|
|
162
|
+
Returns:
|
|
163
|
+
remaining arguments after flags parsing
|
|
164
|
+
"""
|
|
165
|
+
DefineHelpFlags()
|
|
166
|
+
|
|
167
|
+
argv = parse_flags_with_usage(sys.argv)
|
|
168
|
+
return argv
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def really_start(main=None):
|
|
172
|
+
"""Initializes flag values, and calls main with non-flag arguments.
|
|
173
|
+
|
|
174
|
+
Only non-flag arguments are passed to main(). The return value of main() is
|
|
175
|
+
used as the exit status.
|
|
176
|
+
|
|
177
|
+
Args:
|
|
178
|
+
main: Main function to run with the list of non-flag arguments, or None
|
|
179
|
+
so that sys.modules['__main__'].main is to be used.
|
|
180
|
+
"""
|
|
181
|
+
argv = RegisterAndParseFlagsWithUsage()
|
|
182
|
+
|
|
183
|
+
if main is None:
|
|
184
|
+
main = sys.modules['__main__'].main
|
|
185
|
+
|
|
186
|
+
try:
|
|
187
|
+
if FLAGS.run_with_pdb:
|
|
188
|
+
sys.exit(pdb.runcall(main, argv))
|
|
189
|
+
else:
|
|
190
|
+
if FLAGS.run_with_profiling:
|
|
191
|
+
# Avoid import overhead since most apps (including performance-sensitive
|
|
192
|
+
# ones) won't be run with profiling.
|
|
193
|
+
import atexit
|
|
194
|
+
if FLAGS.use_cprofile_for_profiling:
|
|
195
|
+
import cProfile as profile
|
|
196
|
+
else:
|
|
197
|
+
import profile
|
|
198
|
+
profiler = profile.Profile()
|
|
199
|
+
atexit.register(profiler.print_stats)
|
|
200
|
+
retval = profiler.runcall(main, argv)
|
|
201
|
+
sys.exit(retval)
|
|
202
|
+
else:
|
|
203
|
+
sys.exit(main(argv))
|
|
204
|
+
except UsageError, error:
|
|
205
|
+
usage(shorthelp=1, detailed_error=error, exitcode=error.exitcode)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def run():
|
|
209
|
+
"""Begin executing the program.
|
|
210
|
+
|
|
211
|
+
- Parses command line flags with the flag module.
|
|
212
|
+
- If there are any errors, print usage().
|
|
213
|
+
- Calls main() with the remaining arguments.
|
|
214
|
+
- If main() raises a UsageError, print usage and the error message.
|
|
215
|
+
"""
|
|
216
|
+
return _actual_start()
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def _actual_start():
|
|
220
|
+
"""Another layer in the starting stack."""
|
|
221
|
+
# Get raw traceback
|
|
222
|
+
tb = None
|
|
223
|
+
try:
|
|
224
|
+
raise ZeroDivisionError('')
|
|
225
|
+
except ZeroDivisionError:
|
|
226
|
+
tb = sys.exc_info()[2]
|
|
227
|
+
assert tb
|
|
228
|
+
|
|
229
|
+
# Look at previous stack frame's previous stack frame (previous
|
|
230
|
+
# frame is run() or start(); the frame before that should be the
|
|
231
|
+
# frame of the original caller, which should be __main__ or appcommands
|
|
232
|
+
prev_prev_frame = tb.tb_frame.f_back.f_back
|
|
233
|
+
if not prev_prev_frame:
|
|
234
|
+
return
|
|
235
|
+
prev_prev_name = prev_prev_frame.f_globals.get('__name__', None)
|
|
236
|
+
if (prev_prev_name != '__main__'
|
|
237
|
+
and not prev_prev_name.endswith('.appcommands')):
|
|
238
|
+
return
|
|
239
|
+
# just in case there's non-trivial stuff happening in __main__
|
|
240
|
+
del tb
|
|
241
|
+
sys.exc_clear()
|
|
242
|
+
|
|
243
|
+
try:
|
|
244
|
+
really_start()
|
|
245
|
+
except SystemExit, e:
|
|
246
|
+
raise
|
|
247
|
+
except Exception, e:
|
|
248
|
+
# Call any installed exception handlers which may, for example,
|
|
249
|
+
# log to a file or send email.
|
|
250
|
+
for handler in EXCEPTION_HANDLERS:
|
|
251
|
+
try:
|
|
252
|
+
if handler.Wants(e):
|
|
253
|
+
handler.Handle(e)
|
|
254
|
+
except:
|
|
255
|
+
# We don't want to stop for exceptions in the exception handlers but
|
|
256
|
+
# we shouldn't hide them either.
|
|
257
|
+
sys.stderr.write(traceback.format_exc())
|
|
258
|
+
raise
|
|
259
|
+
# All handlers have had their chance, now die as we would have normally.
|
|
260
|
+
raise
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def usage(shorthelp=0, writeto_stdout=0, detailed_error=None, exitcode=None):
|
|
264
|
+
"""Write __main__'s docstring to stderr with some help text.
|
|
265
|
+
|
|
266
|
+
Args:
|
|
267
|
+
shorthelp: print only flags from this module, rather than all flags.
|
|
268
|
+
writeto_stdout: write help message to stdout, rather than to stderr.
|
|
269
|
+
detailed_error: additional detail about why usage info was presented.
|
|
270
|
+
exitcode: if set, exit with this status code after writing help.
|
|
271
|
+
"""
|
|
272
|
+
if writeto_stdout:
|
|
273
|
+
stdfile = sys.stdout
|
|
274
|
+
else:
|
|
275
|
+
stdfile = sys.stderr
|
|
276
|
+
|
|
277
|
+
doc = sys.modules['__main__'].__doc__
|
|
278
|
+
if not doc:
|
|
279
|
+
doc = '\nUSAGE: %s [flags]\n' % sys.argv[0]
|
|
280
|
+
doc = flags.TextWrap(doc, indent=' ', firstline_indent='')
|
|
281
|
+
else:
|
|
282
|
+
# Replace all '%s' with sys.argv[0], and all '%%' with '%'.
|
|
283
|
+
num_specifiers = doc.count('%') - 2 * doc.count('%%')
|
|
284
|
+
try:
|
|
285
|
+
doc %= (sys.argv[0],) * num_specifiers
|
|
286
|
+
except (OverflowError, TypeError, ValueError):
|
|
287
|
+
# Just display the docstring as-is.
|
|
288
|
+
pass
|
|
289
|
+
if help_text_wrap:
|
|
290
|
+
doc = flags.TextWrap(flags.DocToHelp(doc))
|
|
291
|
+
if shorthelp:
|
|
292
|
+
flag_str = FLAGS.MainModuleHelp()
|
|
293
|
+
else:
|
|
294
|
+
flag_str = str(FLAGS)
|
|
295
|
+
try:
|
|
296
|
+
stdfile.write(doc)
|
|
297
|
+
if flag_str:
|
|
298
|
+
stdfile.write('\nflags:\n')
|
|
299
|
+
stdfile.write(flag_str)
|
|
300
|
+
stdfile.write('\n')
|
|
301
|
+
if detailed_error is not None:
|
|
302
|
+
stdfile.write('\n%s\n' % detailed_error)
|
|
303
|
+
except IOError, e:
|
|
304
|
+
# We avoid printing a huge backtrace if we get EPIPE, because
|
|
305
|
+
# "foo.par --help | less" is a frequent use case.
|
|
306
|
+
if e.errno != errno.EPIPE:
|
|
307
|
+
raise
|
|
308
|
+
if exitcode is not None:
|
|
309
|
+
sys.exit(exitcode)
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
class ExceptionHandler(object):
|
|
313
|
+
"""Base exception handler from which other may inherit."""
|
|
314
|
+
|
|
315
|
+
def Wants(self, unused_exc):
|
|
316
|
+
"""Check if this exception handler want to handle this exception.
|
|
317
|
+
|
|
318
|
+
Args:
|
|
319
|
+
unused_exc: Exception, the current exception
|
|
320
|
+
|
|
321
|
+
Returns:
|
|
322
|
+
boolean
|
|
323
|
+
|
|
324
|
+
This base handler wants to handle all exceptions, override this
|
|
325
|
+
method if you want to be more selective.
|
|
326
|
+
"""
|
|
327
|
+
return True
|
|
328
|
+
|
|
329
|
+
def Handle(self, exc):
|
|
330
|
+
"""Do something with the current exception.
|
|
331
|
+
|
|
332
|
+
Args:
|
|
333
|
+
exc: Exception, the current exception
|
|
334
|
+
|
|
335
|
+
This method must be overridden.
|
|
336
|
+
"""
|
|
337
|
+
raise NotImplementedError()
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
def InstallExceptionHandler(handler):
|
|
341
|
+
"""Install an exception handler.
|
|
342
|
+
|
|
343
|
+
Args:
|
|
344
|
+
handler: an object conforming to the interface defined in ExceptionHandler
|
|
345
|
+
|
|
346
|
+
Raises:
|
|
347
|
+
TypeError: handler was not of the correct type
|
|
348
|
+
|
|
349
|
+
All installed exception handlers will be called if main() exits via
|
|
350
|
+
an abnormal exception, i.e. not one of SystemExit, KeyboardInterrupt,
|
|
351
|
+
FlagsError or UsageError.
|
|
352
|
+
"""
|
|
353
|
+
if not isinstance(handler, ExceptionHandler):
|
|
354
|
+
raise TypeError('handler of type %s does not inherit from ExceptionHandler'
|
|
355
|
+
% type(handler))
|
|
356
|
+
EXCEPTION_HANDLERS.append(handler)
|