API CHANGE: Move CommandLineArgumentHelper to readers module to allow proper import order.

(CommandLineArgumentHelper references the readers module, which references the utils module, so having CLAH in utils would create a circular reference.)
This commit is contained in:
Henryk Plötz 2010-03-03 00:06:20 +01:00
parent 47485362af
commit bc07262d80
7 changed files with 51 additions and 50 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: iso-8859-1 -*- # -*- coding: iso-8859-1 -*-
import utils, cards, TLV_utils, sys, binascii, time, traceback, smartcard import utils, cards, TLV_utils, sys, binascii, time, traceback, smartcard, readers
OPTIONS = "m:x:dD" OPTIONS = "m:x:dD"
LONG_OPTIONS = ["min-fid", "max-fid", "with-dirs", "dump-contents"] LONG_OPTIONS = ["min-fid", "max-fid", "with-dirs", "dump-contents"]
@ -35,7 +35,7 @@ def dump(data):
pass pass
if __name__ == "__main__": if __name__ == "__main__":
c = utils.CommandLineArgumentHelper() c = readers.CommandLineArgumentHelper()
(options, arguments) = c.getopt(sys.argv[1:], OPTIONS, LONG_OPTIONS) (options, arguments) = c.getopt(sys.argv[1:], OPTIONS, LONG_OPTIONS)
for option, value in options: for option, value in options:

View File

@ -406,7 +406,7 @@ reader = None
if __name__ == "__main__": if __name__ == "__main__":
helper = utils.CommandLineArgumentHelper() helper = readers.CommandLineArgumentHelper()
(options, arguments) = helper.getopt(sys.argv[1:], OPTIONS, LONG_OPTIONS) (options, arguments) = helper.getopt(sys.argv[1:], OPTIONS, LONG_OPTIONS)

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: iso-8859-1 -*- # -*- coding: iso-8859-1 -*-
import utils, cards, TLV_utils, sys, binascii, time, traceback, re import utils, cards, TLV_utils, sys, binascii, time, traceback, re, readers
def fingerprint_rfid(card): def fingerprint_rfid(card):
# Need RFID # Need RFID
@ -180,7 +180,7 @@ def match_fingerprint(fingerprint, database="fingerprints.txt"):
return ["\n".join(e) for e in results] return ["\n".join(e) for e in results]
if __name__ == "__main__": if __name__ == "__main__":
c = utils.CommandLineArgumentHelper() c = readers.CommandLineArgumentHelper()
(options, arguments) = c.getopt(sys.argv[1:]) (options, arguments) = c.getopt(sys.argv[1:])
card_object = c.connect() card_object = c.connect()

View File

@ -4,11 +4,11 @@
import gtk,gtk.glade,gobject import gtk,gtk.glade,gobject
import sys, os, time import sys, os, time
try: try:
import utils, TLV_utils, cards import utils, TLV_utils, cards, readers
except ImportError, e: except ImportError, e:
try: try:
sys.path.append(".") sys.path.append(".")
import utils, TLV_utils, cards import utils, TLV_utils, cards, readers
except ImportError: except ImportError:
raise e raise e
@ -360,7 +360,7 @@ OPTIONS = ""
LONG_OPTIONS = [] LONG_OPTIONS = []
if __name__ == "__main__": if __name__ == "__main__":
## c = utils.CommandLineArgumentHelper() ## c = readers.CommandLineArgumentHelper()
## ##
## (options, arguments) = c.getopt(sys.argv[1:], OPTIONS, LONG_OPTIONS) ## (options, arguments) = c.getopt(sys.argv[1:], OPTIONS, LONG_OPTIONS)
## ##

View File

@ -7,6 +7,9 @@ If you can't install pyscard and want to continue using
pycsc you'll need to downgrade to SVN revision 246. pycsc you'll need to downgrade to SVN revision 246.
""" """
raise raise
import sys, utils, getopt
class Smartcard_Reader(object): class Smartcard_Reader(object):
def list_readers(cls): def list_readers(cls):
"Return a list of tuples: (reader name, implementing object)" "Return a list of tuples: (reader name, implementing object)"
@ -219,11 +222,45 @@ def connect_to(reader):
readerObject.connect() readerObject.connect()
from utils import hexdump print "ATR: %s" % utils.hexdump(readerObject.get_ATR(), short = True)
print "ATR: %s" % hexdump(readerObject.get_ATR(), short = True)
return readerObject return readerObject
class CommandLineArgumentHelper:
OPTIONS = "r:l"
LONG_OPTIONS = ["reader=", "list-readers"]
exit_now = False
reader = None
def connect(self):
"Open the connection to a card"
if self.reader is None:
self.reader = 0
return connect_to(self.reader)
def getopt(self, argv, opts="", long_opts=[]):
"Wrapper around getopt.gnu_getopt. Handles common arguments, returns everything else."
(options, arguments) = getopt.gnu_getopt(sys.argv[1:], self.OPTIONS+opts, self.LONG_OPTIONS+long_opts)
unrecognized = []
for (option, value) in options:
if option in ("-r","--reader"):
self.reader = value
elif option in ("-l","--list-readers"):
for i, (name, obj) in enumerate(list_readers()):
print "%i: %s" % (i,name)
self.exit_now = True
else:
unrecognized.append( (option, value) )
if self.exit_now:
sys.exit()
return unrecognized, arguments
if __name__ == "__main__": if __name__ == "__main__":
list_readers() list_readers()

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: iso-8859-1 -*- # -*- coding: iso-8859-1 -*-
import utils, cards, TLV_utils, sys, binascii, time, traceback import utils, cards, TLV_utils, sys, binascii, time, traceback, readers
OPTIONS = "iGW:R:" OPTIONS = "iGW:R:"
LONG_OPTIONS = ["interactive","no-gui", "write-files-basename", "read-files-basename"] LONG_OPTIONS = ["interactive","no-gui", "write-files-basename", "read-files-basename"]
@ -12,7 +12,7 @@ read_files = None
start_interactive = False start_interactive = False
if __name__ == "__main__": if __name__ == "__main__":
c = utils.CommandLineArgumentHelper() c = readers.CommandLineArgumentHelper()
(options, arguments) = c.getopt(sys.argv[1:], OPTIONS, LONG_OPTIONS) (options, arguments) = c.getopt(sys.argv[1:], OPTIONS, LONG_OPTIONS)

View File

@ -1,40 +1,4 @@
import string, binascii, sys, re, getopt, readers import string, binascii, sys, re
class CommandLineArgumentHelper:
OPTIONS = "r:l"
LONG_OPTIONS = ["reader=", "list-readers"]
exit_now = False
reader = None
def connect(self):
"Open the connection to a card"
if self.reader is None:
self.reader = 0
return readers.connect_to(self.reader)
def getopt(self, argv, opts="", long_opts=[]):
"Wrapper around getopt.gnu_getopt. Handles common arguments, returns everything else."
(options, arguments) = getopt.gnu_getopt(sys.argv[1:], self.OPTIONS+opts, self.LONG_OPTIONS+long_opts)
unrecognized = []
for (option, value) in options:
if option in ("-r","--reader"):
self.reader = value
elif option in ("-l","--list-readers"):
for i, (name, obj) in enumerate(readers.list_readers()):
print "%i: %s" % (i,name)
self.exit_now = True
else:
unrecognized.append( (option, value) )
if self.exit_now:
sys.exit()
return unrecognized, arguments
def represent_binary_fancy(len, value, mask = 0): def represent_binary_fancy(len, value, mask = 0):
result = [] result = []