-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathota.py
30 lines (25 loc) · 834 Bytes
/
ota.py
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
"""Perform an over-the-air update if internet is available"""
import subprocess
import socket
def has_internet(host="8.8.8.8", port=53, timeout=3):
"""Check if we have a working internet connection
Host: 8.8.8.8 (google-public-dns-a.google.com)
OpenPort: 53/tcp
Service: domain (DNS/TCP)
"""
try:
socket.setdefaulttimeout(timeout)
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
return True
except socket.error as ex:
#print(ex)
return False
def run():
"""Try running an over-the-air update"""
if (has_internet()):
try:
process = subprocess.Popen(["git", "pull"], stdout=subprocess.PIPE)
output = process.communicate()[0]
return True
except Exception: pass
return False