Skip to content

Commit

Permalink
API CHANGE: Move CommandLineArgumentHelper to readers module to allow…
Browse files Browse the repository at this point in the history
… proper import order.

(CommandLineArgumentHelper references the readers module, which references the utils module, so having CLAH in utils would create a circular reference.)
  • Loading branch information
henryk committed Mar 2, 2010
1 parent 4748536 commit bc07262
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 50 deletions.
4 changes: 2 additions & 2 deletions brutefid.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- 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"
LONG_OPTIONS = ["min-fid", "max-fid", "with-dirs", "dump-contents"]
Expand Down Expand Up @@ -35,7 +35,7 @@ def dump(data):
pass

if __name__ == "__main__":
c = utils.CommandLineArgumentHelper()
c = readers.CommandLineArgumentHelper()

(options, arguments) = c.getopt(sys.argv[1:], OPTIONS, LONG_OPTIONS)
for option, value in options:
Expand Down
2 changes: 1 addition & 1 deletion cyberflex-shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def usage():

if __name__ == "__main__":

helper = utils.CommandLineArgumentHelper()
helper = readers.CommandLineArgumentHelper()

(options, arguments) = helper.getopt(sys.argv[1:], OPTIONS, LONG_OPTIONS)

Expand Down
4 changes: 2 additions & 2 deletions fingerpass.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- 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):
# Need RFID
Expand Down Expand Up @@ -180,7 +180,7 @@ def do_match(line, fingerprint):
return ["\n".join(e) for e in results]

if __name__ == "__main__":
c = utils.CommandLineArgumentHelper()
c = readers.CommandLineArgumentHelper()
(options, arguments) = c.getopt(sys.argv[1:])

card_object = c.connect()
Expand Down
6 changes: 3 additions & 3 deletions gui/ireadyou.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import gtk,gtk.glade,gobject
import sys, os, time
try:
import utils, TLV_utils, cards
import utils, TLV_utils, cards, readers
except ImportError, e:
try:
sys.path.append(".")
import utils, TLV_utils, cards
import utils, TLV_utils, cards, readers
except ImportError:
raise e

Expand Down Expand Up @@ -360,7 +360,7 @@ def _remove_ticket(self, card, ticket):
LONG_OPTIONS = []

if __name__ == "__main__":
## c = utils.CommandLineArgumentHelper()
## c = readers.CommandLineArgumentHelper()
##
## (options, arguments) = c.getopt(sys.argv[1:], OPTIONS, LONG_OPTIONS)
##
Expand Down
43 changes: 40 additions & 3 deletions readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
pycsc you'll need to downgrade to SVN revision 246.
"""
raise

import sys, utils, getopt

class Smartcard_Reader(object):
def list_readers(cls):
"Return a list of tuples: (reader name, implementing object)"
Expand Down Expand Up @@ -219,11 +222,45 @@ def connect_to(reader):

readerObject.connect()

from utils import hexdump

print "ATR: %s" % hexdump(readerObject.get_ATR(), short = True)
print "ATR: %s" % utils.hexdump(readerObject.get_ATR(), short = True)
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__":
list_readers()

4 changes: 2 additions & 2 deletions readpass.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- 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:"
LONG_OPTIONS = ["interactive","no-gui", "write-files-basename", "read-files-basename"]
Expand All @@ -12,7 +12,7 @@
start_interactive = False

if __name__ == "__main__":
c = utils.CommandLineArgumentHelper()
c = readers.CommandLineArgumentHelper()

(options, arguments) = c.getopt(sys.argv[1:], OPTIONS, LONG_OPTIONS)

Expand Down
38 changes: 1 addition & 37 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,4 @@
import string, binascii, sys, re, getopt, readers

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

import string, binascii, sys, re

def represent_binary_fancy(len, value, mask = 0):
result = []
Expand Down

0 comments on commit bc07262

Please sign in to comment.