aboutsummaryrefslogtreecommitdiffstats
path: root/readpass.py
blob: 2d68e27eb4ddb11f50ef7e73c3acc999b4a43c95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-

import utils, cards, TLV_utils, sys, binascii, time, traceback, readers

OPTIONS = "iGW:R:"
LONG_OPTIONS = ["interactive","no-gui", "write-files-basename", "read-files-basename"]

use_gui = True
write_files = None
read_files = None
start_interactive = False

if __name__ == "__main__":
    c = readers.CommandLineArgumentHelper()
    
    (options, arguments) = c.getopt(sys.argv[1:], OPTIONS, LONG_OPTIONS)
    
    for option, value in options:
        if option in ("-G","--no-gui"):
            use_gui = False
            start_interactive = False
        elif option in ("-W","--write-files-basename"):
            write_files = value
        elif option in ("-R","--read-files-basename"):
            read_files = value
        elif option in ("-i", "--interactive"):
            start_interactive = True
            use_gui = True
    
    if read_files is None and not start_interactive:
        card_object = c.connect()
        card = cards.new_card_object(card_object)
        cards.generic_card.DEBUG = False
        
        print >>sys.stderr, "Using %s" % card.DRIVER_NAME
        
        if len(arguments) > 1:
            p = cards.passport_application.Passport.from_card(card, arguments[:2])
        elif len(arguments) == 1:
            p = cards.passport_application.Passport.from_card(card, ["",arguments[0]])
        else:
            p = cards.passport_application.Passport.from_card(card)
    elif read_files is not None:
        p = cards.passport_application.Passport.from_files(basename=read_files)
    elif start_interactive:
        p = None
    
    if write_files is not None and not start_interactive:
        p.to_files(basename=write_files)
    
    if use_gui:
        import gui
        
        g = gui.PassportGUI()
        if p is not None:
            g.set_passport(p)
        else:
            g.clear_display()
        g.set_card_factory(c)
        g.run()