Adapt all python code to PEP8 style standards

Signed-off-by: Kamil Lepek <kamil.lepek94@gmail.com>
This commit is contained in:
Kamil Lepek
2019-06-10 15:49:15 +02:00
parent 1e2b8f1980
commit e52d34c1c8
15 changed files with 822 additions and 765 deletions

View File

@@ -86,6 +86,7 @@ class CacheMode(IntEnum):
def read_insert(self):
return self.value not in [CacheMode.PT, CacheMode.WO]
class EvictionPolicy(IntEnum):
LRU = 0
DEFAULT = LRU
@@ -306,7 +307,7 @@ class Cache:
c.start_cache()
try:
c.load_cache(device)
except:
except: # noqa E722
c.stop()
raise
@@ -319,7 +320,7 @@ class Cache:
c.start_cache()
try:
c.attach_device(device, force=True)
except:
except: # noqa E722
c.stop()
raise
@@ -529,13 +530,12 @@ class Cache:
if c.results["error"]:
raise OcfError("Couldn't flush cache", c.results["error"])
def get_name(self):
self.read_lock()
try:
return str(self.owner.lib.ocf_cache_get_name(self), encoding="ascii")
except:
except: # noqa E722
raise OcfError("Couldn't get cache name")
finally:
self.read_unlock()

View File

@@ -56,7 +56,7 @@ class DataOps(Structure):
class Data:
DATA_POISON=0xA5
DATA_POISON = 0xA5
PAGE_SIZE = 4096
_instances_ = {}
@@ -109,7 +109,7 @@ class Data:
def from_string(cls, source: str, encoding: str = "ascii"):
b = bytes(source, encoding)
# duplicate string to fill space up to sector boundary
padding_len = S.from_B(len(b), sector_aligned = True).B - len(b)
padding_len = S.from_B(len(b), sector_aligned=True).B - len(b)
padding = b * (padding_len // len(b) + 1)
padding = padding[:padding_len]
b = b + padding

View File

@@ -92,7 +92,7 @@ class Io(Structure):
def end(self, err):
try:
self.callback(err)
except:
except: # noqa E722
pass
self.put()

View File

@@ -36,6 +36,7 @@ def io_queue_run(*, queue: Queue, kick: Condition, stop: Event):
if stop.is_set() and not OcfLib.getInstance().ocf_queue_pending_io(queue):
break
class Queue:
_instances_ = {}
@@ -102,4 +103,3 @@ class Queue:
self.kick_condition.notify_all()
self.thread.join()

View File

@@ -102,7 +102,7 @@ class SharedOcfObject(Structure):
def get_instance(cls, ref: int):
try:
return cls._instances_[ref]
except:
except: # noqa E722
logging.getLogger("pyocf").error(
"OcfSharedObject corruption. wanted: {} instances: {}".format(
ref, cls._instances_

View File

@@ -74,7 +74,7 @@ class VolumeIoPriv(Structure):
class Volume(Structure):
VOLUME_POISON=0x13
VOLUME_POISON = 0x13
_fields_ = [("_storage", c_void_p)]
_instances_ = {}
@@ -184,7 +184,7 @@ class Volume(Structure):
uuid = str(uuid_ptr.contents._data, encoding="ascii")
try:
volume = Volume.get_by_uuid(uuid)
except:
except: # noqa E722 TODO:Investigate whether this really should be so broad
print("Tried to access unallocated volume {}".format(uuid))
print("{}".format(Volume._uuid_))
return -1
@@ -255,7 +255,7 @@ class Volume(Structure):
memset(dst, 0, discard.contents._bytes)
discard.contents._end(discard, 0)
except:
except: # noqa E722
discard.contents._end(discard, -5)
def get_stats(self):
@@ -269,8 +269,7 @@ class Volume(Structure):
self.stats[IoDir(io.contents._dir)] += 1
io_priv = cast(
OcfLib.getInstance().ocf_io_get_priv(io), POINTER(VolumeIoPriv)
)
OcfLib.getInstance().ocf_io_get_priv(io), POINTER(VolumeIoPriv))
offset = io_priv.contents._offset
if io.contents._dir == IoDir.WRITE:
@@ -286,7 +285,7 @@ class Volume(Structure):
io_priv.contents._offset += io.contents._bytes
io.contents._end(io, 0)
except:
except: # noqa E722
io.contents._end(io, -5)
def dump(self, offset=0, size=0, ignore=VOLUME_POISON, **kwargs):
@@ -325,10 +324,11 @@ class ErrorDevice(Volume):
super().reset_stats()
self.stats["errors"] = {IoDir.WRITE: 0, IoDir.READ: 0}
class TraceDevice(Volume):
def __init__(self, size, trace_fcn=None, uuid=None):
super().__init__(size, uuid)
self.trace_fcn=trace_fcn
self.trace_fcn = trace_fcn
def submit_io(self, io):
submit = True

View File

@@ -6,7 +6,8 @@
from ctypes import string_at
def print_buffer(buf, length, offset=0, width=16, ignore=0, stop_after_count_ignored=0, print_fcn=print):
def print_buffer(buf, length, offset=0, width=16, ignore=0,
stop_after_count_ignored=0, print_fcn=print):
end = int(offset) + int(length)
offset = int(offset)
ignored_lines = 0
@@ -15,16 +16,13 @@ def print_buffer(buf, length, offset=0, width=16, ignore=0, stop_after_count_ign
stop_after_count_ignored = int(stop_after_count_ignored / width)
for addr in range(offset, end, width):
cur_line = buf[addr : min(end, addr + width)]
cur_line = buf[addr: min(end, addr + width)]
byteline = ""
asciiline = ""
if not any(x != ignore for x in cur_line):
if stop_after_count_ignored and ignored_lines > stop_after_count_ignored:
print_fcn(
"<{} bytes of '0x{:02X}' encountered, stopping>".format(
stop_after_count_ignored * width, ignore
)
)
print_fcn("<{} bytes of '0x{:02X}' encountered, stopping>".
format(stop_after_count_ignored * width, ignore))
return
ignored_lines += 1
continue
@@ -71,23 +69,23 @@ class Size:
return self.bytes
@classmethod
def from_B(cls, value, sector_aligned = False):
def from_B(cls, value, sector_aligned=False):
return cls(value, sector_aligned)
@classmethod
def from_KiB(cls, value, sector_aligned = False):
def from_KiB(cls, value, sector_aligned=False):
return cls(value * cls._KiB, sector_aligned)
@classmethod
def from_MiB(cls, value, sector_aligned = False):
def from_MiB(cls, value, sector_aligned=False):
return cls(value * cls._MiB, sector_aligned)
@classmethod
def from_GiB(cls, value, sector_aligned = False):
def from_GiB(cls, value, sector_aligned=False):
return cls(value * cls._GiB, sector_aligned)
@classmethod
def from_TiB(cls, value, sector_aligned = False):
def from_TiB(cls, value, sector_aligned=False):
return cls(value * cls._TiB, sector_aligned)
@classmethod