2007-06-08 00:55:16 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: iso-8859-1 -*-
|
|
|
|
|
2010-03-02 23:06:20 +00:00
|
|
|
import utils, cards, TLV_utils, sys, binascii, time, traceback, readers
|
2007-06-08 00:55:16 +00:00
|
|
|
|
2007-11-14 14:04:32 +00:00
|
|
|
OPTIONS = "iGW:R:"
|
|
|
|
LONG_OPTIONS = ["interactive","no-gui", "write-files-basename", "read-files-basename"]
|
2007-06-08 02:10:18 +00:00
|
|
|
|
|
|
|
use_gui = True
|
2007-06-08 05:33:29 +00:00
|
|
|
write_files = None
|
|
|
|
read_files = None
|
2007-11-14 14:04:32 +00:00
|
|
|
start_interactive = False
|
2007-06-08 02:10:18 +00:00
|
|
|
|
2007-06-08 00:55:16 +00:00
|
|
|
if __name__ == "__main__":
|
2010-03-02 23:06:20 +00:00
|
|
|
c = readers.CommandLineArgumentHelper()
|
2007-06-08 00:55:16 +00:00
|
|
|
|
2007-06-08 02:10:18 +00:00
|
|
|
(options, arguments) = c.getopt(sys.argv[1:], OPTIONS, LONG_OPTIONS)
|
|
|
|
|
|
|
|
for option, value in options:
|
|
|
|
if option in ("-G","--no-gui"):
|
|
|
|
use_gui = False
|
2007-11-14 14:04:32 +00:00
|
|
|
start_interactive = False
|
2007-06-08 05:33:29 +00:00
|
|
|
elif option in ("-W","--write-files-basename"):
|
|
|
|
write_files = value
|
|
|
|
elif option in ("-R","--read-files-basename"):
|
|
|
|
read_files = value
|
2007-11-14 14:04:32 +00:00
|
|
|
elif option in ("-i", "--interactive"):
|
|
|
|
start_interactive = True
|
|
|
|
use_gui = True
|
2007-06-08 00:55:16 +00:00
|
|
|
|
2007-11-14 14:04:32 +00:00
|
|
|
if read_files is None and not start_interactive:
|
2007-06-16 06:56:57 +00:00
|
|
|
card_object = c.connect()
|
|
|
|
card = cards.new_card_object(card_object)
|
2007-06-08 05:33:29 +00:00
|
|
|
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)
|
2007-11-14 14:04:32 +00:00
|
|
|
elif read_files is not None:
|
2007-06-08 05:33:29 +00:00
|
|
|
p = cards.passport_application.Passport.from_files(basename=read_files)
|
2007-11-14 14:04:32 +00:00
|
|
|
elif start_interactive:
|
|
|
|
p = None
|
2007-06-08 05:33:29 +00:00
|
|
|
|
2007-11-14 14:04:32 +00:00
|
|
|
if write_files is not None and not start_interactive:
|
2007-06-08 05:33:29 +00:00
|
|
|
p.to_files(basename=write_files)
|
2007-06-08 00:55:16 +00:00
|
|
|
|
2007-06-08 02:10:18 +00:00
|
|
|
if use_gui:
|
|
|
|
import gui
|
|
|
|
|
|
|
|
g = gui.PassportGUI()
|
2007-11-14 14:04:32 +00:00
|
|
|
if p is not None:
|
|
|
|
g.set_passport(p)
|
|
|
|
else:
|
|
|
|
g.clear_display()
|
|
|
|
g.set_card_factory(c)
|
2007-06-08 02:10:18 +00:00
|
|
|
g.run()
|