From 4a312ce2df04e5bad5a4e7775e3dedf2907f13f2 Mon Sep 17 00:00:00 2001 From: Heiko Thiery Date: Sun, 16 Sep 2018 21:55:07 +0200 Subject: [PATCH] change methods that could be a function add @staticmethod Signed-off-by: Heiko Thiery --- pyipmi/errors.py | 3 ++- pyipmi/hpm.py | 24 +++++++++++++++--------- pyipmi/interfaces/aardvark.py | 6 ++++-- pyipmi/interfaces/ipmitool.py | 10 ++++++---- pyipmi/msgs/message.py | 3 ++- pyipmi/sdr.py | 1 + pyipmi/sel.py | 13 +++++++------ 7 files changed, 37 insertions(+), 23 deletions(-) diff --git a/pyipmi/errors.py b/pyipmi/errors.py index cd481534..c86b897c 100644 --- a/pyipmi/errors.py +++ b/pyipmi/errors.py @@ -40,7 +40,8 @@ def __init__(self, cc): def __str__(self): return "%s cc=0x%02x desc=%s" % (self.__class__.__name__, self.cc, self.cc_desc) - def find_cc_desc(self, error_cc): + @staticmethod + def find_cc_desc(error_cc): for cc in cc_err_desc: if error_cc == cc[0]: return cc[1] diff --git a/pyipmi/hpm.py b/pyipmi/hpm.py index 27ec7789..6584b64b 100644 --- a/pyipmi/hpm.py +++ b/pyipmi/hpm.py @@ -65,7 +65,8 @@ class Hpm(object): - def _get_component_count(self, components): + @staticmethod + def _get_component_count(components): """Return the number of components""" return bin(components).count('1') @@ -140,7 +141,8 @@ def upload_firmware_block(self, block_number, data): self.send_message_with_name('UploadFirmwareBlock', number=block_number, data=data) - def _determine_max_block_size(self): + @staticmethod + def _determine_max_block_size(): #tbd return 22 @@ -248,28 +250,32 @@ def initiate_manual_rollback_and_wait(self, timeout=2, interval=0.1): # controller is in reset and flashed new firmware pass - def open_upgrade_image(self, filename): - image = UpgradeImage(filename) - return image + @staticmethod + def open_upgrade_image(filename): + return UpgradeImage(filename) - def get_upgrade_version_from_file(self, filename): + @staticmethod + def get_upgrade_version_from_file(filename): image = UpgradeImage(filename) for action in image.actions: if type(action) == UpgradeActionRecordUploadForUpgrade: return action.firmware_version return None - def _do_upgrade_action_backup(self, image): + @staticmethod + def _do_upgrade_action_backup(image): for action in image.actions: if type(action) == UpgradeActionRecordBackup: pass - def _do_upgrade_action_prepare(self, image): + @staticmethod + def _do_upgrade_action_prepare(image): for action in image.actions: if type(action) == UpgradeActionRecordPrepare: print("do ACTION_PREPARE_COMPONENT") - def _do_upgrade_action_upload(self, image): + @staticmethod + def _do_upgrade_action_upload(image): for action in image.actions: if type(action) == UpgradeActionRecordUploadForUpgrade: print("do ACTION_UPLOAD_FOR_UPGRADE") diff --git a/pyipmi/interfaces/aardvark.py b/pyipmi/interfaces/aardvark.py index fda4909c..cd949585 100644 --- a/pyipmi/interfaces/aardvark.py +++ b/pyipmi/interfaces/aardvark.py @@ -78,14 +78,16 @@ def is_ipmc_accessible(self, target): def _inc_sequence_number(self): self.next_sequence_number = (self.next_sequence_number + 1) % 64 - def _encode_ipmb_msg_req(self, header, cmd_data): + @staticmethod + def _encode_ipmb_msg_req(header, cmd_data): data = header.encode() data.extend(cmd_data) data.append(checksum(data[2:])) return data - def _rx_filter(self, header, rx_data): + @staticmethod + def _rx_filter(header, rx_data): log().debug('[%s]' % ' '.join(['%02x' % b for b in rx_data])) diff --git a/pyipmi/interfaces/ipmitool.py b/pyipmi/interfaces/ipmitool.py index 249621a6..88e48a66 100644 --- a/pyipmi/interfaces/ipmitool.py +++ b/pyipmi/interfaces/ipmitool.py @@ -137,12 +137,14 @@ def send_and_receive(self, req): return rsp - def _build_ipmitool_raw_data(self, lun, netfn, raw_bytes): + @staticmethod + def _build_ipmitool_raw_data(lun, netfn, raw_bytes): cmd_data = ' -l %d raw 0x%02x ' % (lun, netfn) cmd_data += ' '.join(['0x%02x' % ord(d) for d in raw_bytes]) return cmd_data - def _build_ipmitool_target(self, target): + @staticmethod + def _build_ipmitool_target(target): cmd = '' if hasattr(target, 'routing'): # we have to do bridging here @@ -205,7 +207,8 @@ def _build_serial_ipmitool_cmd(self, target, lun, netfn, raw_bytes): return cmd - def _run_ipmitool(self, cmd): + @staticmethod + def _run_ipmitool(cmd): """Legacy call of ipmitool (will be removed in future). """ @@ -218,4 +221,3 @@ def _run_ipmitool(self, cmd): output) return output, child.returncode - diff --git a/pyipmi/msgs/message.py b/pyipmi/msgs/message.py index 7a3e34d6..d3d9471d 100644 --- a/pyipmi/msgs/message.py +++ b/pyipmi/msgs/message.py @@ -183,7 +183,8 @@ def encode(self, obj, data): if getattr(obj, self._field.name) is not None: self._field.encode(obj, data) - def create(self): + @staticmethod + def create(): return None diff --git a/pyipmi/sdr.py b/pyipmi/sdr.py index 065ee184..5bb6a237 100644 --- a/pyipmi/sdr.py +++ b/pyipmi/sdr.py @@ -318,6 +318,7 @@ def l(self): raise errors.DecodingError('unknown linearization %d' % (self.linearization & 0x7f)) + @staticmethod def _convert_complement(self, value, size): if (value & (1 << (size-1))): value = -(1<