Skip to content

Commit

Permalink
Get working under Windows with http://cheeseshop.python.org/pypi/PyCS…
Browse files Browse the repository at this point in the history
…C/0.3 (with Python 2.5 for Windows)

Note: you additionally need pycrypto, the source of which you'll get from http://cheeseshop.python.org/pypi/pycrypto/2.0.1
  Compilation of pycrypto can work with cygwin in two steps: python setup.py build -c mingw32 and python setup.py install --skip-build


git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@190 f711b948-2313-0410-aaa9-d29f33439f0b
  • Loading branch information
hploetz committed May 8, 2007
1 parent a94d4d8 commit 47662ab
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
12 changes: 11 additions & 1 deletion 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
Expand Down
12 changes: 11 additions & 1 deletion 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():
Expand Down
16 changes: 14 additions & 2 deletions shell.py
Expand Up @@ -23,7 +23,7 @@ def __init__(self, basename):
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:
Expand All @@ -50,6 +50,18 @@ def __init__(self, basename):
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
Expand Down Expand Up @@ -81,7 +93,7 @@ def run_startup(self):
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:
Expand Down
12 changes: 11 additions & 1 deletion 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 = []
Expand Down

0 comments on commit 47662ab

Please sign in to comment.