Cover Letter
v2 cover Cover Letter
Patch 9 fixes an issue where the device has IPv6 disabled, causing a FileNotFound error.
All other patches edit files to replace standard strings with f-strings.
Anubhav Shelat (10):
rteval: Use f-strings in rtevalclient.py
rteval: Use f-strings in rtevalConfig
rteval: Use f-strings in cputopology
rteval: Use f-strings in kernel.py
rteval: Use f-strings in memory.py
rteval: Use f-strings in osinfo
rteval: Use f-strings in services.py
rteval: Use f-strings in tools.py
Added code to check if the proc/net/if_inet6 file exists while loading
IPv6 addresses in the IPv6Addresses class
rteval: Use f-strings in __init__.py
rteval/rtevalConfig.py | 2 +- rteval/rtevalclient.py | 2 +- rteval/sysinfo/__init__.py | 18 +++++++----------- rteval/sysinfo/cputopology.py | 4 +--- rteval/sysinfo/kernel.py | 4 ++-- rteval/sysinfo/memory.py | 8 ++++---- rteval/sysinfo/newnet.py | 28 ++++++++++++++++------------ rteval/sysinfo/osinfo.py | 12 ++++++------ rteval/sysinfo/services.py | 12 ++++++------ rteval/sysinfo/tools.py | 2 +- 10 files changed, 45 insertions(+), 47 deletions(-)
Signature · 1 line
2.31.1
PATCH v2 1/10 rteval: Use f-strings in rtevalclient.py
Use f-strings in rtevalclient.py
--- rteval/rtevalclient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rteval/rtevalclient.py +1 -1
@@ -61,7 +61,7 @@ class rtevalclient: cmpr = compr.compress(fbuf.getvalue()) data = base64.b64encode(cmpr + compr.flush()) ret = self.srv.SendReport(self.hostname, data) - print("rtevalclient::SendReport() - Sent %i bytes (XML document length: %i bytes, compression ratio: %.02f%%)" % (len(data), doclen, (1-(float(len(data)) / float(doclen)))*100 )) + print(f"rtevalclient::SendReport() - Sent {len(data)} bytes (XML document length: {doclen} bytes, compression ratio: {(1-(float(len(data)) / float(doclen)))*100}:.2f)") return ret def SendDataAsFile(self, fname, data, decompr = False):
Signature · 1 line
2.31.1
Re: [PATCH v2 01/10] rteval: Use f-strings in rtevalclient.py
Quoted 13 lines · Anubhav Shelat
Use f-strings in
rtevalclient.pySigned-off-by Anubhav Shelat <[email protected]>--- rteval/rtevalclient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)rteval/rtevalclient.py +0
-0
rteval/rtevalclient.py class rtevalclient: · line 67
Quoted 8 lines
rteval/rtevalclient.py +1
-1@@ -61,7 +61,7 @@ class rtevalclient: cmpr = compr.compress(fbuf.getvalue()) data = base64.b64encode(cmpr + compr.flush()) ret = self.srv.SendReport(self.hostname, data) - print("rtevalclient::SendReport() - Sent %i bytes (XML document length: %i bytes, compression ratio: %.02f%%)" % (len(data), doclen, (1-(float(len(data)) / float(doclen)))*100 )) + print(f"rtevalclient::SendReport() - Sent {len(data)} bytes (XML document length: {doclen} bytes, compression ratio: {(1-(float(len(data)) / float(doclen)))*100}:.2f)") return ret def SendDataAsFile(self, fname, data, decompr = False):
PATCH v2 2/10 rteval: Use f-strings in rtevalConfig
In reply to Anubhav ShelatUse f-strings in rtevalConfig.py
--- rteval/rtevalConfig.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rteval/rtevalConfig.py +1 -1
@@ -115,7 +115,7 @@ class rtevalCfgSection: "Simple method for dumping config when object is used as a string" if not self.__cfgdata: return "# empty" - return "\n".join(["%s: %s" % (k, v) for k, v in list(self.__cfgdata.items())]) + "\n" + return "\n".join([f"{k}: {v}" for k, v in list(self.__cfgdata.items())]) + "\n" def __setattr__(self, key, val):
Signature · 1 line
2.31.1
Re: [PATCH v2 02/10] rteval: Use f-strings in rtevalConfig
Quoted 13 lines · Anubhav Shelat
Use f-strings in
rtevalConfig.pySigned-off-by Anubhav Shelat <[email protected]>--- rteval/rtevalConfig.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)rteval/rtevalConfig.py +0
-0
rteval/rtevalConfig.py class rtevalCfgSection: · line 121
Quoted 8 lines
rteval/rtevalConfig.py +1
-1@@ -115,7 +115,7 @@ class rtevalCfgSection: "Simple method for dumping config when object is used as a string" if not self.__cfgdata: return "# empty" - return "\n".join(["%s: %s" % (k, v) for k, v in list(self.__cfgdata.items())]) + "\n" + return "\n".join([f"{k}: {v}" for k, v in list(self.__cfgdata.items())]) + "\n" def __setattr__(self, key, val):
PATCH v2 3/10 rteval: Use f-strings in cputopology
In reply to Anubhav ShelatUse f-strings in cputopology
--- rteval/sysinfo/cputopology.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
rteval/sysinfo/cputopology.py +1 -3
@@ -124,9 +124,7 @@ def unit_test(rootdir): x.saveFormatFileEnc('-', 'UTF-8', 1) print(" ---- getCPUcores() / getCPUscokets() ---- ") - print("CPU cores: %i (online: %i) - CPU sockets: %i" % (cputop.cpu_getCores(False), - cputop.cpu_getCores(True), - cputop.cpu_getSockets())) + print(f"CPU cores: {cputop.cpu_getCores(False)} (online: {cputop.cpu_getCores(True)}) - CPU sockets: {cputop.cpu_getSockets()}") return 0 except Exception as e: # import traceback
Signature · 1 line
2.31.1
Re: [PATCH v2 03/10] rteval: Use f-strings in cputopology
Quoted 24 lines · Anubhav Shelat
Use f-strings in cputopology
Signed-off-by Anubhav Shelat <[email protected]>--- rteval/sysinfo/cputopology.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)rteval/sysinfo/cputopology.py +1
-3@@ -124,9 +124,7 @@ def unit_test(rootdir): x.saveFormatFileEnc('-', 'UTF-8', 1) print(" ---- getCPUcores() / getCPUscokets() ---- ") - print("CPU cores: %i (online: %i) - CPU sockets: %i" % (cputop.cpu_getCores(False), - cputop.cpu_getCores(True), - cputop.cpu_getSockets())) + print(f"CPU cores: {cputop.cpu_getCores(False)} (online: {cputop.cpu_getCores(True)}) - CPU sockets: {cputop.cpu_getSockets()}") return 0 except Exception as e: # import tracebackSignature · 1 line
2.31.1
PATCH v2 4/10 rteval: Use f-strings in kernel.py
In reply to Anubhav ShelatUse f-strings in kernel.py
--- rteval/sysinfo/kernel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
rteval/sysinfo/kernel.py +2 -2
@@ -47,8 +47,8 @@ class KernelInfo: policies = {'DLN': 'deadline', 'FF':'fifo', 'RR':'rrobin', 'TS':'other', '?':'unknown'} ret_kthreads = {} self.__log(Log.DEBUG, "getting kthread status") - cmd = '%s -eocommand,pid,policy,rtprio,comm' % getcmdpath('ps') - self.__log(Log.DEBUG, "cmd: %s" % cmd) + cmd = f"{getcmdpath('ps')} -eocommand,pid,policy,rtprio,comm" + self.__log(Log.DEBUG, f"cmd: {cmd}") c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) for p in c.stdout: v = p.strip().split()
Signature · 1 line
2.31.1
Re: [PATCH v2 04/10] rteval: Use f-strings in kernel.py
Quoted 26 lines · Anubhav Shelat
Use f-strings in
kernel.pySigned-off-by Anubhav Shelat <[email protected]>--- rteval/sysinfo/kernel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)rteval/sysinfo/kernel.py +2
-2@@ -47,8 +47,8 @@ class KernelInfo: policies = {'DLN': 'deadline', 'FF':'fifo', 'RR':'rrobin', 'TS':'other', '?':'unknown'} ret_kthreads = {} self.__log(Log.DEBUG, "getting kthread status") - cmd = '%s -eocommand,pid,policy,rtprio,comm' % getcmdpath('ps') - self.__log(Log.DEBUG, "cmd: %s" % cmd) + cmd = f"{getcmdpath('ps')} -eocommand,pid,policy,rtprio,comm" + self.__log(Log.DEBUG, f"cmd: {cmd}") c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) for p in c.stdout: v = p.strip().split()Signature · 1 line
2.31.1
PATCH v2 5/10 rteval: Use f-strings in memory.py
In reply to Anubhav ShelatUse f-strings in memory.py
--- rteval/sysinfo/memory.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
rteval/sysinfo/memory.py +4 -4
@@ -49,7 +49,7 @@ class MemoryInfo: if l.startswith('MemTotal:'): parts = l.split() if parts[2].lower() != 'kb': - raise RuntimeError("Units changed from kB! (%s)" % parts[2]) + raise RuntimeError(f"Units changed from kB! ({parts[2]})") rawsize = int(parts[1]) f.close() break
@@ -76,7 +76,7 @@ class MemoryInfo: memsize = self.mem_get_size() mem_n = libxml2.newNode("memory_size") - mem_n.addContent("%.3f" % memsize[0]) + mem_n.addContent(f"{memsize[0]:.3f}") mem_n.newProp("unit", memsize[1]) rep_n.addChild(mem_n)
@@ -88,8 +88,8 @@ def unit_test(rootdir): import sys try: mi = MemoryInfo() - print("Numa nodes: %i" % mi.mem_get_numa_nodes()) - print("Memory: %i %s" % mi.mem_get_size()) + print(f"Numa nodes: {mi.mem_get_numa_nodes()}") + print(f"Memory: {int(mi.mem_get_size()[0])} {mi.mem_get_size()[1]}") except Exception as e: import traceback traceback.print_exc(file=sys.stdout)
Signature · 1 line
2.31.1
Re: [PATCH v2 05/10] rteval: Use f-strings in memory.py
o
Quoted 43 lines · Anubhav Shelat
Use f-strings in
memory.pySigned-off-by Anubhav Shelat <[email protected]>--- rteval/sysinfo/memory.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)rteval/sysinfo/memory.py +4
-4@@ -49,7 +49,7 @@ class MemoryInfo: if l.startswith('MemTotal:'): parts = l.split() if parts[2].lower() != 'kb': - raise RuntimeError("Units changed from kB! (%s)" % parts[2]) + raise RuntimeError(f"Units changed from kB! ({parts[2]})") rawsize = int(parts[1]) f.close() break@@ -76,7 +76,7 @@ class MemoryInfo: memsize = self.mem_get_size() mem_n = libxml2.newNode("memory_size") - mem_n.addContent("%.3f" % memsize[0]) + mem_n.addContent(f"{memsize[0]:.3f}") mem_n.newProp("unit", memsize[1]) rep_n.addChild(mem_n)@@ -88,8 +88,8 @@ def unit_test(rootdir): import sys try: mi = MemoryInfo() - print("Numa nodes: %i" % mi.mem_get_numa_nodes()) - print("Memory: %i %s" % mi.mem_get_size()) + print(f"Numa nodes: {mi.mem_get_numa_nodes()}") + print(f"Memory: {int(mi.mem_get_size()[0])} {mi.mem_get_size()[1]}") except Exception as e: import traceback traceback.print_exc(file=sys.stdout)Signature · 1 line
2.31.1
PATCH v2 6/10 rteval: Use f-strings in osinfo
In reply to Anubhav ShelatUse f-strings in osinfo.py
--- rteval/sysinfo/osinfo.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
rteval/sysinfo/osinfo.py +6 -6
@@ -55,9 +55,9 @@ class OSInfo: shutil.copyfile(dpath, os.path.join(repdir, "dmesg")) return if os.path.exists('/usr/bin/dmesg'): - subprocess.call('/usr/bin/dmesg > %s' % os.path.join(repdir, "dmesg"), shell=True) + subprocess.call(f'/usr/bin/dmesg > {os.path.join(repdir, "dmesg")}', shell=True) return - print("dmesg file not found at %s and no dmesg exe found!" % dpath) + print(f"dmesg file not found at {dpath} and no dmesg exe found!")
@@ -69,16 +69,16 @@ class OSInfo: else: raise RuntimeError("Can't find sosreport/sysreport") - self.__logger.log(Log.DEBUG, "report tool: %s" % exe) + self.__logger.log(Log.DEBUG, f"report tool: {exe}") options = ['-k', 'rpm.rpmva=off', '--name=rteval', '--batch'] self.__logger.log(Log.INFO, "Generating SOS report") - self.__logger.log(Log.INFO, "using command %s" % " ".join([exe]+options)) + self.__logger.log(Log.INFO, f"using command {' '.join([exe]+options)}") subprocess.call([exe] + options) for s in glob('/tmp/s?sreport-rteval-*'): - self.__logger.log(Log.DEBUG, "moving %s to %s" % (s, repdir)) + self.__logger.log(Log.DEBUG, f"moving {s} to {repdir}") shutil.move(s, repdir)
@@ -118,7 +118,7 @@ def unit_test(rootdir): log = Log() log.SetLogVerbosity(Log.DEBUG|Log.INFO) osi = OSInfo(logger=log) - print("Base OS: %s" % osi.get_base_os()) + print(f"Base OS: {osi.get_base_os()}") print("Testing OSInfo::copy_dmesg('/tmp'): ", end=' ') osi.copy_dmesg('/tmp')
Signature · 1 line
2.31.1
Re: [PATCH v2 06/10] rteval: Use f-strings in osinfo
Quoted 56 lines · Anubhav Shelat
Use f-strings in
osinfo.pySigned-off-by Anubhav Shelat <[email protected]>--- rteval/sysinfo/osinfo.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)rteval/sysinfo/osinfo.py +6
-6@@ -55,9 +55,9 @@ class OSInfo: shutil.copyfile(dpath, os.path.join(repdir, "dmesg")) return if os.path.exists('/usr/bin/dmesg'): - subprocess.call('/usr/bin/dmesg > %s' % os.path.join(repdir, "dmesg"), shell=True) + subprocess.call(f'/usr/bin/dmesg > {os.path.join(repdir, "dmesg")}', shell=True) return - print("dmesg file not found at %s and no dmesg exe found!" % dpath) + print(f"dmesg file not found at {dpath} and no dmesg exe found!")@@ -69,16 +69,16 @@ class OSInfo: else: raise RuntimeError("Can't find sosreport/sysreport") - self.__logger.log(Log.DEBUG, "report tool: %s" % exe) + self.__logger.log(Log.DEBUG, f"report tool: {exe}") options = ['-k', 'rpm.rpmva=off', '--name=rteval', '--batch'] self.__logger.log(Log.INFO, "Generating SOS report") - self.__logger.log(Log.INFO, "using command %s" % " ".join([exe]+options)) + self.__logger.log(Log.INFO, f"using command {' '.join([exe]+options)}") subprocess.call([exe] + options) for s in glob('/tmp/s?sreport-rteval-*'): - self.__logger.log(Log.DEBUG, "moving %s to %s" % (s, repdir)) + self.__logger.log(Log.DEBUG, f"moving {s} to {repdir}") shutil.move(s, repdir)@@ -118,7 +118,7 @@ def unit_test(rootdir): log = Log() log.SetLogVerbosity(Log.DEBUG|Log.INFO) osi = OSInfo(logger=log) - print("Base OS: %s" % osi.get_base_os()) + print(f"Base OS: {osi.get_base_os()}") print("Testing OSInfo::copy_dmesg('/tmp'): ", end=' ') osi.copy_dmesg('/tmp')Signature · 1 line
2.31.1
PATCH v2 7/10 rteval: Use f-strings in services.py
In reply to Anubhav ShelatUse f-strings in services.py
--- rteval/sysinfo/services.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
rteval/sysinfo/services.py +6 -6
@@ -55,17 +55,17 @@ class SystemServices: break if not servicesdir: raise RuntimeError("No services dir (init.d) found on your system") - self.__log(Log.DEBUG, "Services located in %s, going through each service file to check status" % servicesdir) + self.__log(Log.DEBUG, f"Services located in {servicesdir}, going through each service file to check status") ret_services = {} for service in glob.glob(os.path.join(servicesdir, '*')): servicename = os.path.basename(service) if not [1 for p in reject if fnmatch.fnmatch(servicename, p)] \ and os.access(service, os.X_OK): - cmd = '%s -qs "\(^\|\W\)status)" %s' % (getcmdpath('grep'), service) + cmd = f'{getcmdpath("grep")} -qs "\(^\|\W\)status)" {service}' c = subprocess.Popen(cmd, shell=True, encoding='utf-8') c.wait() if c.returncode == 0: - cmd = ['env', '-i', 'LANG="%s"' % os.environ['LANG'], 'PATH="%s"' % os.environ['PATH'], 'TERM="%s"' % os.environ['TERM'], service, 'status'] + cmd = ['env', '-i', f'LANG="{os.environ["LANG"]}"', f'PATH="{os.environ["PATH"]}"', f'TERM="{os.environ["TERM"]}"', service, 'status'] c = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8') c.wait() if c.returncode == 0 and (c.stdout.read() or c.stderr.read()):
@@ -79,8 +79,8 @@ class SystemServices: def __get_services_systemd(self): ret_services = {} - cmd = '%s list-unit-files -t service --no-legend' % getcmdpath('systemctl') - self.__log(Log.DEBUG, "cmd: %s" % cmd) + cmd = f'{getcmdpath("systemctl")} list-unit-files -t service --no-legend' + self.__log(Log.DEBUG, f"cmd: {cmd}") c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8') for p in c.stdout: # p are lines like b'servicename.service status'
@@ -133,7 +133,7 @@ def unit_test(rootdir): return 0 except Exception as err: - print("** EXCEPTION: %s" % str(err)) + print(f"** EXCEPTION: {str(err)}") return 1
Signature · 1 line
2.31.1
Re: [PATCH v2 07/10] rteval: Use f-strings in services.py
Quoted 56 lines · Anubhav Shelat
Use f-strings in
services.pySigned-off-by Anubhav Shelat <[email protected]>--- rteval/sysinfo/services.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)rteval/sysinfo/services.py +6
-6@@ -55,17 +55,17 @@ class SystemServices: break if not servicesdir: raise RuntimeError("No services dir (init.d) found on your system") - self.__log(Log.DEBUG, "Services located in %s, going through each service file to check status" % servicesdir) + self.__log(Log.DEBUG, f"Services located in {servicesdir}, going through each service file to check status") ret_services = {} for service in glob.glob(os.path.join(servicesdir, '*')): servicename = os.path.basename(service) if not [1 for p in reject if fnmatch.fnmatch(servicename, p)] \ and os.access(service, os.X_OK): - cmd = '%s -qs "\(^\|\W\)status)" %s' % (getcmdpath('grep'), service) + cmd = f'{getcmdpath("grep")} -qs "\(^\|\W\)status)" {service}' c = subprocess.Popen(cmd, shell=True, encoding='utf-8') c.wait() if c.returncode == 0: - cmd = ['env', '-i', 'LANG="%s"' % os.environ['LANG'], 'PATH="%s"' % os.environ['PATH'], 'TERM="%s"' % os.environ['TERM'], service, 'status'] + cmd = ['env', '-i', f'LANG="{os.environ["LANG"]}"', f'PATH="{os.environ["PATH"]}"', f'TERM="{os.environ["TERM"]}"', service, 'status'] c = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8') c.wait() if c.returncode == 0 and (c.stdout.read() or c.stderr.read()):@@ -79,8 +79,8 @@ class SystemServices: def __get_services_systemd(self): ret_services = {} - cmd = '%s list-unit-files -t service --no-legend' % getcmdpath('systemctl') - self.__log(Log.DEBUG, "cmd: %s" % cmd) + cmd = f'{getcmdpath("systemctl")} list-unit-files -t service --no-legend' + self.__log(Log.DEBUG, f"cmd: {cmd}") c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8') for p in c.stdout: # p are lines like b'servicename.service status'@@ -133,7 +133,7 @@ def unit_test(rootdir): return 0 except Exception as err: - print("** EXCEPTION: %s" % str(err)) + print(f"** EXCEPTION: {str(err)}") return 1Signature · 1 line
2.31.1
PATCH v2 8/10 rteval: Use f-strings in tools.py
In reply to Anubhav ShelatUse f-strings in tools.py
--- rteval/sysinfo/tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rteval/sysinfo/tools.py +1 -1
@@ -40,5 +40,5 @@ def getcmdpath(which): pathSave[which] = cmdfile break if not pathSave[which]: - raise RuntimeError("Command '%s' is unknown on this system" % which) + raise RuntimeError(f"Command '{which}' is unknown on this system") return pathSave[which]
Signature · 1 line
2.31.1
Re: [PATCH v2 08/10] rteval: Use f-strings in tools.py
Quoted 22 lines · Anubhav Shelat
Use f-strings in
tools.pySigned-off-by Anubhav Shelat <[email protected]>--- rteval/sysinfo/tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)rteval/sysinfo/tools.py +1
-1@@ -40,5 +40,5 @@ def getcmdpath(which): pathSave[which] = cmdfile break if not pathSave[which]: - raise RuntimeError("Command '%s' is unknown on this system" % which) + raise RuntimeError(f"Command '{which}' is unknown on this system") return pathSave[which]Signature · 1 line
2.31.1
PATCH v2 9/10 Added code to check if the proc/net/if_inet6 file exists while loading IPv6 addresses in the IPv6Addresses class
In reply to Anubhav ShelatAdded code to check if the proc/net/if_inet6 file exists while loading IPv6 addresses in the IPv6Addresses class. If it doesn't, then the system has IPv6 disabled, and that chunk of code is passed.
--- rteval/sysinfo/newnet.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
rteval/sysinfo/newnet.py +16 -12
@@ -72,19 +72,23 @@ class IPv6Addresses(): and a list of ipv6addresses ''' MYP = '/proc/net/if_inet6' - with open(MYP, 'r') as f: - mystr = f.readline().strip() - while len(mystr) > 0: - ipv6addr , _, _, _, _, intf = mystr.split() - ipv6addr = compress_iv6(ipv6addr) - if intf == 'lo': - mystr = f.readline().strip() - continue - if intf not in self.data: - self.data[intf] = [ipv6addr] - else: - self.data[intf].append(ipv6addr) + try: + with open(MYP, 'r') as f: mystr = f.readline().strip() + while len(mystr) > 0: + ipv6addr , _, _, _, _, intf = mystr.split() + ipv6addr = compress_iv6(ipv6addr) + if intf == 'lo': + mystr = f.readline().strip() + continue + if intf not in self.data: + self.data[intf] = [ipv6addr] + else: + self.data[intf].append(ipv6addr) + mystr = f.readline().strip() + # if IPv6 is disabled, the if_net6 files does not exist, so we can pass + except FileNotFoundError: + pass class IPv4Addresses(): ''' Obtains a list of IPv4 addresses from the proc file system '''
Signature · 1 line
2.31.1
Re: [PATCH v2 09/10] Added code to check if the proc/net/if_inet6 file exists while loading IPv6 addresses in the IPv6Addresses class
Quoted 38 lines · Anubhav Shelat
Added code to check if the proc/net/if_inet6 file exists while loading IPv6 addresses in the IPv6Addresses class. If it doesn't, then the system has IPv6 disabled, and that chunk of code is passed.
Signed-off-by Anubhav Shelat <[email protected]>--- rteval/sysinfo/newnet.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)rteval/sysinfo/newnet.py +9
-12@@ -72,19 +72,23 @@ class IPv6Addresses(): and a list of ipv6addresses ''' MYP = '/proc/net/if_inet6' - with open(MYP, 'r') as f: - mystr = f.readline().strip() - while len(mystr) > 0: - ipv6addr , _, _, _, _, intf = mystr.split() - ipv6addr = compress_iv6(ipv6addr) - if intf == 'lo': - mystr = f.readline().strip() - continue - if intf not in self.data: - self.data[intf] = [ipv6addr] - else: - self.data[intf].append(ipv6addr) + try: + with open(MYP, 'r') as f: mystr = f.readline().strip() + while len(mystr) > 0: + ipv6addr , _, _, _, _, intf = mystr.split() + ipv6addr = compress_iv6(ipv6addr) + if intf == 'lo': + mystr = f.readline().strip() + continue + if intf not in self.data:
rteval/sysinfo/newnet.py class IPv6Addresses(): · line 94
Quoted 10 lines
rteval/sysinfo/newnet.py +7
-0+ self.data[intf] = [ipv6addr] + else: + self.data[intf].append(ipv6addr) + mystr = f.readline().strip() + # if IPv6 is disabled, the if_net6 files does not exist, so we can pass + except FileNotFoundError: + pass class IPv4Addresses(): ''' Obtains a list of IPv4 addresses from the proc file system '''
PATCH v2 10/10 rteval: Use f-strings in __init__.py
In reply to Anubhav ShelatUse f-strings in __init__.py
--- rteval/sysinfo/__init__.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
rteval/sysinfo/__init__.py +7 -11
@@ -83,27 +83,23 @@ if __name__ == "__main__": print(f"\tRunning on {si.get_base_os()}") print(f"\tNUMA nodes: {si.mem_get_numa_nodes()}") - print("\tMemory available: %03.2f %s\n" % si.mem_get_size()) + print(f"\tMemory available: {si.mem_get_size()[0]:03.2f} {si.mem_get_size()[1]}\n") print("\tServices: ") for (s, r) in list(si.services_get().items()): - print("\t\t%s: %s" % (s, r)) + print(f"\t\t{s}: {r}") (curr, avail) = si.kernel_get_clocksources() - print("\tCurrent clocksource: %s" % curr) - print("\tAvailable clocksources: %s" % avail) + print(f"\tCurrent clocksource: {curr}") + print(f"\tAvailable clocksources: {avail}") print("\tModules:") for m in si.kernel_get_modules(): - print("\t\t%s: %s" % (m['modname'], m['modstate'])) + print(f"\t\t{m['modname']}: {m['modstate']}") print("\tKernel threads:") for (p, i) in list(si.kernel_get_kthreads().items()): - print("\t\t%-30.30s pid: %-5.5s policy: %-7.7s prio: %-3.3s" % ( - str(i["name"])+":", p, i["policy"], i["priority"] - )) + print(f"\t\t{str(i['name'])[:30]+':':<30} pid: {str(p)[:5]:<5} policy: {str(i['policy'])[:7]:<7} prio: {str(i['priority'])[:3]:<3}") - print("\n\tCPU topology info - cores: %i online: %i sockets: %i" % ( - si.cpu_getCores(False), si.cpu_getCores(True), si.cpu_getSockets() - )) + print(f"\n\tCPU topology info - cores: {si.cpu_getCores(False)} online: {si.cpu_getCores(True)} sockets: {si.cpu_getSockets()}") xml = si.MakeReport() xml_d = libxml2.newDoc("1.0")
Signature · 1 line
2.31.1