examples: Add example to feed non-imaging virtual driver

Add an example script that can add and remove prints from the
non-imaging virtual driver.
This commit is contained in:
Bastien Nocera 2020-04-15 12:01:11 +02:00
parent 170d7c2cf7
commit 8632877b95

53
examples/sendvirtcmd.py Executable file
View file

@ -0,0 +1,53 @@
#!/usr/bin/env python3
# This script can be used together with the virtual_imgdev to simulate an
# image based fingerprint reader.
#
# To use, set the FP_VIRTUAL_IMAGE environment variable for both the
# libfprint using program (e.g. fprintd) and this script.
#
# Usually this would work by adding it into the systemd unit file. The
# best way of doing so is to create
# /etc/systemd/system/fprintd.service.d/fprintd-test.conf
#
# [Service]
# RuntimeDirectory=fprint
# Environment=FP_VIRTUAL_DEVICE=/run/fprint/virtdev_sock
# Environment=G_MESSAGES_DEBUG=all
# ReadWritePaths=$RUNTIME_DIR
#
# After that run:
#
# systemctl daemon-reload
# systemctl restart fprintd.service
#
# You may also need to disable selinux.
#
# Then run this script with e.g.
# FP_VIRTUAL_DEVICE=/run/fprint/virtdev_sock ./sendvirtimg.py "ADD <username> <finger> <success|failure>"
import cairo
import sys
import os
import socket
import struct
if len(sys.argv) != 2:
sys.stderr.write('You need to pass commands!\n')
sys.stderr.write('Usage: ./sendvirtimg.py "ADD <finger> <username> <success|failure>"\n')
sys.exit(1)
command = sys.argv[1]
# Send image through socket
sockaddr = os.environ['FP_VIRTUAL_DEVICE']
if not sockaddr:
sockaddr = os.environ['FP_VIRTUAL_DEVICE_IDENT']
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(sockaddr)
sock.sendall(command.encode('utf-8'))