diff --git a/examples/v4l2py-ctl.py b/examples/v4l2py-ctl.py index dc25f34..4e08160 100644 --- a/examples/v4l2py-ctl.py +++ b/examples/v4l2py-ctl.py @@ -155,7 +155,9 @@ def save_to_file(device: str, legacy_controls: bool, filename) -> None: elif isinstance(filename, str): filename = pathlib.Path(filename) else: - raise TypeError(f"filename expected to be str or pathlib.Path, not {filename.__class__.__name__}") + raise TypeError( + f"filename expected to be str or pathlib.Path, not {filename.__class__.__name__}" + ) with Device(device, legacy_controls) as cam: print(f"Saving device configuration to {filename.resolve()}") @@ -165,13 +167,17 @@ def save_to_file(device: str, legacy_controls: bool, filename) -> None: print("") -def load_from_file(device: str, legacy_controls: bool, filename, pedantic: bool) -> None: +def load_from_file( + device: str, legacy_controls: bool, filename, pedantic: bool +) -> None: if isinstance(filename, pathlib.Path): pass elif isinstance(filename, str): filename = pathlib.Path(filename) else: - raise TypeError(f"filename expected to be str or pathlib.Path, not {filename.__class__.__name__}") + raise TypeError( + f"filename expected to be str or pathlib.Path, not {filename.__class__.__name__}" + ) with Device(device, legacy_controls) as cam: print(f"Loading device configuration from {filename.resolve()}") @@ -218,7 +224,7 @@ def csv(string: str) -> list: "--pedantic", default=False, action="store_true", - help="be pedantic when validating a loaded configuration (default: %(default)s)" + help="be pedantic when validating a loaded configuration (default: %(default)s)", ) actions = parser.add_argument_group("Actions") diff --git a/v4l2py/config.py b/v4l2py/config.py index af30ffb..56462da 100644 --- a/v4l2py/config.py +++ b/v4l2py/config.py @@ -34,7 +34,10 @@ def __init__(self, device: Device): @property def has_config(self) -> bool: - return isinstance(self.config, configparser.ConfigParser) and self.config.sections() + return ( + isinstance(self.config, configparser.ConfigParser) + and self.config.sections() + ) @property def config_loaded(self) -> bool: @@ -68,7 +71,9 @@ def save(self, filename) -> None: elif isinstance(filename, str): filename = pathlib.Path(filename) else: - raise TypeError(f"filename expected to be str or pathlib.Path, not {filename.__class__.__name__}") + raise TypeError( + f"filename expected to be str or pathlib.Path, not {filename.__class__.__name__}" + ) if self.device.closed: raise V4L2Error(f"{self.device} must be opened to save configuration") @@ -86,7 +91,9 @@ def load(self, filename) -> None: elif isinstance(filename, str): filename = pathlib.Path(filename) else: - raise TypeError(f"filename expected to be str or pathlib.Path, not {filename.__class__.__name__}") + raise TypeError( + f"filename expected to be str or pathlib.Path, not {filename.__class__.__name__}" + ) if not (filename.exists() and filename.is_file()): raise RuntimeError(f"{filename} must be an existing file") @@ -113,12 +120,14 @@ def validate(self, pedantic: bool = False) -> None: controls = self.device.controls.named_keys() for ctrl, _ in self.config.items("controls"): if ctrl not in controls: - raise CompatibilityError(f"{self.device.filename} has no control named {ctrl}") + raise CompatibilityError( + f"{self.device.filename} has no control named {ctrl}" + ) if pedantic: if not self.config.has_section("device"): raise ConfigurationError("Section 'device' is missing") - for (option, have) in ( + for option, have in ( ("card", str(self.device.info.card)), ("driver", str(self.device.info.driver)), ("version", str(self.device.info.version)), @@ -126,7 +135,9 @@ def validate(self, pedantic: bool = False) -> None: ): want = self.config["device"][option] if not (want == have): - raise CompatibilityError(f"{option.title()} mismatch: want '{want}', have '{have}'") + raise CompatibilityError( + f"{option.title()} mismatch: want '{want}', have '{have}'" + ) self.log.info("configuration validated") def apply(self, cycles: int = 2) -> None: