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

Last change on this file since 11540 was 11540, checked in by uli, 10 years ago

Add some enroll-script. A quick, dirty hack.

  • Property svn:executable set to *
File size: 1.8 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# create results dir if it does not exist already.
31if not os.path.exists(RESULTS_DIR):
32    print "Creating dir for collected fingerprints in %s" % RESULTS_DIR
33    os.mkdir(RESULTS_DIR)
34
35print "Hello Issoufou!"
36print
37print "After pressing a key, the fingerprint scanner GUI will"
38print "appear. Then, please do a scan of a finger via the GUI."
39print
40print "After scanning, please close the scanner programme."
41print
42
43if os.path.exists(PRINTS_DIR):
44    shutil.rmtree(PRINTS_DIR)
45
46stud_id = raw_input("Please ENTER the STUDENT ID: ")
47
48os.system(CMD)
49
50fp_file = get_first_dir(get_first_dir(get_first_dir(PRINTS_DIR)))
51if fp_file is None or not os.path.isfile(fp_file):
52    print "ERROR: No fingerprint generated. Exiting."
53    sys.exit(0)
54
55basename = os.path.basename(fp_file)
56
57student_path = os.path.join(RESULTS_DIR, stud_id.upper())
58fp_target = os.path.join(student_path, basename)
59if not os.path.exists(student_path):
60    # create a dir for each student
61    os.mkdir(student_path)
62
63print "COPYING fingerprint over..."
64shutil.copy2(fp_file, fp_target)
65
66print "DONE. Thanks for using enroll_script.py."
67print "Collected prints are in %s" % RESULTS_DIR
Note: See TracBrowser for help on using the repository browser.