#!/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