Login | Register
My pages Projects Community openCollabNet

Discussions > Commits > svn commit: r146 - trunk/repoguard: src/repoguard/core test/repoguard_test/core

repoguard
Discussion topic

Back to topic list

svn commit: r146 - trunk/repoguard: src/repoguard/core test/repoguard_test/core

Author schlauch
Full name Tobias Schlauch
Date 2012-10-26 07:01:06 PDT
Message Author: schlauch
Date: 2012-10-26 07:01:06-0700
New Revision: 146

Modified:
   trunk/repoguard/src/​repoguard/core/proce​ss.py
   trunk/repoguard/test​/repoguard_test/core​/test_process.py

Log:
Fixed ISSUE #51:
Ensured that the process module correctly transforms the command output to unicode.
This should prevent similar in issues in other handlers/checks.


Modified: trunk/repoguard/src/​repoguard/core/proce​ss.py
Url: http://repoguard.tig​ris.org/source/brows​e/repoguard/trunk/re​poguard/src/repoguar​d/core/process.py?vi​ew=diff&pathrev=​146&r1=145&r​2=146
====================​====================​====================​==================
--- trunk/repoguard/src/​repoguard/core/proce​ss.py (original)
+++ trunk/repoguard/src/​repoguard/core/proce​ss.py 2012-10-26 07:01:06-0700
@@ -1,4 +1,4 @@
-# pylint: disable-msg=W0231
+#
 # Copyright 2008 German Aerospace Center (DLR)
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,19 +13,21 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+
 """ Execute a Process and return the output. """
 
+
 import subprocess
+import sys
+
 
 class ProcessException(Exception):
     """
     Exception that can be raised when an external process execution failed.
     """
-
+
     def __init__(self, command, exit_code, output):
         """
- Constructor.
-
         :param command: The command that was executed.
         :type command: string
         
@@ -40,12 +42,12 @@
         self.command = command
         self.output = output
         self.exit_code = exit_code
-
+
     def __str__(self):
         """
         Returns the process as string representation.
         
- :return: The stirng representation of this exception.
+ :return: The string representation of this exception.
         :rtype: string
         """
         
@@ -69,12 +71,22 @@
     :raises ProcessException: Is raised when the process execution failed.
     """
     
- process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
- output = process.communicate()[0]
+ process = subprocess.Popen(
+ command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ output = _decode_to_unicode(p​rocess.communicate()​[0])
     exit_code = process.returncode
 
     if exit_code == 0:
         return output
     else:
- raise ProcessException(command, exit_code, output)
+ raise ProcessException(_de​code_to_unicode(comm​and), exit_code, output)
+
+def _decode_to_unicode(b​inary_string):
+ if binary_string is None:
+ return u""
+ elif isinstance(binary_string, unicode):
+ return binary_string
+ else:
+ return binary_string.decode​(_CONSOLE_ENCODING)
+
+_CONSOLE_ENCODING = sys.stdout.encoding or sys.getdefaultencoding() or "ascii"

Modified: trunk/repoguard/test​/repoguard_test/core​/test_process.py
Url: http://repoguard.tig​ris.org/source/brows​e/repoguard/trunk/re​poguard/test/repogua​rd_test/core/test_pr​ocess.py?view=diff​&pathrev=146&r​1=145&r2=146
====================​====================​====================​==================
--- trunk/repoguard/test​/repoguard_test/core​/test_process.py (original)
+++ trunk/repoguard/test​/repoguard_test/core​/test_process.py 2012-10-26 07:01:06-0700
@@ -32,7 +32,9 @@
     popen_class = patcher.start()
     try:
         popen_class.return_v​alue.returncode = 0
- process.execute("svnlook help")
+ popen_class.return_v​alue.communicate.ret​urn_value = ("output")
+ output = process.execute("svnlook help")
+ assert isinstance(output, unicode)
     finally:
         patcher.stop()

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

svn commit: r146 - trunk/repoguard: src/repoguard/core test/repoguard_test/core schlauch Tobias Schlauch 2012-10-26 07:01:06 PDT
Messages per page: