From 6ab41891eacbfa910e73c7d521df01ab395d015c Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Sun, 22 Sep 2024 20:41:52 -0400 Subject: initial commit --- fprintd_tk_lib.py | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 fprintd_tk_lib.py (limited to 'fprintd_tk_lib.py') diff --git a/fprintd_tk_lib.py b/fprintd_tk_lib.py new file mode 100644 index 0000000..1f1b022 --- /dev/null +++ b/fprintd_tk_lib.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +# Startdate: 2024-09-22-1 15:33 +# Purpose: backend for fprintd_tk that uses fprintd-* binaries, in case I ever rewrite this to use dbus directly? +# Dependencies: +# /usr/bin/fprintd-* +# Improve: +# add a verbose/debug param to everything? + +import os, subprocess, re + +_user = os.getenv("USER") +#fre = re.compile("^.* . #[0-9]: \w+$") +fre = re.compile ("^.* - #[0-9]+: ([^ ]+)$") + +def get_enrolled_fingers(user = None): + # return list of full strings of fingers that are enrolled. + enrolled_fingers = [] + if user is None: + user = _user + proc = subprocess.Popen( + ["fprintd-list",user], + stdout = subprocess.PIPE, + universal_newlines = True # or maybe text=True + ) + #print(result.stdout) + while True: + line = proc.stdout.readline() + if not line: + break + if fre.match(line): + #print(f"Got {fre.match(line).groups()[0]}") + enrolled_fingers.append(fre.match(line).groups()[0].strip()) + else: + #print(f"Not-matching: {line}",end="") + pass + return enrolled_fingers + +def enroll_finger(finger, status_function = None, user = None): + if user is None: + user = _user + proc = subprocess.Popen( + ["fprintd-enroll","-f",finger,user], + stdout = subprocess.PIPE, + universal_newlines = True + ) + while True: + line = proc.stdout.readline() + if not line: + break + if re.match("^.*enroll-duplicate.*",line): + # Using the same finger as any other finger enrolled by any user already is considered an error by fprintd, and there is nothing we can do about it. It is an error and we must raise an error here. + return "enroll-duplicate" + elif re.match("^.*enroll-completed.*",line): + return "enroll-completed" + elif re.match("^.*enroll-stage-passed.*",line): + if status_function: + #print(f"Will use function {status_function}(\"enroll-stage-passed\")") + status_function("enroll-stage-passed") + print(f"Great, keep going!") + # so the process has ended, now what? + return f"Last line was: {line}" + +def verify_finger(finger, status_function = None, user = None): + if user is None: + user = _user + proc = subprocess.Popen( + ["fprintd-verify","-f",finger,user], + stdout = subprocess.PIPE, + universal_newlines = True + ) + while True: + line = proc.stdout.readline() + if not line: + break + if re.match("^.*verify-match (done).*",line): + return "verify-match" + else: + if status_function: + #print(f"Will use function {status_function}(\"enroll-stage-passed\")") + status_function(line) + return line -- cgit