CVS: python/msp430 jtag.py,1.22,1.23

Chris Liechti <[email protected]>
Newsgroups gmane.comp.hardware.texas-instruments.msp430.gcc.cvs
Message-ID <[email protected]>
Update of /cvsroot/mspgcc/python/msp430
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21205/python/msp430

Modified Files:
	jtag.py 
Log Message:
- update backend detection, library search
- move debug output message

Index: jtag.py
===================================================================
RCS file: /cvsroot/mspgcc/python/msp430/jtag.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -w -d -r1.22 -r1.23
--- jtag.py	4 Apr 2006 21:58:10 -0000	1.22
+++ jtag.py	7 Apr 2006 20:01:06 -0000	1.23
@@ -45,8 +45,10 @@
 class JTAGException(Exception): pass
 
 backend = None
+backend_info = None
 def init_backend(force=None):
     global backend
+    global backend_info
     global _parjtag
     
     #1st try the ctypes implementation, if that's not available try to use the C extension
@@ -74,11 +76,13 @@
         #create a wrapper class with ctypes, that has the same API as _parjtag
         def locate_library(libname, paths=sys.path, loader=ctypes.windll):
             for path in paths:
+                if path.lower().endswith('.zip'):
+                    path = os.path.dirname(path)
                 library = os.path.join(path, libname)
-                if DEBUG: sys.stderr.write('trying %r...\n' % library)
+                if DEBUG > 4: sys.stderr.write('trying %r...\n' % library)
                 if os.path.exists(library):
-                    if DEBUG: sys.stderr.write('using %r\n' % library)
-                    return loader.LoadLibrary(library)
+                    if DEBUG > 4: sys.stderr.write('using %r\n' % library)
+                    return loader.LoadLibrary(library), library
             else:
                 raise IOError('%s not found' % libname)
         
@@ -89,7 +93,7 @@
         try:
             search_path.insert(0, os.environ['LIBMSPGCC_PATH'])
         except KeyError:
-            if DEBUG: sys.stderr.write('LIBMSPGCC_PATH is not set\n')
+            if DEBUG > 4: sys.stderr.write('LIBMSPGCC_PATH is not set\n')
         #as fallback, append PATH
         try:
             search_path.extend(os.environ['PATH'].split(os.pathsep))
@@ -107,26 +111,26 @@
             #the library is found on the PATH, respectively in the executables directory
             
             if force == CTYPES_MSPGCC:
-                MSP430mspgcc = locate_library('MSP430mspgcc.dll', search_path)
+                MSP430mspgcc, backend_info = locate_library('MSP430mspgcc.dll', search_path)
                 backend = CTYPES_MSPGCC
             elif force == CTYPES_TI:
                 #~ MSP430mspgcc = ctypes.windll.MSP430
-                MSP430mspgcc = locate_library('MSP430.dll', search_path)
+                MSP430mspgcc, backend_info = locate_library('MSP430.dll', search_path)
                 backend = CTYPES_TI
             else:
                 #autodetect
                 try:
                     #try to use the TI or third party library
-                    MSP430mspgcc = locate_library('MSP430.dll', search_path)
+                    MSP430mspgcc, backend_info = locate_library('MSP430.dll', search_path)
                     backend = CTYPES_TI
                 except IOError:
                     #when that fails, use the mspgcc implementation
-                    MSP430mspgcc = locate_library('MSP430mspgcc.dll', search_path)
+                    MSP430mspgcc, backend_info = locate_library('MSP430mspgcc.dll', search_path)
                     backend = CTYPES_MSPGCC
         else:
             #now try to locate library
             try:
-                MSP430mspgcc = locate_library('libMSP430mspgcc.so', search_path, ctypes.cdll)
+                MSP430mspgcc, backend_info = locate_library('libMSP430mspgcc.so', search_path, ctypes.cdll)
             except IOError, e:
                 raise IOError('The environment variable "LIBMSPGCC_PATH" must point to the folder that contains "libMSP430mspgcc.so": %s' % e)
             backend = CTYPES_MSPGCC
@@ -387,6 +391,10 @@
         
         _parjtag = ParJTAG()
 
+    # print the used backend
+    if DEBUG:
+        sys.stderr.write("JTAG backend: %s (%s)\n" % (backend, backend_info))
+
 
 class JTAG:
     """wrap the _parjtag extension.
@@ -395,7 +403,6 @@
     """
 
     def __init__(self):
-        if backend is None: init_backend()
         self.showprogess = 0
         self.data = None
         self.verbose = 1
@@ -404,6 +411,7 @@
     
     def open(self, lpt=None):
         """Initialize and open port."""
+        if backend is None: init_backend()
         if lpt is None:
             _parjtag.open()
         else:



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.