Verified Commit 9e90569a authored by Martin Prudek's avatar Martin Prudek
Browse files

netmetr: Cache atsha hw-rev

parent ae813b23
......@@ -19,6 +19,7 @@ import csv
RMBT_BIN = "rmbt"
HIST_FILE = "/tmp/netmetr-history.json"
HW_REV_FILE = "/tmp/netmetr-hw-rev"
# FALLBACK_CTRL_SRV = "netmetr-control.labs.nic.cz"
FALLBACK_CTRL_SRV = "control.netmetr.cz"
FALLBACK_MAX_HISTORY_LOGS = 10
......@@ -49,16 +50,32 @@ class Netmetr:
if os.path.isfile("/etc/turris-version"):
with open("/etc/turris-version", 'r') as turris_version:
self.os_version = turris_version.read().split('\n')[0]
self.hw_version = subprocess.check_output([
"atsha204cmd",
"hw-rev"
])[:-1]
self.set_turris_hw_version()
self.model = "Turris"
else:
self.os_version = "unknown"
self.hw_version = "unknown"
self.model = "default"
def set_turris_hw_version(self):
if os.path.isfile(HW_REV_FILE):
with open(HW_REV_FILE, 'r') as hw_version:
self.hw_version = hw_version.read().split('\n')[0]
else:
self.hw_version = subprocess.check_output([
"atsha204cmd",
"hw-rev"
])[:-1]
_, hw_version_file = tempfile.mkstemp()
try:
with open(hw_version_file, "w") as hw_file:
hw_file.write(self.hw_version)
os.rename(hw_version_file, HW_REV_FILE)
except Exception as e:
print("Error saving turris hw revision.")
print(e)
def get_time(cls):
return str(int(round(calendar.timegm(time.gmtime())*1000)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment