[Pcsclite-cvs-commit] r5997 - /trunk/PCSC/src/spy/pcsc-spy.py

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Tue Oct 4 13:11:06 UTC 2011


Author: rousseau
Date: Tue Oct  4 13:11:05 2011
New Revision: 5997

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=5997
Log:
Use the command line argument (if any) as the log file

If a command argument is passed we use it instead of the default
~/pcsc-spy FIFO file. It is then possible to record an execution log and
use pcsc-spy.py multiple times on the same log.

To create the log file just do:
$ mkfifo ~/pcsc-spy
$ cat ~/pcsc-spy > logfile
and run your PC/SC application

Modified:
    trunk/PCSC/src/spy/pcsc-spy.py

Modified: trunk/PCSC/src/spy/pcsc-spy.py
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/spy/pcsc-spy.py?rev=5997&op=diff
==============================================================================
--- trunk/PCSC/src/spy/pcsc-spy.py (original)
+++ trunk/PCSC/src/spy/pcsc-spy.py Tue Oct  4 13:11:05 2011
@@ -534,22 +534,30 @@
 
     def __del__(self):
         """ cleanup """
-        os.unlink(self.fifo)
-
-    def __init__(self):
-        self.fifo = os.path.expanduser('~/pcsc-spy')
-
-        # create the FIFO file
-        try:
-            os.mkfifo(self.fifo)
-        except (OSError):
-            print "fifo %s already present. Reusing it." % self.fifo
+        from stat import S_ISFIFO
+        file_stat = os.stat(self.fifo)
+
+        #  remove the log fifo only if it is a FIFO and not a log file
+        if S_ISFIFO(file_stat.st_mode):
+            os.unlink(self.fifo)
+
+    def __init__(self, logfile=None):
+        """ constructor """
+
+        # use default fifo file?
+        if logfile == None:
+            logfile = os.path.expanduser('~/pcsc-spy')
+
+            # create the FIFO file
+            try:
+                os.mkfifo(logfile)
+            except (OSError):
+                print "fifo %s already present. Reusing it." % logfile
 
         self.sec = self.usec = 0
 
+        self.fifo = logfile 
         self.filedesc = open(self.fifo, 'r')
-        #import sys
-        #self.filedesc = sys.stdin
 
         self.features = {0x01: "FEATURE_VERIFY_PIN_START",
             0x02: "FEATURE_VERIFY_PIN_FINISH",
@@ -642,11 +650,16 @@
             line = self.filedesc.readline()
 
 
-def main():
+def main(logfile=None):
     """ main """
-    spy = PCSCspy()
+    spy = PCSCspy(logfile)
     spy.loop()
 
 
 if __name__ == "__main__":
-    main()
+    import sys
+    logfile = None
+    if len(sys.argv) > 1:
+        logfile = sys.argv[1]
+
+    main(logfile)




More information about the Pcsclite-cvs-commit mailing list