Changeset 167
- Timestamp:
- 10/23/09 17:08:23 (9 months ago)
- Files:
-
- pykcs11/trunk/samples/getinfo.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
pykcs11/trunk/samples/getinfo.py
r144 r167 1 1 #!/usr/bin/env python 2 2 3 # Copyright (C) 2006 Ludovic Rousseau (ludovic.rousseau@free.fr)3 # Copyright (C) 2006-2009 Ludovic Rousseau (ludovic.rousseau@free.fr) 4 4 # 5 5 # This file is free software; you can redistribute it and/or modify it … … 30 30 print "[-o][--opensession]" 31 31 32 def colorize(text, arg): 33 print magenta + text + blue, arg, normal 32 def getinfo(lib, pin = None, open_session = False, slot = None): 33 def colorize(text, arg): 34 print magenta + text + blue, arg, normal 34 35 35 try: 36 opts, args = getopt.getopt(sys.argv[1:], "p:s:c:ho", ["pin=", "slot=", "lib=", "help", "opensession"])37 except getopt.GetoptError: 38 # print help information and exit:39 usage()40 sys.exit(2)36 red = blue = magenta = normal = "" 37 if sys.stdout.isatty() and platform.system().lower() != 'windows': 38 red = "\x1b[01;31m" 39 blue = "\x1b[34m" 40 magenta = "\x1b[35m" 41 normal = "\x1b[0m" 41 42 42 slot = None 43 lib = None 44 open_session = False 45 pin_available = False 46 for o, a in opts: 47 if o in ("-h", "--help"): 48 usage() 49 sys.exit() 50 if o in ("-p", "--pin"): 51 pin = a 52 pin_available = True 53 open_session = True 54 if o in ("-s", "--slot"): 55 slot = int(a) 56 if o in ("-c", "--lib"): 57 lib = a 58 if o in ("-o", "--opensession"): 59 open_session = True 60 61 red = blue = magenta = normal = "" 62 if sys.stdout.isatty() and platform.system().lower() != 'windows': 63 red = "\x1b[01;31m" 64 blue = "\x1b[34m" 65 magenta = "\x1b[35m" 66 normal = "\x1b[0m" 67 68 pkcs11 = PyKCS11.PyKCS11Lib() 69 try: 43 pkcs11 = PyKCS11.PyKCS11Lib() 70 44 pkcs11.load(lib) 71 45 info = pkcs11.getInfo() … … 99 73 100 74 if pin_available: 75 print " Using pin:", pin 101 76 session.login(pin = pin) 102 77 … … 151 126 session.closeSession() 152 127 153 except PyKCS11.PyKCS11Error, e: 154 print "Error:", e 128 if __name__ == '__main__': 129 try: 130 opts, args = getopt.getopt(sys.argv[1:], "p:s:c:ho", ["pin=", "slot=", "lib=", "help", "opensession"]) 131 except getopt.GetoptError: 132 # print help information and exit: 133 usage() 134 sys.exit(2) 155 135 136 slot = None 137 lib = None 138 pin = None 139 open_session = False 140 pin_available = False 141 for o, a in opts: 142 if o in ("-h", "--help"): 143 usage() 144 sys.exit() 145 if o in ("-p", "--pin"): 146 pin = a 147 pin_available = True 148 open_session = True 149 if o in ("-s", "--slot"): 150 slot = int(a) 151 if o in ("-c", "--lib"): 152 lib = a 153 if o in ("-o", "--opensession"): 154 open_session = True 155 156 try: 157 getinfo(lib, pin = pin, open_session = open_session, slot = slot) 158 except PyKCS11.PyKCS11Error, e: 159 print "Error:", e 160 161
