No need for explicit string conversion

This commit is contained in:
Fabien Castan 2025-04-14 11:09:12 +02:00
parent 51b04bc077
commit 4e1182c3dc
5 changed files with 16 additions and 16 deletions

View file

@ -91,7 +91,7 @@ def loadPlugins(folder, packageName, classType):
if importPlugin: if importPlugin:
pluginTypes.extend(plugins) pluginTypes.extend(plugins)
except Exception as e: except Exception as e:
errors.append(f' * {pluginName}: {str(e)}') errors.append(f' * {pluginName}: {e}')
if errors: if errors:
logging.warning('== The following "{package}" plugins could not be loaded ==\n' logging.warning('== The following "{package}" plugins could not be loaded ==\n'

View file

@ -737,7 +737,7 @@ class Graph(BaseObject):
try: try:
self.addEdge(self.attribute(srcName), self.attribute(dstName)) self.addEdge(self.attribute(srcName), self.attribute(dstName))
except (KeyError, ValueError) as e: except (KeyError, ValueError) as e:
logging.warning(f"Failed to restore edge {srcName} -> {dstName}: {str(e)}") logging.warning(f"Failed to restore edge {srcName} -> {dstName}: {e}")
def upgradeAllNodes(self): def upgradeAllNodes(self):
""" Upgrade all upgradable CompatibilityNode instances in the graph. """ """ Upgrade all upgradable CompatibilityNode instances in the graph. """

View file

@ -84,7 +84,7 @@ class ComputerStatistics:
self._addKV('ioCounters', psutil.disk_io_counters()) self._addKV('ioCounters', psutil.disk_io_counters())
self.updateGpu() self.updateGpu()
except Exception as e: except Exception as e:
logging.debug(f'Failed to get statistics: "{str(e)}".') logging.debug(f'Failed to get statistics: "{e}".')
def updateGpu(self): def updateGpu(self):
if not self.nvidia_smi: if not self.nvidia_smi:
@ -99,38 +99,38 @@ class ComputerStatistics:
try: try:
self.gpuName = gpuTree.find('product_name').text self.gpuName = gpuTree.find('product_name').text
except Exception as e: except Exception as e:
logging.debug(f'Failed to get gpuName: "{str(e)}".') logging.debug(f'Failed to get gpuName: "{e}".')
pass pass
try: try:
gpuMemoryUsed = gpuTree.find('fb_memory_usage').find('used').text.split(" ")[0] gpuMemoryUsed = gpuTree.find('fb_memory_usage').find('used').text.split(" ")[0]
self._addKV('gpuMemoryUsed', gpuMemoryUsed) self._addKV('gpuMemoryUsed', gpuMemoryUsed)
except Exception as e: except Exception as e:
logging.debug(f'Failed to get gpuMemoryUsed: "{str(e)}".') logging.debug(f'Failed to get gpuMemoryUsed: "{e}".')
pass pass
try: try:
self.gpuMemoryTotal = gpuTree.find('fb_memory_usage').find('total').text.split(" ")[0] self.gpuMemoryTotal = gpuTree.find('fb_memory_usage').find('total').text.split(" ")[0]
except Exception as e: except Exception as e:
logging.debug(f'Failed to get gpuMemoryTotal: "{str(e)}".') logging.debug(f'Failed to get gpuMemoryTotal: "{e}".')
pass pass
try: try:
gpuUsed = gpuTree.find('utilization').find('gpu_util').text.split(" ")[0] gpuUsed = gpuTree.find('utilization').find('gpu_util').text.split(" ")[0]
self._addKV('gpuUsed', gpuUsed) self._addKV('gpuUsed', gpuUsed)
except Exception as e: except Exception as e:
logging.debug(f'Failed to get gpuUsed: "{str(e)}".') logging.debug(f'Failed to get gpuUsed: "{e}".')
pass pass
try: try:
gpuTemperature = gpuTree.find('temperature').find('gpu_temp').text.split(" ")[0] gpuTemperature = gpuTree.find('temperature').find('gpu_temp').text.split(" ")[0]
self._addKV('gpuTemperature', gpuTemperature) self._addKV('gpuTemperature', gpuTemperature)
except Exception as e: except Exception as e:
logging.debug(f'Failed to get gpuTemperature: "{str(e)}".') logging.debug(f'Failed to get gpuTemperature: "{e}".')
pass pass
except subprocess.TimeoutExpired as e: except subprocess.TimeoutExpired as e:
logging.debug(f'Timeout when retrieving information from nvidia_smi: "{str(e)}".') logging.debug(f'Timeout when retrieving information from nvidia_smi: "{e}".')
p.kill() p.kill()
outs, errs = p.communicate() outs, errs = p.communicate()
return return
except Exception as e: except Exception as e:
logging.debug(f'Failed to get information from nvidia_smi: "{str(e)}".') logging.debug(f'Failed to get information from nvidia_smi: "{e}".')
return return
def toDict(self): def toDict(self):
@ -270,15 +270,15 @@ class Statistics:
try: try:
self.computer.fromDict(d.get('computer', {})) self.computer.fromDict(d.get('computer', {}))
except Exception as e: except Exception as e:
logging.debug(f'Failed while loading statistics: computer: "{str(e)}".') logging.debug(f'Failed while loading statistics: computer: "{e}".')
try: try:
self.process.fromDict(d.get('process', {})) self.process.fromDict(d.get('process', {}))
except Exception as e: except Exception as e:
logging.debug(f'Failed while loading statistics: process: "{str(e)}".') logging.debug(f'Failed while loading statistics: process: "{e}".')
try: try:
self.times = d.get('times', []) self.times = d.get('times', [])
except Exception as e: except Exception as e:
logging.debug(f'Failed while loading statistics: times: "{str(e)}".') logging.debug(f'Failed while loading statistics: times: "{e}".')
bytesPerGiga = 1024. * 1024. * 1024. bytesPerGiga = 1024. * 1024. * 1024.

View file

@ -77,7 +77,7 @@ class CsvData(QObject):
for idx, value in enumerate(elt): for idx, value in enumerate(elt):
dataList[idx].appendValue(value) dataList[idx].appendValue(value)
except Exception as e: except Exception as e:
logging.error(f"CsvData: Failed to load file: {self._filepath}\n{str(e)}") logging.error(f"CsvData: Failed to load file: {self._filepath}\n{e}")
return dataList return dataList

View file

@ -225,7 +225,7 @@ class ViewpointWrapper(QObject):
# When the viewpoint attribute has already been deleted, metadata.value becomes a PySide property (whereas a string is expected) # When the viewpoint attribute has already been deleted, metadata.value becomes a PySide property (whereas a string is expected)
self._metadata = json.loads(self._viewpoint.metadata.value) if isinstance(self._viewpoint.metadata.value, str) and self._viewpoint.metadata.value else None self._metadata = json.loads(self._viewpoint.metadata.value) if isinstance(self._viewpoint.metadata.value, str) and self._viewpoint.metadata.value else None
except Exception as e: except Exception as e:
logging.warning(f"Failed to parse Viewpoint metadata: '{str(e)}', '{str(self._viewpoint.metadata.value)}'") logging.warning(f"Failed to parse Viewpoint metadata: '{e}', '{str(self._viewpoint.metadata.value)}'")
self._metadata = {} self._metadata = {}
if not self._metadata: if not self._metadata:
self._metadata = {} self._metadata = {}
@ -974,7 +974,7 @@ class Reconstruction(UIGraph):
# Retrieve the list of updated viewpoints and intrinsics # Retrieve the list of updated viewpoints and intrinsics
views, intrinsics = cameraInitCopy.nodeDesc.buildIntrinsics(cameraInitCopy, additionalViews) views, intrinsics = cameraInitCopy.nodeDesc.buildIntrinsics(cameraInitCopy, additionalViews)
except Exception as e: except Exception as e:
logging.error(f"Error while building intrinsics: {str(e)}") logging.error(f"Error while building intrinsics: {e}")
raise raise
finally: finally:
# Delete the duplicate # Delete the duplicate