source: main/pyfprint/trunk/enroll-script.py @ 11547

Last change on this file since 11547 was 11547, checked in by uli, 11 years ago

Ask two times for student id.

  • Property svn:executable set to *
File size: 2.5 KB
Line 
1#!/usr/bin/python
2import os
3import shutil
4import sys
5
6CMD = 'LD_LIBRARY_PATH=/usr/local/lib fprint_demo'
7PRINTS_DIR = os.path.join(
8    os.path.expanduser('~'), '.fprint', 'prints')
9RESULTS_DIR = os.path.join(
10    os.path.expanduser('~'), 'fingerprints')
11
12
13def get_first_dir(path):
14    """Get first available path in `path`.
15
16    For instance if `path` is the directory ``/a/b/`` and contains the
17    files/directories ``c``, ``d``, ``e``, then this function will
18    return ``/a/b/c``.
19    """
20    name = ''
21    if path is None or not os.path.exists(path):
22        print "Doesn't exist: ", path
23        return None
24    try:
25        name = sorted(os.listdir(path))[0]
26    except:
27        return None
28    return os.path.join(path, name)
29
30
31def get_stud_id():
32    """Get a student id via input from keyboard.
33
34    We require the id two times (for safety). The id must not be
35    empty.
36    """
37    while True:
38        stud_id = raw_input("Please ENTER the STUDENT ID: ")
39        ctrl_id = raw_input("Please repeat              : ")
40        if not stud_id:
41            print "Please enter a valid student ID!"
42            stud_id = None
43        if stud_id != ctrl_id:
44            print "IDs do not match. We restart."
45        if stud_id and stud_id == ctrl_id:
46            return stud_id
47
48
49# create results dir if it does not exist already.
50if not os.path.exists(RESULTS_DIR):
51    print "Creating dir for collected fingerprints in %s" % RESULTS_DIR
52    os.mkdir(RESULTS_DIR)
53
54print
55print "After entering a student ID, the fingerprint scanner GUI will"
56print "appear. Then, please do a scan ('enroll') of a finger via the GUI."
57print
58print "After scanning, please close the scanner programme."
59print
60
61if os.path.exists(PRINTS_DIR):
62    shutil.rmtree(PRINTS_DIR)
63
64stud_id = get_stud_id()
65
66os.system(CMD)
67
68fp_file = get_first_dir(get_first_dir(get_first_dir(PRINTS_DIR)))
69if fp_file is None or not os.path.isfile(fp_file):
70    print "ERROR: No fingerprint generated. Exiting."
71    sys.exit(0)
72
73basename = os.path.basename(fp_file)
74
75student_path = os.path.join(RESULTS_DIR, stud_id.upper())
76fp_target = os.path.join(student_path, basename)
77if not os.path.exists(student_path):
78    # create a dir for each student
79    os.mkdir(student_path)
80
81print "COPYING fingerprint over..."
82if os.path.isfile(fp_target):
83    # such a fingerprint exists already (same finger, stud_id)
84    os.unlink(fp_target)
85shutil.copy2(fp_file, fp_target)
86
87print "DONE. Thanks for using enroll_script.py."
88print "Collected prints are in %s" % RESULTS_DIR
Note: See TracBrowser for help on using the repository browser.