-
Notifications
You must be signed in to change notification settings - Fork 0
/
example python file for pushing remote branches.txt
52 lines (43 loc) · 1.27 KB
/
example python file for pushing remote branches.txt
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
#!/usr/bin/env python3
import os
import shutil
import sys
import socket
def check_reboot:
"""Returns True if the computer has a pending reboot."""
return os.path.exists("/run/reboot-required")
def check_disk_full(disk, min_gb, min_percent):
"""Returns True if there isn't enough disk space, False otherwise."""
du = shutil.disk_usage(disk)
#Calculate the percentage of free space
percent_free = 100 * du.free / du.total
#Calculate how many free gigabytes
gigabytes_free = du.free / 2**30
if gigabytes_free < min_gb or percent_free < min_percent:
return True
return False
def check_root_full():
"""Returns True if the root partition is full, False otherwise."""
return check_disk_full(disk='/', min_gb=2, min_percent=10)
def check_no_network():
"""Returns True if it fails to resolve Google's URL, False otherwise."""
try:
socket.gethostbyname("www.google.com")
return False
except:
return True
def main():
checks=[
(check_reboot, "Pending Reboot"),
(check_root_full, "Root partition full"),
(check_no_network, "No working network"),
]
everything_ok = True
for check, msg in checks:
if check():
print(msg)
everything_ok = False
if not everything_ok:
sys.exit(1)
print("Everything ok.")
sys.exit(0)