Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .flake8

This file was deleted.

12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ update-venv:
ifeq (, $(shell which poetry))
$(error "No poetry in $(PATH)")
endif
poetry install --sync --without=deploy
poetry sync --without=deploy

# clean environment
semi-clean:
Expand All @@ -37,19 +37,19 @@ build-pyinstaller-onedir:

# code checks
check-format:
poetry run black --check $(PACKAGE_NAME)/
poetry run ruff format --check $(PACKAGE_NAME)/

check-import-sorting:
poetry run isort --check-only $(PACKAGE_NAME)/
poetry run ruff check --select I --diff $(PACKAGE_NAME)/

check-style:
poetry run flake8 $(PACKAGE_NAME)/
poetry run ruff check $(PACKAGE_NAME)/

check-typing:
poetry run mypy $(PACKAGE_NAME)/

check: check-format check-import-sorting check-style check-typing

fix:
poetry run black $(PACKAGE_NAME)/
poetry run isort $(PACKAGE_NAME)/
poetry run ruff format $(PACKAGE_NAME)/
poetry run ruff check --fix $(PACKAGE_NAME)/
6 changes: 1 addition & 5 deletions nitrokeyapp/device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ def add(self) -> List[DeviceData]:
new_devices = []
for candidate in all_devs:
# ignore bootloader device during update
if (
len(self._devices) == 1
and self._devices[0].updating
and candidate.is_bootloader
):
if len(self._devices) == 1 and self._devices[0].updating and candidate.is_bootloader:
continue

# handle from bootloader-device updating
Expand Down
18 changes: 6 additions & 12 deletions nitrokeyapp/device_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,17 @@

class DeviceView(Protocol):
@property
def common_ui(self) -> CommonUi:
...
def common_ui(self) -> CommonUi: ...

@property
def title(self) -> str:
...
def title(self) -> str: ...

@property
def widget(self) -> QWidget:
...
def widget(self) -> QWidget: ...

@property
def worker(self) -> Optional[Worker]:
...
def worker(self) -> Optional[Worker]: ...

def reset(self) -> None:
...
def reset(self) -> None: ...

def refresh(self, data: DeviceData) -> None:
...
def refresh(self, data: DeviceData) -> None: ...
4 changes: 1 addition & 3 deletions nitrokeyapp/error_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def __init__(self, log_file: str, parent: Optional[QWidget] = None) -> None:
self.button_save_log = QPushButton("Save Log File", self)
self.button_save_log.pressed.connect(self.save_log)

self.ui.buttonBox.addButton(
self.button_save_log, QDialogButtonBox.ButtonRole.ActionRole
)
self.ui.buttonBox.addButton(self.button_save_log, QDialogButtonBox.ButtonRole.ActionRole)

def set_exception(
self,
Expand Down
3 changes: 1 addition & 2 deletions nitrokeyapp/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def __init__(self, qt_app: QtWidgets.QApplication, log_file: str):
]
for view in self.views:
if view.worker:

view.worker.busy_state_changed.connect(self.set_busy)

view.common_ui.touch.start.connect(self.touch_dialog.start)
Expand Down Expand Up @@ -149,7 +148,7 @@ def detect_added_devices(
device_info: Optional[Dict[str, str]] = None,
) -> None:
# retry for up to 2secs
for tries in range(8):
for _tries in range(8):
devs = self.device_manager.add()
if devs:
break
Expand Down
8 changes: 2 additions & 6 deletions nitrokeyapp/information_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def __init__(
self.hide_timer.timeout.connect(self.hide_status)

@Slot(str, int, str)
def set_status(
self, text: str, timeout: int = 7000, icon: Optional[str] = None
) -> None:
def set_status(self, text: str, timeout: int = 7000, icon: Optional[str] = None) -> None:
self.status.setText(text)
self.status.show()
self.information_frame.show()
Expand All @@ -88,9 +86,7 @@ def hide_status(self) -> None:

@Slot()
def set_touch_status(self) -> None:
self.set_status(
"Press your Nitrokey to confirm...", timeout=15000, icon="touch.svg"
)
self.set_status("Press your Nitrokey to confirm...", timeout=15000, icon="touch.svg")

@Slot()
def hide_touch(self) -> None:
Expand Down
4 changes: 1 addition & 3 deletions nitrokeyapp/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def init_logging() -> Generator[str, None, None]:
log_format = "%(relativeCreated)-8d %(levelname)6s %(name)10s %(message)s"

try:
handler = logging.FileHandler(
filename=log_file.name, delay=True, encoding="utf-8"
)
handler = logging.FileHandler(filename=log_file.name, delay=True, encoding="utf-8")
console_handler = logging.StreamHandler(sys.stdout)

handlers = [handler]
Expand Down
4 changes: 1 addition & 3 deletions nitrokeyapp/nk3_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@


class Nk3Button(QtWidgets.QToolButton):
def __init__(
self, data: DeviceData, on_click: Callable[[DeviceData], None]
) -> None:
def __init__(self, data: DeviceData, on_click: Callable[[DeviceData], None]) -> None:
super().__init__()

self.setIcon(QtUtilsMixIn.get_qicon("nitrokey.svg"))
Expand Down
4 changes: 1 addition & 3 deletions nitrokeyapp/overview_tab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ def device_updated(self, result: UpdateResult) -> None:
elif result.status == UpdateStatus.ABORTED:
self.common_ui.info.error.emit(f"Nitrokey 3 update aborted{msg}")
else:
self.common_ui.info.error.emit(
f"Unexpected update result: {result.status}{msg}"
)
self.common_ui.info.error.emit(f"Unexpected update result: {result.status}{msg}")

self.common_ui.gui.refresh_devices.emit()

Expand Down
4 changes: 1 addition & 3 deletions nitrokeyapp/overview_tab/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def update_device(self, data: DeviceData, is_qubesos: bool) -> None:
self.run(job)

@Slot(DeviceData, str)
def update_device_file(
self, data: DeviceData, filename: str, is_qubesos: bool
) -> None:
def update_device_file(self, data: DeviceData, filename: str, is_qubesos: bool) -> None:
job = UpdateDevice(self.common_ui, data, is_qubesos)
job.image = filename
job.device_updated.connect(self.device_updated)
Expand Down
3 changes: 1 addition & 2 deletions nitrokeyapp/prompt_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def confirm(self, title: str, desc: str) -> None:
self.setText(desc)
self.setWindowTitle(title)
self.setStandardButtons(
QtWidgets.QMessageBox.StandardButton.Ok
| QtWidgets.QMessageBox.StandardButton.Cancel
QtWidgets.QMessageBox.StandardButton.Ok | QtWidgets.QMessageBox.StandardButton.Cancel
)
self.setIcon(QtWidgets.QMessageBox.Icon.Information)

Expand Down
8 changes: 2 additions & 6 deletions nitrokeyapp/qt_utils_mix_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def __init__(self) -> None:
assert isinstance(self, QObject)

@staticmethod
def load_ui(
filename: str, base_instance: Optional[QtWidgets.QWidget] = None
) -> Any:
def load_ui(filename: str, base_instance: Optional[QtWidgets.QWidget] = None) -> Any:
# returning `Any` to avoid `mypy` going crazy due to monkey-patching
loader = UiLoader(base_instance, customWidgets=None)
p_dir = (Path(__file__).parent / "ui").absolute()
Expand Down Expand Up @@ -80,9 +78,7 @@ def get_widget(self, qt_cls: Type[Q], name: str = "") -> Q:
self.widgets[name] = widget
return widget # type: ignore

def collapse(
self, frame: QtWidgets.QWidget, expand_button: QtWidgets.QPushButton
) -> None:
def collapse(self, frame: QtWidgets.QWidget, expand_button: QtWidgets.QPushButton) -> None:
# Find out if the state is on or off
state = expand_button.isChecked()
if not state:
Expand Down
27 changes: 6 additions & 21 deletions nitrokeyapp/secrets_tab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,10 @@ def __init__(self, parent: Optional[QWidget] = None) -> None:
self.action_password_show.triggered.connect(self.act_password_show)

self.action_comment_copy = self.ui.comment.addAction(icon_copy, loc)
self.action_comment_copy.triggered.connect(
lambda: self.act_copy_line_edit(self.ui.comment)
)
self.action_comment_copy.triggered.connect(lambda: self.act_copy_line_edit(self.ui.comment))

self.action_otp_copy = self.ui.otp.addAction(icon_copy, loc)
self.action_otp_copy.triggered.connect(
lambda: self.act_copy_line_edit(self.ui.otp)
)
self.action_otp_copy.triggered.connect(lambda: self.act_copy_line_edit(self.ui.otp))

self.action_otp_gen = self.ui.otp.addAction(icon_refresh, loc)
self.action_otp_gen.triggered.connect(self.generate_otp)
Expand Down Expand Up @@ -499,9 +495,7 @@ def edit_credential(self, credential: Credential) -> None:
if credential.otp or credential.other:
self.ui.otp.setReadOnly(True)

self.ui.select_algorithm.setCurrentText(
str(credential.otp or credential.other)
)
self.ui.select_algorithm.setCurrentText(str(credential.otp or credential.other))
self.ui.select_algorithm.setEnabled(False)
self.action_hmac_gen.setVisible(False)

Expand Down Expand Up @@ -546,7 +540,6 @@ def act_enable_otp_edit(self) -> None:

@Slot()
def add_new_credential(self) -> None:

if not self.data:
return

Expand Down Expand Up @@ -661,9 +654,7 @@ def check_credential(self) -> None:
self.show_hmac_view()
if len(check_secret) != 32:
can_save = False
self.common_ui.info.info.emit(
"The HMAC-Secret is not 32 chars long"
)
self.common_ui.info.info.emit("The HMAC-Secret is not 32 chars long")
tool_Tip = tool_Tip + "\n- The HMAC-Secret is not 32 chars long"
else:
self.hide_hmac_view()
Expand Down Expand Up @@ -694,9 +685,7 @@ def act_copy_line_edit(self, obj: QLineEdit) -> None:
self.line2copy_action[obj].setIcon(self.get_qicon("done.svg"))
QTimer.singleShot(
5000,
lambda: self.line2copy_action[obj].setIcon(
self.get_qicon("content_copy.svg")
),
lambda: self.line2copy_action[obj].setIcon(self.get_qicon("content_copy.svg")),
)

def act_password_show(self) -> None:
Expand All @@ -723,7 +712,6 @@ def hide_credential(self) -> None:
self.active_credential = None

def show_hmac_view(self) -> None:

name_hmac = "HmacSlot2"

if self.active_credential is None:
Expand Down Expand Up @@ -754,7 +742,6 @@ def show_hmac_view(self) -> None:
self.ui.is_touch_protected.hide()

def hide_hmac_view(self) -> None:

if self.active_credential is None and self.ui.name_label.text() == "HmacSlot2":
self.ui.name_label.clear()
self.ui.name_label.hide()
Expand Down Expand Up @@ -873,9 +860,7 @@ def save_credential(self) -> None:
if self.active_credential is None:
self.trigger_add_credential.emit(self.data, cred, secret)
else:
self.trigger_edit_credential.emit(
self.data, cred, secret, self.active_credential.id
)
self.trigger_edit_credential.emit(self.data, cred, secret, self.active_credential.id)

@Slot()
def generate_otp(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion nitrokeyapp/secrets_tab/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def query(self, attempts: int) -> None:
pin, ok = QInputDialog.getText(
self.parent_widget,
"Enter Passwords PIN",
"Please enter the Passwords PIN (remaining retries: " f"{attempts}):",
f"Please enter the Passwords PIN (remaining retries: {attempts}):",
QLineEdit.EchoMode.Password,
)
if ok and pin:
Expand Down
Loading