Skip to content

Commit 833e7fe

Browse files
authored
Change linter to Ruff (#35)
1 parent 13e1c48 commit 833e7fe

12 files changed

+274
-207
lines changed

dissect/vmfs/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
from dissect.vmfs.vmfs import VMFS
1010

1111
__all__ = [
12+
"LVM",
13+
"VMFS",
1214
"Error",
15+
"Extent",
1316
"FileNotFoundError",
1417
"InvalidHeader",
1518
"NotADirectoryError",
1619
"NotASymlinkError",
17-
"LVM",
18-
"Extent",
19-
"VMFS",
2020
]

dissect/vmfs/c_vmfs.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import stat
24
import struct
35

@@ -375,21 +377,22 @@
375377
FileType = c_vmfs.FileType
376378

377379

378-
def bsf(value, size=32):
380+
def bsf(value: int, size: int = 32) -> int:
379381
"""Count the number of zero bits in an integer of a given size."""
380382
for i in range(size):
381383
if value & (1 << i):
382384
return i
385+
return 0
383386

384387

385-
def type_to_mode(type_):
388+
def type_to_mode(type_: FileType) -> int:
386389
if type_ == FileType.Directory:
387390
return stat.S_IFDIR
388-
elif type_ == FileType.Symlink:
391+
if type_ == FileType.Symlink:
389392
return stat.S_IFLNK
390393
return stat.S_IFREG
391394

392395

393-
def vmfs_uuid(buf):
396+
def vmfs_uuid(buf: bytes) -> str:
394397
uuid1, uuid2, uuid3, uuid4 = struct.unpack("<IIH6s", buf)
395398
return f"{uuid1:08x}-{uuid2:08x}-{uuid3:04x}-{uuid4.hex()}"

dissect/vmfs/lvm.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# References:
22
# - /usr/lib/vmware/vmkmod/lvmdriver
3+
from __future__ import annotations
34

45
from bisect import bisect_right
6+
from typing import BinaryIO
57

68
from dissect.util.stream import AlignedStream
79

@@ -26,8 +28,8 @@ class LVM(AlignedStream):
2628
VMFS should start at LVM dataOffset + 0x200000
2729
"""
2830

29-
def __init__(self, fh):
30-
fhs = [fh] if not type(fh) is list else fh
31+
def __init__(self, fh: BinaryIO | list[BinaryIO]):
32+
fhs = [fh] if type(fh) is not list else fh
3133

3234
size = None
3335
self.uuid = None
@@ -56,7 +58,7 @@ def __init__(self, fh):
5658

5759
super().__init__(size)
5860

59-
def _read(self, offset, length):
61+
def _read(self, offset: int, length: int) -> bytes:
6062
r = []
6163

6264
pe_offset = offset // VMFS_LVM_PE_SIZE
@@ -93,7 +95,7 @@ class Extent(AlignedStream):
9395
- 0x900000
9496
"""
9597

96-
def __init__(self, fh):
98+
def __init__(self, fh: BinaryIO):
9799
self.fh = fh
98100

99101
fh.seek(c_vmfs.VMFS_LVM_DEVICE_META_BASE)
@@ -126,6 +128,6 @@ def __init__(self, fh):
126128

127129
super().__init__(self.metadata.volumeSize)
128130

129-
def _read(self, offset, length):
131+
def _read(self, offset: int, length: int) -> bytes:
130132
self.fh.seek(self.metadata.dataOffset + offset)
131133
return self.fh.read(length)

0 commit comments

Comments
 (0)