Browse Source

Implement versioning

check-vt100
Aleksander Kiryk 4 years ago
parent
commit
84ecef1eef
  1. 18
      common.py
  2. 19
      graph.py
  3. 3
      watch.py

18
common.py

@ -12,6 +12,11 @@ import sys
import re
# Increase major number for general changes, middle number for smaller changes
# that can cause incompatibilities and minor number for regular fixes
SARGRAPH_VERSION = "2.0.0"
# Print an error message and exit with non-zero status
def fail(msg):
print(f"Error: {msg}", file=sys.stderr)
@ -47,3 +52,16 @@ def scan(regex, conv, string):
except ValueError:
return None
return value
# Return True iff version string `a` is greater than or equal to `b`
def is_version_ge(a, b):
a = [int(n) for n in a.split('.')]
b = [int(n) for n in b.split('.')]
if len(a) != len(b):
return len(a) > len(b)
for i, _ in enumerate(a):
if a[i] != b[i]:
break
return a[i] >= b[i]

19
graph.py

@ -17,7 +17,7 @@ from common import *
global gnuplot
GNUPLOT_VERSION_EXPECTED = 5.0
GNUPLOT_VERSION_EXPECTED = "5.0"
START_DATE = ""
END_DATE = ""
@ -47,9 +47,9 @@ labels = []
# Check if the avaliable gnuplot has a required version
p = run_or_fail("gnuplot", "--version", stdout=subprocess.PIPE)
version = scan(r"gnuplot (\S+)", float, p.stdout.readline().decode())
if version < GNUPLOT_VERSION_EXPECTED:
fail(f"gnuplot version too low. Need at least {GNUPLOT_VERSION_EXPECTED} found {version[0]}")
version = scan(r"gnuplot (\S+)", str, p.stdout.readline().decode())
if not is_version_ge(version, GNUPLOT_VERSION_EXPECTED):
fail(f"gnuplot version too low. Need at least {GNUPLOT_VERSION_EXPECTED} found {version}")
# Run a command in a running gnuplot process
@ -94,6 +94,8 @@ def read_comments(session):
global CPU_NAME
global DURATION
data_version = None
with open(f"{session}.txt", "r") as f:
for line in f:
value = None
@ -114,6 +116,10 @@ def read_comments(session):
# Comments are not mixed with anything else, so skip
continue
value = scan("sargraph version: (\d+\.\d+)", str, line)
if value is not None:
data_version = value
value = scan("machine: ([^,]+)", str, line)
if value is not None:
UNAME = value
@ -154,6 +160,9 @@ def read_comments(session):
if value is not None:
AVERAGE_LOAD = value
if data_version != SARGRAPH_VERSION:
print("Warning: the data comes from an incompatible version of sargraph")
def graph(session, fname='plot.png'):
global OUTPUT_TYPE
@ -193,7 +202,7 @@ def graph(session, fname='plot.png'):
seconds_between = (edt - sdt).total_seconds()
if seconds_between < 100:
seconds_between = 100
seconds_between = 100
nsdt = sdt - datetime.timedelta(seconds = (seconds_between * 0.01))
nedt = edt + datetime.timedelta(seconds = (seconds_between * 0.01))

3
watch.py

@ -88,7 +88,8 @@ def initialize(session, machine):
break
with open(f"{session}.txt", "w") as f:
print(f"# pid: {os.getpid()}",
print(f"# sargraph version: {SARGRAPH_VERSION}",
f"pid: {os.getpid()}",
f"machine: {uname}",
f"cpu count: {cpus}",
f"cpu: {cpu_name}",

Loading…
Cancel
Save