diff --git a/doc/example/sysinfo.py b/doc/example/sysinfo.py index c88517d7..ce3bb9ce 100644 --- a/doc/example/sysinfo.py +++ b/doc/example/sysinfo.py @@ -6,7 +6,6 @@ (c) Holger Krekel, MIT license """ import optparse -import pathlib import re import sys @@ -34,12 +33,12 @@ def parsehosts(path): - path = pathlib.Path(path) + host_regex = re.compile(r"Host\s*(\S+)") l = [] - rex = re.compile(r"Host\s*(\S+)") - with path.open() as f: - for line in f: - m = rex.match(line) + + with open(path) as fp: + for line in fp: + m = host_regex.match(line) if m is not None: (sshname,) = m.groups() l.append(sshname) @@ -119,7 +118,7 @@ def getcpuinfo(self): def debug(*args): - print >> sys.stderr, " ".join(map(str, args)) + print(" ".join(map(str, args)), file=sys.stderr) def error(*args): @@ -140,7 +139,7 @@ def getinfo(sshname, ssh_config=None, loginfo=sys.stdout): ri = RemoteInfo(gw) # print "%s info:" % sshname prefix = sshname.upper() + " " - print >> loginfo, prefix, "fqdn:", ri.getfqdn() + print(prefix, "fqdn:", ri.getfqdn(), file=loginfo) for attr in ("sys.platform", "sys.version_info"): loginfo.write(f"{prefix} {attr}: ") loginfo.flush() @@ -151,12 +150,12 @@ def getinfo(sshname, ssh_config=None, loginfo=sys.stdout): memswap = ri.getmemswap() if memswap: mem, swap = memswap - print >> loginfo, prefix, "Memory:", mem, "Swap:", swap + print(prefix, "Memory:", mem, "Swap:", swap, file=loginfo) cpuinfo = ri.getcpuinfo() if cpuinfo: numcpu, model = cpuinfo - print >> loginfo, prefix, "number of cpus:", numcpu - print >> loginfo, prefix, "cpu model", model + print(prefix, "number of cpus:", numcpu, file=loginfo) + print(prefix, "cpu model", model, file=loginfo) return ri