1
|
|
|
""" |
2
|
|
|
This module handles every related to online checking. |
3
|
|
|
|
4
|
|
|
We need to request several information from various providers. |
5
|
|
|
We could just try to request them, but instead |
6
|
|
|
you can ping them first and check if they are even reachable. |
7
|
|
|
This does not mean, that do not need to handle a failure on their part |
8
|
|
|
(e.g. if the server is responding, but can't deliver the information). |
9
|
|
|
""" |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
import http.client |
|
|
|
|
13
|
|
|
|
14
|
|
|
|
15
|
|
|
def _is_online(domain, sub_path, response_status, response_reason): |
|
|
|
|
16
|
|
|
conn = http.client.HTTPSConnection(domain, timeout=1) |
|
|
|
|
17
|
|
|
conn.request("HEAD", sub_path) |
18
|
|
|
response = conn.getresponse() |
19
|
|
|
conn.close() |
20
|
|
|
|
21
|
|
|
return (response.status == response_status) and (response.reason == response_reason) |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
def is_rm_doc_online(): |
25
|
|
|
""" |
26
|
|
|
Check if the Rainmeter documentation page is online. |
27
|
|
|
|
28
|
|
|
The Rainmeter online documentation is required to synchronize the local model |
29
|
|
|
with the latest online version. These information are stored and parsed |
30
|
|
|
to display them as a tooltip on special constructs. |
31
|
|
|
""" |
32
|
|
|
return _is_online("docs.rainmeter.net", "/manual-beta/", 200, "OK") |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
def is_gh_online(): |
36
|
|
|
""" |
37
|
|
|
Check if GitHub is online. |
38
|
|
|
|
39
|
|
|
The different services of GitHub are running in seperat services |
40
|
|
|
and thus just being GitHub online does not mean, |
41
|
|
|
that required parts are online. |
42
|
|
|
""" |
43
|
|
|
return _is_online("github.com", "/", 200, "OK") |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
def is_gh_raw_online(): |
47
|
|
|
""" |
48
|
|
|
Check if the raw content delivery from Github is online. |
49
|
|
|
|
50
|
|
|
It is routed to 301 and Moved Permanently because per standard it is routed to github.com |
51
|
|
|
because it natively only accepts real content paths. |
52
|
|
|
|
53
|
|
|
We do not follow reroutes else it would be 200 OK on github.com but we already have another method to check for that |
54
|
|
|
and Github.com is on a different service than the content delivery. |
55
|
|
|
""" |
56
|
|
|
return _is_online("raw.githubusercontent.com", "/", 301, "Moved Permanently") |
57
|
|
|
|