From 8632877b95d48644f9e7ad97442aba8f0b747c24 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 15 Apr 2020 12:01:11 +0200 Subject: [PATCH] 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. --- examples/sendvirtcmd.py | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 examples/sendvirtcmd.py diff --git a/examples/sendvirtcmd.py b/examples/sendvirtcmd.py new file mode 100755 index 00000000..a3cd6064 --- /dev/null +++ b/examples/sendvirtcmd.py @@ -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 " + + + +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 "\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')) +