Skip to content

Commit 44fd96e

Browse files
RonnyPfannschmidtbluetech
authored andcommitted
doc/example/sysinfo: port to Python 3
1 parent 8ff949e commit 44fd96e

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

doc/example/sysinfo.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
(c) Holger Krekel, MIT license
77
"""
88
import optparse
9-
import pathlib
109
import re
1110
import sys
1211

@@ -34,12 +33,12 @@
3433

3534

3635
def parsehosts(path):
37-
path = pathlib.Path(path)
36+
host_regex = re.compile(r"Host\s*(\S+)")
3837
l = []
39-
rex = re.compile(r"Host\s*(\S+)")
40-
with path.open() as f:
41-
for line in f:
42-
m = rex.match(line)
38+
39+
with open(path) as fp:
40+
for line in fp:
41+
m = host_regex.match(line)
4342
if m is not None:
4443
(sshname,) = m.groups()
4544
l.append(sshname)
@@ -119,7 +118,7 @@ def getcpuinfo(self):
119118

120119

121120
def debug(*args):
122-
print >> sys.stderr, " ".join(map(str, args))
121+
print(" ".join(map(str, args)), file=sys.stderr)
123122

124123

125124
def error(*args):
@@ -140,7 +139,7 @@ def getinfo(sshname, ssh_config=None, loginfo=sys.stdout):
140139
ri = RemoteInfo(gw)
141140
# print "%s info:" % sshname
142141
prefix = sshname.upper() + " "
143-
print >> loginfo, prefix, "fqdn:", ri.getfqdn()
142+
print(prefix, "fqdn:", ri.getfqdn(), file=loginfo)
144143
for attr in ("sys.platform", "sys.version_info"):
145144
loginfo.write(f"{prefix} {attr}: ")
146145
loginfo.flush()
@@ -151,12 +150,12 @@ def getinfo(sshname, ssh_config=None, loginfo=sys.stdout):
151150
memswap = ri.getmemswap()
152151
if memswap:
153152
mem, swap = memswap
154-
print >> loginfo, prefix, "Memory:", mem, "Swap:", swap
153+
print(prefix, "Memory:", mem, "Swap:", swap, file=loginfo)
155154
cpuinfo = ri.getcpuinfo()
156155
if cpuinfo:
157156
numcpu, model = cpuinfo
158-
print >> loginfo, prefix, "number of cpus:", numcpu
159-
print >> loginfo, prefix, "cpu model", model
157+
print(prefix, "number of cpus:", numcpu, file=loginfo)
158+
print(prefix, "cpu model", model, file=loginfo)
160159
return ri
161160

162161

0 commit comments

Comments
 (0)