1 # Copyright 2009, Google Inc.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
14 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 r
"o3d_assets[\\\/].*",
36 r
"third_party[\\\/].*",
39 def FindOnPage(input_api
, url
, regex
):
40 """Given a url, download it and find the part matching a regex.
42 input_api: the limited set of input modules allowed in presubmit
44 regex: regex to match on
46 A string extracted from the match, or None if no match or error.
49 connection
= input_api
.urllib2
.urlopen(url
)
50 text
= connection
.read()
52 match
= input_api
.re
.search(regex
, text
)
62 def CheckTreeIsOpen(input_api
, output_api
, url
, url_text
):
63 """Similar to the one in presubmit_canned_checks except it shows an helpful
66 input_api: the limited set of input modules allowed in presubmit
67 output_api: the limited set of output modules allowed in presubmit
68 url: url to get numerical tree status from
69 url_text: url to get human readable tree status from
70 regex: regex to match on
72 A list of presubmit warnings.
74 assert(input_api
.is_committing
)
75 # Check if tree is open.
76 status
= FindOnPage(input_api
, url
, '([0-9]+)')
77 if status
and int(status
):
79 # Try to find out what failed.
80 message
= FindOnPage(input_api
, url_text
,
81 r
'\<div class\="Notice"\>(.*)\<\/div\>')
83 return [output_api
.PresubmitPromptWarning("The tree is closed.",
84 long_text
=message
.strip())]
85 # Report unknown reason.
86 return [output_api
.PresubmitPromptWarning(
87 "The tree status can't be checked.")]
90 def CheckChangeOnUpload(input_api
, output_api
):
92 black_list
= input_api
.DEFAULT_BLACK_LIST
+ EXCLUDED_PATHS
93 sources
= lambda x
: input_api
.FilterSourceFile(x
, black_list
=black_list
)
94 report
.extend(input_api
.canned_checks
.CheckChangeSvnEolStyle(
95 input_api
, output_api
, sources
))
99 def CheckChangeOnCommit(input_api
, output_api
):
101 black_list
= input_api
.DEFAULT_BLACK_LIST
+ EXCLUDED_PATHS
102 sources
= lambda x
: input_api
.FilterSourceFile(x
, black_list
=black_list
)
103 report
.extend(input_api
.canned_checks
.CheckChangeSvnEolStyle(
104 input_api
, output_api
, sources
))
105 report
.extend(CheckTreeIsOpen(
106 input_api
, output_api
,
107 'http://o3d-status.appspot.com/status',
108 'http://o3d-status.appspot.com/current'))