Skip to content

Commit

Permalink
doc/example/sysinfo: port to Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt authored and bluetech committed Apr 26, 2023
1 parent 8ff949e commit 44fd96e
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions doc/example/sysinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
(c) Holger Krekel, MIT license
"""
import optparse
import pathlib
import re
import sys

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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()
Expand All @@ -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


Expand Down

0 comments on commit 44fd96e

Please sign in to comment.