66(c) Holger Krekel, MIT license
77"""
88import optparse
9- import pathlib
109import re
1110import sys
1211
3433
3534
3635def 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
121120def debug (* args ):
122- print >> sys . stderr , " " .join (map (str , args ))
121+ print ( " " .join (map (str , args )), file = sys . stderr )
123122
124123
125124def 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