From 14eae96e37ee4ec89ec45de25c32a735124a4ebd Mon Sep 17 00:00:00 2001 From: Matthew Giaconelli Date: Sat, 6 May 2023 22:15:57 -0700 Subject: [PATCH 1/2] fix issue where data dir doesnt exist on reboot --- bin/validity-sensors-firmware | 4 ++-- dbus_service/dbus-service | 4 +++- debian/python3-validity.postinst | 1 - setup.py | 2 +- validitysensor/init.py | 2 ++ validitysensor/init_data_dir.py | 8 ++++++++ validitysensor/sensor.py | 3 ++- validitysensor/upload_fwext.py | 3 ++- 8 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 validitysensor/init_data_dir.py diff --git a/bin/validity-sensors-firmware b/bin/validity-sensors-firmware index 9c9e7b9..c9d357b 100755 --- a/bin/validity-sensors-firmware +++ b/bin/validity-sensors-firmware @@ -29,10 +29,10 @@ import urllib.request from usb import core as usb_core +from validitysensor.init_data_dir import PYTHON_VALIDITY_DATA_DIR from validitysensor.firmware_tables import FIRMWARE_NAMES, FIRMWARE_URIS from validitysensor.usb import SupportedDevices -python_validity_data = '/var/run/python-validity/' def download_and_extract_fw(dev_type, fwdir, fwuri=None): @@ -99,4 +99,4 @@ if __name__ == "__main__": with tempfile.TemporaryDirectory() as fwdir: fwpath = download_and_extract_fw(dev_type, fwdir, fwuri=args.driver_uri) - shutil.copy(fwpath, python_validity_data) + shutil.copy(fwpath, PYTHON_VALIDITY_DATA_DIR) diff --git a/dbus_service/dbus-service b/dbus_service/dbus-service index 8159a1a..1c63e8d 100755 --- a/dbus_service/dbus-service +++ b/dbus_service/dbus-service @@ -23,6 +23,7 @@ from usb import core as usb_core from validitysensor import init from validitysensor.db import subtype_to_string, db, SidIdentity, User +from validitysensor.init_data_dir import PYTHON_VALIDITY_DATA_DIR, init_data_dir from validitysensor.sensor import sensor, RebootException from validitysensor.sid import sid_from_string from validitysensor.tls import tls @@ -35,6 +36,7 @@ INTERFACE_NAME = 'io.github.uunicorn.Fprint.Device' loop = GLib.MainLoop() +init_data_dir() class NoEnrolledPrints(dbus.DBusException): _dbus_error_name = 'net.reactivated.Fprint.Error.NoEnrolledPrints' @@ -191,7 +193,7 @@ class Device(dbus.service.Object): return hexlify(tls.app(unhexlify(cmd))).decode() -backoff_file = '/var/run/python-validity/backoff' +backoff_file = PYTHON_VALIDITY_DATA_DIR + 'backoff' # I don't know how to tell systemd to backoff in case of multiple instance of the same template service, help! diff --git a/debian/python3-validity.postinst b/debian/python3-validity.postinst index 4a9f48a..ca62874 100644 --- a/debian/python3-validity.postinst +++ b/debian/python3-validity.postinst @@ -4,7 +4,6 @@ set -e #DEBHELPER# if [ "$1" = "configure" ]; then - mkdir -p /var/run/python-validity || true validity-sensors-firmware || true systemctl daemon-reload || true udevadm control --reload-rules || true diff --git a/setup.py b/setup.py index 9c53e29..ac6d50b 100755 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup(name='python-validity', - version='0.14', + version='0.15', py_modules=[], packages=['validitysensor'], scripts=[ diff --git a/validitysensor/init.py b/validitysensor/init.py index f3c0498..1153cf7 100644 --- a/validitysensor/init.py +++ b/validitysensor/init.py @@ -1,6 +1,7 @@ import atexit import logging +from validitysensor.init_data_dir import init_data_dir from validitysensor.flash import read_tls_flash from validitysensor.init_db import init_db from validitysensor.init_flash import init_flash @@ -26,6 +27,7 @@ def close(): def open_common(): + init_data_dir() init_flash() usb.send_init() tls.parse_tls_flash(read_tls_flash()) diff --git a/validitysensor/init_data_dir.py b/validitysensor/init_data_dir.py new file mode 100644 index 0000000..2f38872 --- /dev/null +++ b/validitysensor/init_data_dir.py @@ -0,0 +1,8 @@ +import os + +PYTHON_VALIDITY_DATA_DIR = '/var/run/python-validity/' + +def init_data_dir(): + if not os.path.isdir(PYTHON_VALIDITY_DATA_DIR): + os.mkdir(PYTHON_VALIDITY_DATA_DIR) + diff --git a/validitysensor/sensor.py b/validitysensor/sensor.py index 31a31e9..dd019bb 100644 --- a/validitysensor/sensor.py +++ b/validitysensor/sensor.py @@ -14,13 +14,14 @@ from .db import db, SidIdentity from .flash import write_enable, call_cleanups, read_flash, erase_flash, write_flash_all, read_flash_all from .hw_tables import dev_info_lookup +from .init_data_dir import PYTHON_VALIDITY_DATA_DIR from .table_types import SensorTypeInfo, SensorCaptureProg from .tls import tls from .usb import usb, CancelledException from .util import assert_status, unhex # TODO: this should be specific to an individual device (system may have more than one sensor) -calib_data_path = '/var/run/python-validity/calib-data.bin' +calib_data_path = PYTHON_VALIDITY_DATA_DIR + 'calib-data.bin' line_update_type1_devices = [ 0xB5, 0x885, 0xB3, 0x143B, 0x1055, 0xE1, 0x8B1, 0xEA, 0xE4, 0xED, 0x1825, 0x1FF5, 0x199 diff --git a/validitysensor/upload_fwext.py b/validitysensor/upload_fwext.py index 695bf0f..540297f 100644 --- a/validitysensor/upload_fwext.py +++ b/validitysensor/upload_fwext.py @@ -5,10 +5,11 @@ from .firmware_tables import FIRMWARE_NAMES from .flash import write_flash_all, write_fw_signature, get_fw_info +from .init_data_dir import PYTHON_VALIDITY_DATA_DIR from .sensor import reboot, write_hw_reg32, read_hw_reg32, identify_sensor from .usb import usb, SupportedDevices -firmware_home = '/var/run/python-validity' +firmware_home = PYTHON_VALIDITY_DATA_DIR def default_fwext_name(): From 50566b8ad50ed94565c09b977fd67e3a0cb57856 Mon Sep 17 00:00:00 2001 From: Matthew Giaconelli Date: Sat, 6 May 2023 22:48:50 -0700 Subject: [PATCH 2/2] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ac6d50b..9c53e29 100755 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup(name='python-validity', - version='0.15', + version='0.14', py_modules=[], packages=['validitysensor'], scripts=[