Changeset 401:15ad3c16ee11


Ignore:
Timestamp:
12/27/12 08:04:59 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

The exception strings are converted from UTF-8 to unicode for proper logging (re #170)

Location:
src/mlx
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/config.py

    r392 r401  
    22
    33import const
    4 from util import secondaryInstallation
     4from util import secondaryInstallation, utf2unicode
    55
    66import os
     
    788788            self._modified = False
    789789        except Exception, e:
    790             print >> sys.stderr, "Failed to update config: " + str(e)
     790            print >> sys.stderr, "Failed to update config: " + \
     791                                 utf2unicode(str(e))
    791792
    792793    def _getBoolean(self, config, section, option, default):
  • src/mlx/fsuipc.py

    r394 r401  
    104104            return fun()
    105105        except Exception, e:
    106             print >> sys.stderr, str(e)
     106            print >> sys.stderr, util.utf2unicode(str(e))
    107107            return None
    108108
     
    386386                return attempts
    387387            except Exception, e:
    388                 print "fsuipc.Handler._connect: connection failed: " + str(e) + \
     388                print "fsuipc.Handler._connect: connection failed: " + \
     389                      util.utf2unicode(str(e)) + \
    389390                      " (attempts: %d)" % (attempts,)
    390391                if attempts<self.NUM_CONNECTATTEMPTS:
     
    446447            except Exception as e:
    447448                print "fsuipc.Handler._processRequest: FSUIPC connection failed (" + \
    448                       str(e) + "), reconnecting (attempts=%d)." % (attempts,)
     449                      util.utf2unicode(str(e)) + \
     450                      "), reconnecting (attempts=%d)." % (attempts,)
    449451                needReconnect = True
    450452
     
    895897
    896898        Return if a new model was created."""
     899        name = self._latin1decoder(name)[0]
     900        airPath = self._latin1decoder(airPath)[0]
     901
    897902        aircraftName = (name, airPath)
    898903        if aircraftName==self._aircraftName:
     
    912917
    913918        if needNew:
    914             self._setAircraftModel(AircraftModel.create(self._aircraft, aircraftName))
    915 
    916 
    917         self._aircraft.modelChanged(timestamp, self._latin1decoder(name)[0],
    918                                     self._aircraftModel.name)
     919            self._setAircraftModel(AircraftModel.create(self._aircraft,
     920                                                        aircraftName))
     921
     922        self._aircraft.modelChanged(timestamp, name, self._aircraftModel.name)
    919923
    920924        return needNew
  • src/mlx/gui/common.py

    r373 r401  
    9696        """Convert the given text, returned by xstr to a string."""
    9797        return str(text)
     98
    9899else:
    99100    print "Using PyGObject"
     
    106107    from gi.repository import Pango as pango
    107108    appIndicator = True
    108    
     109
    109110    MESSAGETYPE_ERROR = gtk.MessageType.ERROR
    110111    MESSAGETYPE_QUESTION = gtk.MessageType.QUESTION
     
    156157    import codecs
    157158    _utf8Decoder = codecs.getdecoder("utf-8")
    158    
     159
    159160    def text2unicode(str):
    160161        """Convert the given text, returned by a Gtk widget, to Unicode."""
     
    182183        self._noGoReason = None
    183184        self._updateFlightStatus()
    184        
     185
    185186    def setStage(self, stage):
    186187        """Set the stage of the flight."""
     
    233234            self.emit("integer-changed", self._currentInteger)
    234235        self._set_text()
    235    
     236
    236237    def _handle_changed(self, widget):
    237238        """Handle the changed signal."""
     
    253254                      else str(self._currentInteger))
    254255        self._selfSetting = False
    255                
     256
    256257#------------------------------------------------------------------------------
    257258
  • src/mlx/gui/flight.py

    r393 r401  
    512512                    flight.writeIntoFile(f)
    513513            except Exception, e:
    514                 print "Failed to save flight:", str(e)
     514                print "Failed to save flight:", util.utf2unicode(str(e))
    515515                dialog = gtk.MessageDialog(parent = self._wizard.gui.mainWindow,
    516516                                           type = MESSAGETYPE_ERROR,
     
    555555                self._addFlight(bookedFlight)
    556556            except Exception, e:
    557                 print "Failed to load flight:", str(e)
     557                print "Failed to load flight:", util.utf2unicode(str(e))
    558558                dialog = gtk.MessageDialog(parent = self._wizard.gui.mainWindow,
    559559                                           type = MESSAGETYPE_ERROR,
  • src/mlx/pirep.py

    r393 r401  
     1
     2from util import utf2unicode
    13
    24import const
     
    5254                return pirep
    5355        except Exception, e:
    54             print "Failed loading PIREP from %s: %s" % (path, str(e))
     56            print "Failed loading PIREP from %s: %s" % (path,
     57                                                        utf2unicode(str(e)))
    5558            return None
    5659
     
    157160            return None
    158161        except Exception, e:
    159             error = str(e)
    160             #print u"Failed saving PIREP to %s: %s" % (path, error)
     162            error = utf2unicode(str(e))
     163            print u"Failed saving PIREP to %s: %s" % (path, error)
    161164            return error
  • src/mlx/singleton.py

    r298 r401  
     1
     2from util import utf2unicode
    13
    24import os
     
    7274                                print "singleton._PipeServer.run: failed to read from the pipe"
    7375                    except Exception, e:
    74                         print "singleton._PipeServer.run: exception:", str(e)
     76                        print "singleton._PipeServer.run: exception:",
     77                        print utf2unicode(str(e))
    7578                    finally:
    7679                        win32pipe.DisconnectNamedPipe(handle)
    7780                        win32file.CloseHandle(handle)
    7881            except Exception, e:
    79                 print "singleton._PipeServer.run: fatal exception:", str(e)
     82                print "singleton._PipeServer.run: fatal exception:",
     83                print utf2unicode(str(e))
    8084                           
    8185        def _createPipe(self):
     
    141145                    return
    142146                except Exception, e:
    143                     print "SingleInstance._notifySingleton: failed:", str(e)
     147                    print "SingleInstance._notifySingleton: failed:",
     148                    print utf2unicode(str(e))
    144149                    time.sleep(0.5)
    145150       
     
    190195                    self._raiseCallback()
    191196            except Exception, e:
    192                 print "singleton._SocketServer.run: fatal exception:", str(e)           
     197                print "singleton._SocketServer.run: fatal exception:",
     198                print utf2unicode(str(e))
    193199   
    194200    class SingleInstance(object):
     
    254260                    return
    255261                except Exception, e:
    256                     print "singleton.SingleInstance._notifySingleton: failed:", str(e)
     262                    print "singleton.SingleInstance._notifySingleton: failed:",
     263                    print utf2unicode(str(e))
    257264                    time.sleep(0.5)
    258265
  • src/mlx/sound.py

    r299 r401  
     1
     2from util import utf2unicode
    13
    24import os
     
    115117                        print "Closed", alias
    116118                    except Exception, e:
    117                         print "Failed closing " + alias + ":", str(e)
     119                        print "Failed closing " + alias + ":",
     120                        print utf2unicode(str(e))
    118121                        success = False
    119122
     
    143146                        print "Started to play", path
    144147                    except Exception, e:
    145                         print "Failed to start playing " + path + ":", str(e)                       
     148                        print "Failed to start playing " + path + ":",
     149                        print utf2unicode(str(e))
    146150                        (finishCallback, extra) = finishData
    147151                        if finishCallback is not None:
  • src/mlx/update.py

    r298 r401  
    11
    22from config import Config
     3from util import utf2unicode
    34
    45import os
     
    206207            manifest.readFrom(f)
    207208    except Exception, e:
    208         print "Error reading the manifest, ignoring:", str(e)
     209        print "Error reading the manifest, ignoring:", utf2unicode(str(e))
    209210        manifest = Manifest()
    210211
     
    228229
    229230    except Exception, e:
    230         print >> sys.stderr, "Error downloading manifest:", str(e)
    231         listener.failed(str(e))
     231        error = utf2unicode(str(e))
     232        print >> sys.stderr, "Error downloading manifest:", error
     233        listener.failed(error)
    232234        return None
    233235    finally:
     
    291293            os.rename(path, os.path.join(toremoveDir, sum.hexdigest()))
    292294        except Exception, e:
    293             print "Cannot remove file " + path + ": " + str(e)   
     295            print "Cannot remove file " + path + ": " + utf2unicode(str(e))
    294296
    295297#------------------------------------------------------------------------------
     
    370372        listener.done()
    371373    except Exception, e:
    372         print >> sys.stderr, "Error:", str(e)
    373         listener.failed(str(e))       
     374        error = utf2unicode(str(e))
     375        print >> sys.stderr, "Error:", error
     376        listener.failed(error)
    374377
    375378#------------------------------------------------------------------------------
     
    432435        except Exception, e:
    433436            print >> sys.stderr, "Failed to parse line '%s': %s" % \
    434                   (line, str(e))               
     437                  (line, utf2unicode(str(e)))
    435438
    436439    return buffer
     
    488491       
    489492    except Exception, e:
    490         print >> sys.stderr, "Failed updating:", str(e)
    491         listener.failed(str(e))
     493        error = utf2unicode(str(e))
     494        print >> sys.stderr, "Failed updating:", error
     495        listener.failed(error)
    492496    finally:
    493497        if serverSocket is not None:
  • src/mlx/util.py

    r373 r401  
    33import time
    44import sys
     5import codecs
    56
    67#------------------------------------------------------------------------------
     
    165166
    166167secondaryInstallation="secondary" in sys.argv
     168
     169#------------------------------------------------------------------------------
     170
     171_utf8decoder = codecs.getdecoder("utf-8")
     172
     173def utf2unicode(text):
     174    """Convert the given text from UTF-8 encoding to unicode."""
     175    return unicode(_utf8decoder(text)[0])
  • src/mlx/web.py

    r326 r401  
    465465            self._callback(returned, result)
    466466        except Exception, e:
    467             print >> sys.stderr, "web.Handler.Request.perform: callback throwed an exception: " + str(e)
     467            print >> sys.stderr, "web.Handler.Request.perform: callback throwed an exception: " + util.utf2unicode(str(e))
    468468            traceback.print_exc()
    469469
Note: See TracChangeset for help on using the changeset viewer.