6
6
(c) Holger Krekel, MIT license
7
7
"""
8
8
import optparse
9
- import pathlib
10
9
import re
11
10
import sys
12
11
34
33
35
34
36
35
def parsehosts (path ):
37
- path = pathlib . Path ( path )
36
+ host_regex = re . compile ( r"Host\s*(\S+)" )
38
37
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 )
43
42
if m is not None :
44
43
(sshname ,) = m .groups ()
45
44
l .append (sshname )
@@ -119,7 +118,7 @@ def getcpuinfo(self):
119
118
120
119
121
120
def debug (* args ):
122
- print >> sys . stderr , " " .join (map (str , args ))
121
+ print ( " " .join (map (str , args )), file = sys . stderr )
123
122
124
123
125
124
def error (* args ):
@@ -140,7 +139,7 @@ def getinfo(sshname, ssh_config=None, loginfo=sys.stdout):
140
139
ri = RemoteInfo (gw )
141
140
# print "%s info:" % sshname
142
141
prefix = sshname .upper () + " "
143
- print >> loginfo , prefix , "fqdn:" , ri .getfqdn ()
142
+ print ( prefix , "fqdn:" , ri .getfqdn (), file = loginfo )
144
143
for attr in ("sys.platform" , "sys.version_info" ):
145
144
loginfo .write (f"{ prefix } { attr } : " )
146
145
loginfo .flush ()
@@ -151,12 +150,12 @@ def getinfo(sshname, ssh_config=None, loginfo=sys.stdout):
151
150
memswap = ri .getmemswap ()
152
151
if memswap :
153
152
mem , swap = memswap
154
- print >> loginfo , prefix , "Memory:" , mem , "Swap:" , swap
153
+ print ( prefix , "Memory:" , mem , "Swap:" , swap , file = loginfo )
155
154
cpuinfo = ri .getcpuinfo ()
156
155
if cpuinfo :
157
156
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 )
160
159
return ri
161
160
162
161
0 commit comments