VirtualBox

Changeset 71157 in vbox


Ignore:
Timestamp:
Feb 28, 2018 3:38:15 PM (7 years ago)
Author:
vboxsync
Message:

utils.py,vcs_import.py: Added printOut and printErr to utils for dealing console encoding issues in python2; use it in vcs_import.py.

Location:
trunk/src/VBox/ValidationKit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/common/utils.py

    r70710 r71157  
    66Common Utility Functions.
    77"""
     8
     9from __future__ import print_function;
    810
    911__copyright__ = \
     
    6163    xrange = range; # pylint: disable=redefined-builtin,invalid-name
    6264    long = int;     # pylint: disable=redefined-builtin,invalid-name
     65
     66
     67#
     68# Output.
     69#
     70
     71def printOut(sString):
     72    """
     73    Outputs a string to standard output, dealing with python 2.x encoding stupidity.
     74    """
     75    sStreamEncoding = sys.stdout.encoding;
     76    if sStreamEncoding == 'UTF-8' or not isinstance(sString, unicode):
     77        print(sString);
     78    else:
     79        print(sString.encode(sStreamEncoding, 'backslashreplace').decode(sStreamEncoding));
     80
     81def printErr(sString):
     82    """
     83    Outputs a string to standard error, dealing with python 2.x encoding stupidity.
     84    """
     85    sStreamEncoding = sys.stderr.encoding;
     86    if sStreamEncoding == 'UTF-8' or not isinstance(sString, unicode):
     87        print(sString, file = sys.stderr);
     88    else:
     89        print(sString.encode(sStreamEncoding, 'backslashreplace').decode(sStreamEncoding), file = sys.stderr);
    6390
    6491
  • trunk/src/VBox/ValidationKit/testmanager/batch/vcs_import.py

    r71156 r71157  
    131131                sMessage = sMessage[:VcsRevisionData.kcchMax_sMessage - 4] + ' ...';
    132132            if not self.oConfig.fQuiet:
    133                 if isinstance(sMessage, unicode) and hasattr(sMessage, 'encode'):
    134                     sMessage = sMessage.encode(sys.getdefaultencoding(), 'ignore')
    135                 print(u'sDate=%s iRev=%u sAuthor=%s sMsg[%s]=%s' % (sDate, iRevision, sAuthor, type(sMessage).__name__, sMessage));
     133                utils.printOut(u'sDate=%s iRev=%u sAuthor=%s sMsg[%s]=%s'
     134                               % (sDate, iRevision, sAuthor, type(sMessage).__name__, sMessage));
    136135            oData = VcsRevisionData().initFromValues(self.oConfig.sRepository, iRevision, sDate, sAuthor, sMessage);
    137136            oLogic.addVcsRevision(oData);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette