aboutsummaryrefslogtreecommitdiffstats
path: root/readpass.py
blob: 1e36ba2acb895eab85168d3ebd5de45e3e26f733 (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
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-

from utils import pycsc
import utils, cards, TLV_utils, sys, binascii, time, traceback

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

use_gui = True
write_files = None
read_files = None

if __name__ == "__main__":
    c = utils.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
        elif option in ("-W","--write-files-basename"):
            write_files = value
        elif option in ("-R","--read-files-basename"):
            read_files = value
    
    if read_files is None:
        pycsc_card = c.connect()
        card = cards.new_card_object(pycsc_card)
        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)
    else:
        p = cards.passport_application.Passport.from_files(basename=read_files)
    
    if write_files is not None:
        p.to_files(basename=write_files)
    
    if use_gui:
        import gui
        
        g = gui.PassportGUI()
        g.set_passport(p)
        g.run()