diff --git a/cards/generic_card.py b/cards/generic_card.py index a197a6a..daf77e4 100644 --- a/cards/generic_card.py +++ b/cards/generic_card.py @@ -1,4 +1,14 @@ -import TLV_utils, crypto_utils, utils, pycsc, binascii, fnmatch, sre +try: + import pycsc +except ImportError,e: + try: + import PyCSC + from PyCSC import pycsc # Windows + pycsc.SCARD_PROTOCOL_ANY = PyCSC.SCARD_PROTOCOL_ANY + except ImportError: + raise e # raise the original exception, masking the windows-only attempt + +import TLV_utils, crypto_utils, utils, binascii, fnmatch, sre from utils import C_APDU, R_APDU DEBUG = True diff --git a/cyberflex-shell.py b/cyberflex-shell.py index e617625..ab27f3d 100755 --- a/cyberflex-shell.py +++ b/cyberflex-shell.py @@ -1,7 +1,17 @@ #!/usr/bin/env python # -*- coding: iso-8859-1 -*- -import pycsc, crypto_utils, utils, cards, os, re, binascii, sys, exceptions, traceback, getopt, datetime +try: + import pycsc +except ImportError,e: + try: + import PyCSC + from PyCSC import pycsc # Windows + pycsc.SCARD_PROTOCOL_ANY = PyCSC.SCARD_PROTOCOL_ANY + except ImportError: + raise e # raise the original exception, masking the windows-only attempt + +import crypto_utils, utils, cards, os, re, binascii, sys, exceptions, traceback, getopt, datetime from shell import Shell def list_readers(): diff --git a/shell.py b/shell.py index cdfe10c..e5d274c 100644 --- a/shell.py +++ b/shell.py @@ -23,7 +23,7 @@ class Shell: own commands first.""" if sys.modules.has_key("readline"): - histfile = os.path.join(os.environ["HOME"], ".%s.history" % basename) + histfile = os.path.join(self.find_homedir(), ".%s.history" % basename) try: readline.read_history_file(histfile) except IOError: @@ -50,6 +50,18 @@ class Shell: self.pre_hook = [] self.post_hook = [] self.prompt = "" + + def find_homedir(self): + "Returns the home directory of the current user or (in Windows) a directory for application specific data." + if os.environ.has_key("HOME"): return os.environ["HOME"] + elif os.environ.has_key("APPDATA"): + appdata = os.environ["APPDATA"] + dirname = os.path.join(appdata, self.basename) + if not os.path.exists(dirname): + os.mkdir(dirname) + return dirname + else: + raise EnvironmentError, "Can't find a home directory from the environment." def get_prompt(self): return self.prompt @@ -81,7 +93,7 @@ class Shell: lines = [] self.startup_ran = True try: - fp = file(os.path.join(os.environ["HOME"], ".%src" % self.basename)) + fp = file(os.path.join(self.find_homedir(), ".%src" % self.basename)) lines = fp.readlines() fp.close() except IOError: diff --git a/utils.py b/utils.py index 57981fc..42bcd4f 100644 --- a/utils.py +++ b/utils.py @@ -1,4 +1,14 @@ -import pycsc, string, binascii, sys, re +try: + import pycsc +except ImportError,e: + try: + import PyCSC + from PyCSC import pycsc # Windows + pycsc.SCARD_PROTOCOL_ANY = PyCSC.SCARD_PROTOCOL_ANY + except ImportError: + raise e # raise the original exception, masking the windows-only attempt + +import string, binascii, sys, re def represent_binary_fancy(len, value, mask = 0): result = []