aboutsummaryrefslogtreecommitdiff
path: root/fprintd_tk_lib.py
diff options
context:
space:
mode:
Diffstat (limited to 'fprintd_tk_lib.py')
-rw-r--r--fprintd_tk_lib.py77
1 files changed, 43 insertions, 34 deletions
diff --git a/fprintd_tk_lib.py b/fprintd_tk_lib.py
index 1f1b022..f4947ec 100644
--- a/fprintd_tk_lib.py
+++ b/fprintd_tk_lib.py
@@ -9,8 +9,12 @@
import os, subprocess, re
_user = os.getenv("USER")
-#fre = re.compile("^.* . #[0-9]: \w+$")
fre = re.compile ("^.* - #[0-9]+: ([^ ]+)$")
+prevent_success_messages = [
+ "no-match",
+ "failed to claim",
+ "not enrolled for user"
+]
def get_enrolled_fingers(user = None):
# return list of full strings of fingers that are enrolled.
@@ -35,47 +39,52 @@ def get_enrolled_fingers(user = None):
pass
return enrolled_fingers
-def enroll_finger(finger, status_function = None, user = None):
+# WORKHERE: count duplicate lines as before, and also save last line, so we can prepend "succeeded"?
+def fprintd_action(action, finger, status_function = None, user = None):
if user is None:
user = _user
+ if action == "enroll":
+ command = ["fprintd-enroll","-f",finger,user]
+ elif action == "verify":
+ command = ["fprintd-verify","-f",finger,user]
+ elif action == "delete":
+ command = ["fprintd-delete",user]
+ else:
+ if status_function:
+ status_function(f"Invalid action {action}")
+ return False
proc = subprocess.Popen(
- ["fprintd-enroll","-f",finger,user],
+ command,
stdout = subprocess.PIPE,
universal_newlines = True
)
+ old_line = "INITIAL_LINE"
+ dupe_count = 0
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"
+ display_line = line
+ if line == old_line:
+ dupe_count = dupe_count + 1
+ display_line = line.strip() + str(f" (x{dupe_count})")
else:
- if status_function:
- #print(f"Will use function {status_function}(\"enroll-stage-passed\")")
- status_function(line)
- return line
+ dupe_count = 1
+ old_line = line
+ if status_function:
+ status_function(display_line)
+ # If you want to react to any lines.
+ #if re.match("^.*verify-match (done).*",line):
+ # proc.kill()
+ # return "verify-match"
+ # so the process has ended, now what?
+ proc.kill()
+ if status_function:
+ if display_line:
+ display = True
+ for i in prevent_success_messages:
+ if i in display_line:
+ display = False
+ break
+ if display:
+ status_function(f"Succeeded! {display_line}")
bgstack15