diff options
author | Patrick Williams <patrick@stwcx.xyz> | 2015-09-15 22:41:29 +0300 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2015-09-15 22:41:29 +0300 |
commit | 21f9b84b4b729fbd7acbd465e7a3f726e4d20f91 (patch) | |
tree | eb2d091d427ca0813b445509d59cc8e27e8ad25f /yocto-poky/bitbake/lib/toaster/contrib/tts/urlcheck.py | |
parent | 101cef31e2bf54c678501155cd2106251acbd076 (diff) | |
parent | c124f4f2e04dca16a428a76c89677328bc7bf908 (diff) | |
download | openbmc-21f9b84b4b729fbd7acbd465e7a3f726e4d20f91.tar.xz |
Merge commit 'c124f4f2e04dca16a428a76c89677328bc7bf908' as 'yocto-poky'
Diffstat (limited to 'yocto-poky/bitbake/lib/toaster/contrib/tts/urlcheck.py')
-rw-r--r-- | yocto-poky/bitbake/lib/toaster/contrib/tts/urlcheck.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/yocto-poky/bitbake/lib/toaster/contrib/tts/urlcheck.py b/yocto-poky/bitbake/lib/toaster/contrib/tts/urlcheck.py new file mode 100644 index 000000000..0820f82e2 --- /dev/null +++ b/yocto-poky/bitbake/lib/toaster/contrib/tts/urlcheck.py @@ -0,0 +1,53 @@ +from __future__ import print_function +import sys + +import httplib2 +import config +import urllist + + +config.logger.info("Testing %s with %s", config.TOASTER_BASEURL, config.W3C_VALIDATOR) + +def validate_html5(url): + http_client = httplib2.Http(None) + status = "Failed" + errors = -1 + warnings = -1 + + urlrequest = config.W3C_VALIDATOR+url + + # pylint: disable=broad-except + # we disable the broad-except because we want to actually catch all possible exceptions + try: + resp, _ = http_client.request(urlrequest, "HEAD") + if resp['x-w3c-validator-status'] != "Abort": + status = resp['x-w3c-validator-status'] + errors = int(resp['x-w3c-validator-errors']) + warnings = int(resp['x-w3c-validator-warnings']) + + if status == 'Invalid': + config.logger.warn("Failed %s is %s\terrors %s warnings %s (check at %s)", url, status, errors, warnings, urlrequest) + else: + config.logger.debug("OK! %s", url) + + except Exception as exc: + config.logger.warn("Failed validation call: %s", exc) + return (status, errors, warnings) + + +def print_validation(url): + status, errors, warnings = validate_html5(url) + config.logger.error("url %s is %s\terrors %s warnings %s (check at %s)", url, status, errors, warnings, config.W3C_VALIDATOR+url) + + +def main(): + print("Testing %s with %s" % (config.TOASTER_BASEURL, config.W3C_VALIDATOR)) + + if len(sys.argv) > 1: + print_validation(sys.argv[1]) + else: + for url in urllist.URLS: + print_validation(config.TOASTER_BASEURL+url) + +if __name__ == "__main__": + main() |