CVS: python msp430-downloader.py,1.4,1.5

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

Modified Files:
	msp430-downloader.py 
Log Message:
- improve error handling
- do not show the ctypes error dialog, instead a dialog box with the messages

Index: msp430-downloader.py
===================================================================
RCS file: /cvsroot/mspgcc/python/msp430-downloader.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -d -r1.4 -r1.5
--- msp430-downloader.py	20 Nov 2004 04:35:02 -0000	1.4
+++ msp430-downloader.py	14 Jun 2005 10:17:18 -0000	1.5
@@ -31,9 +31,11 @@
 lpt = '1'
 
 
+#redirect console output
+sys.stdout = sys.stderr = StringIO()
 
 if EasyDialogs.AskYesNoCancel(
-    "Download '%s' using the JTAG interface?" % filename,
+    "Download '%s' using the JTAG interface?" % (filename,)
 ) != 1:
     sys.exit(1)
 
@@ -51,6 +53,7 @@
     jtagobj = ProgressJTAG()
     jtagobj.showprogess = True
     jtagobj.bar = EasyDialogs.ProgressBar('Programming %r...' % filename, 100)
+    showError = 0
     try:
         jtagobj.data = msp430.memory.Memory()   #prepare downloaded data
         jtagobj.data.loadFile(filename)         #autodetect filetype
@@ -66,14 +69,20 @@
                 jtagobj.actionMassErase()
             else:   #CANCEL
                 sys.exit(0)
+            showError = 1
             jtagobj.bar.label('Programming...')
             jtagobj.actionProgram()
         finally:
+            if sys.exc_info()[:1]:              #if there is an exception pending
+                jtagobj.verbose = 0             #do not write any more messages
             jtagobj.reset(1, 1)                 #reset and release target
             jtagobj.close()                     #Release communication port
     finally:
-        del jtagobj.bar
-except IOError:
+        del jtagobj.bar                         #close progress bar
+except IOError, e:
+    if showError:
+        EasyDialogs.Message('An error occoured: "%s"\n\nMessages:\n%s' % (e, sys.stdout.getvalue()))
+    else:
     EasyDialogs.Message("%s: Can't Connect to target" % name)
 except (SystemExit, KeyboardInterrupt):
     raise
@@ -82,5 +91,8 @@
     #~ traceback.print_exc(file=s)
     #~ print s.getvalue()
     #~ EasyDialogs.Message(s.getvalue())
-    EasyDialogs.Message('An error occoured: %s' % (e))
-    
\ No newline at end of file
+    EasyDialogs.Message('An error occoured: %s\nMessages:\n%s' % (e, sys.stdout.getvalue()))
+else:
+    messages = sys.stdout.getvalue()
+    if messages:
+        EasyDialogs.Message('Messages:\n%s\nSuccess!' % (messages,))
\ No newline at end of file



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
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.