Skip to content

Commit

Permalink
Apply black
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagocoutinho committed Oct 14, 2023
1 parent a087b28 commit f3b87fa
Show file tree
Hide file tree
Showing 11 changed files with 32,072 additions and 26,868 deletions.
5 changes: 4 additions & 1 deletion examples/video/tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ def update(cam, mask=None):


import argparse

parser = argparse.ArgumentParser("v4l2-tk")
parser.add_argument("-d", "--device", type=int, default=0)
parser.add_argument("-s", "--source", choices=["auto", "stream", "read"], default="auto")
parser.add_argument(
"-s", "--source", choices=["auto", "stream", "read"], default="auto"
)
args = parser.parse_args()
if args.source == "auto":
source = None
Expand Down
13 changes: 11 additions & 2 deletions linuxpy/codegen/usbfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,19 @@ class usb_hid_descriptor(Struct):
# macros from #define statements
MACRO_ENUMS = [
CEnum("URBType", "USBDEVFS_URB_TYPE_"),
CEnum("URB", "USBDEVFS_URB_", "IntFlag", filter=lambda name, _: not name.startswith("USBDEVFS_USB_TYPE_")),
CEnum(
"URB",
"USBDEVFS_URB_",
"IntFlag",
filter=lambda name, _: not name.startswith("USBDEVFS_USB_TYPE_"),
),
CEnum("Capability", "USBDEVFS_CAP_", "IntFlag"),
CEnum("DisconnectClaim", "USBDEVFS_DISCONNECT_CLAIM_", "IntFlag"),
CEnum("IOC", "USBDEVFS_", filter=lambda name, value: "_IO" in value and not name.endswith("32")),
CEnum(
"IOC",
"USBDEVFS_",
filter=lambda name, value: "_IO" in value and not name.endswith("32"),
),
CEnum("Direction", "USB_DIR_"),
CEnum("RequestType", "USB_TYPE_"),
CEnum("Recipient", "USB_RECIP_"),
Expand Down
21 changes: 10 additions & 11 deletions linuxpy/codegen/usbids.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

# run with:
#
#

import pathlib
import pprint
Expand All @@ -21,7 +20,7 @@ def get_raw(url: str = USB_IDS) -> str:
return response.text


def get(url: str = USB_IDS) -> dict[int, ]:
def get(url: str = USB_IDS) -> dict[int,]:
raw = get_raw(url=url)

items = {}
Expand All @@ -30,7 +29,7 @@ def get(url: str = USB_IDS) -> dict[int, ]:
if line.startswith("#"):
continue
if line.startswith("\t\t"): # Interface, protocol, etc
l2_id, l2_name = line.strip().split(" ", 1)
l2_id, l2_name = line.strip().split(" ", 1)
l2_id = int(l2_id, 16)
l2 = {"name": l2_name}
l1.setdefault("children", {})[l2_id] = l2
Expand All @@ -39,12 +38,12 @@ def get(url: str = USB_IDS) -> dict[int, ]:
l1_id = int(l1_id, 16)
l1 = {"name": l1_name}
l0.setdefault("children", {})[l1_id] = l1
elif line: # Vendor, class, audio terminal, etc
elif line: # Vendor, class, audio terminal, etc
l0_id, l0_name = line.split(" ", 1)
if ' ' in l0_id:
itype, l0_id = l0_id.split(' ', 1)
if " " in l0_id:
itype, l0_id = l0_id.split(" ", 1)
else:
itype = 'V' # Vendors don't have prefix
itype = "V" # Vendors don't have prefix
l0_id = int(l0_id, 16)
l0 = {"name": l0_name}
items.setdefault(itype, {})[l0_id] = l0
Expand All @@ -67,10 +66,10 @@ def get(url: str = USB_IDS) -> dict[int, ]:
"""


def dump_items(items, path = this_dir.parent / "usb" / "usbids.py"):
def dump_items(items, path=this_dir.parent / "usb" / "usbids.py"):
path = pathlib.Path(path)
fields = {
"name": 'linuxpy.codegen.usbids',
"name": "linuxpy.codegen.usbids",
"date": datetime.datetime.now(),
"system": platform.system(),
"release": platform.release(),
Expand All @@ -90,4 +89,4 @@ def main():


if __name__ == "__main__":
main()
main()
2 changes: 1 addition & 1 deletion linuxpy/ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ class timespec(Struct):
]


c = ctypes.cdll.LoadLibrary('libc.so.6')
c = ctypes.cdll.LoadLibrary("libc.so.6")
1 change: 1 addition & 0 deletions linuxpy/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def opener(path, flags):
if close_on_exec:
flags |= os.O_CLOEXEC
return os.open(path, flags)

kwargs = {"buffering": 0, "opener": opener}
flgs = "rb" if binary else "r"
if rw:
Expand Down
2 changes: 1 addition & 1 deletion linuxpy/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

release = platform.release()

VERSION = tuple(int(i) for i in release.split('-')[0].split('.'))
VERSION = tuple(int(i) for i in release.split("-")[0].split("."))
1 change: 0 additions & 1 deletion linuxpy/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,3 @@ class Magic(enum.IntEnum):
PPC_CMM = 0xC7571590
SECRETMEM = 0x5345434D # "SECM"
SHIFTFS = 0x6A656A62

76 changes: 42 additions & 34 deletions linuxpy/statfs.py
Original file line number Diff line number Diff line change
@@ -1,66 +1,74 @@
import enum
import functools

from .ctypes import Struct, POINTER, pointer, culong, cint, cuint, ccharp, fsblkcnt, fsfilcnt, c
from .ctypes import (
Struct,
POINTER,
pointer,
culong,
cint,
cuint,
ccharp,
fsblkcnt,
fsfilcnt,
c,
)
from .magic import Magic


class fsid(Struct):
_fields_ = [
("val", cint * 2)
]
_fields_ = [("val", cint * 2)]


class statfs(Struct):
_fields_ = [
("f_type", cuint), # Type of filesystem (see below)
("f_bsize", cuint), # Optimal transfer block size
("f_type", cuint), # Type of filesystem (see below)
("f_bsize", cuint), # Optimal transfer block size
("f_blocks", fsblkcnt), # Total data blocks in filesystem
("f_bfree", fsblkcnt), # Free blocks in filesystem
("f_bfree", fsblkcnt), # Free blocks in filesystem
("f_bavail", fsblkcnt), # Free blocks available to unprivileged user
("f_files", fsfilcnt), # Total file nodes in filesystem
("f_ffree", fsfilcnt), # Free file nodes in filesystem
("f_fsid", fsid), # Filesystem ID
("f_namelen", cuint), # Maximum length of filenames
("f_frsize", cuint), # Fragment size (since Linux 2.6)
("f_flags", cuint), # Mount flags of filesystem (since Linux 2.6.36)
("f_files", fsfilcnt), # Total file nodes in filesystem
("f_ffree", fsfilcnt), # Free file nodes in filesystem
("f_fsid", fsid), # Filesystem ID
("f_namelen", cuint), # Maximum length of filenames
("f_frsize", cuint), # Fragment size (since Linux 2.6)
("f_flags", cuint), # Mount flags of filesystem (since Linux 2.6.36)
# Setting f_spare to 4 * int was giving me segfault
("f_spare", cuint * 16), # Padding bytes reserved for future use

("f_spare", cuint * 16), # Padding bytes reserved for future use
]


class statvfs(Struct):
_fields_ = [
("f_bsize", culong), # Filesystem block size
("f_frsize", culong), # Fragment size
("f_bsize", culong), # Filesystem block size
("f_frsize", culong), # Fragment size
("f_blocks", fsblkcnt), # Size of fs in f_frsize units
("f_bfree", fsblkcnt), # Number of free blocks
("f_bfree", fsblkcnt), # Number of free blocks
("f_bavail", fsblkcnt), # Number of free blocks for unprivileged user
("f_files", fsfilcnt), # Number of inodes
("f_ffree", fsfilcnt), # Number of free inodes
("f_files", fsfilcnt), # Number of inodes
("f_ffree", fsfilcnt), # Number of free inodes
("f_favail", fsfilcnt), # Number of free inodes for unprivileged user
("f_fsid", culong), # Filesystem ID
("f_flag", culong), # Mount flags
("f_namemax", culong), # Maximum filename length
("f_fsid", culong), # Filesystem ID
("f_flag", culong), # Mount flags
("f_namemax", culong), # Maximum filename length
]


class Flag(enum.IntFlag):
RDONLY = 0x0001 # mount read-only
NOSUID = 0x0002 # ignore suid and sgid bits
NODEV = 0x0004 # disallow access to device special files
NOEXEC = 0x0008 # disallow program execution
SYNCHRONOUS = 0x0010 # writes are synced at once
VALID = 0x0020 # f_flags support is implemented
MANDLOCK = 0x0040 # allow mandatory locks on an FS
RDONLY = 0x0001 # mount read-only
NOSUID = 0x0002 # ignore suid and sgid bits
NODEV = 0x0004 # disallow access to device special files
NOEXEC = 0x0008 # disallow program execution
SYNCHRONOUS = 0x0010 # writes are synced at once
VALID = 0x0020 # f_flags support is implemented
MANDLOCK = 0x0040 # allow mandatory locks on an FS
# 0x0080 used for ST_WRITE in glibc
# 0x0100 used for ST_APPEND in glibc
# 0x0200 used for ST_IMMUTABLE in glibc
NOATIME = 0x0400 # do not update access times
NODIRATIME = 0x0800 # do not update directory access times
RELATIME = 0x1000 # update atime relative to mtime/ctime
NOSYMFOLLOW = 0x2000 # do not follow symlinks
NOATIME = 0x0400 # do not update access times
NODIRATIME = 0x0800 # do not update directory access times
RELATIME = 0x1000 # update atime relative to mtime/ctime
NOSYMFOLLOW = 0x2000 # do not follow symlinks


c.statfs.argtypes = [ccharp, POINTER(statfs)]
Expand Down
2 changes: 1 addition & 1 deletion linuxpy/sysfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ def is_sysfs(path) -> bool:


def is_available() -> bool:
return is_sysfs(MOUNT_PATH)
return is_sysfs(MOUNT_PATH)
Loading

0 comments on commit f3b87fa

Please sign in to comment.