summaryrefslogtreecommitdiffstats
path: root/import-layers/yocto-poky/bitbake/lib/toaster/contrib/tts/urlcheck.py
blob: 001fcee96a739fb0bf4a04d9f4ae9dfecbb16119 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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.warning("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.warning("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()
OpenPOWER on IntegriCloud