Login | Register
My pages Projects Community openCollabNet

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

repoguard
Discussion topic

Back to topic list

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

Author schlauch
Full name Tobias Schlauch
Date 2012-11-02 09:59:07 PDT
Message Author: schlauch
Date: 2012-11-02 09:59:07-0700
New Revision: 148

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

Log:
Fixes ISSUE #51:
Added an option raw_out to the execute function. In this case the output of the command is not decoded.
The default is False.
The svn cat command makes use of this.

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=​148&r1=147&r​2=148
====================​====================​====================​==================
--- trunk/repoguard/src/​repoguard/core/proce​ss.py (original)
+++ trunk/repoguard/src/​repoguard/core/proce​ss.py 2012-11-02 09:59:07-0700
@@ -58,12 +58,14 @@
         return self.__str__()
 
 
-def execute(command):
+def execute(command, raw_out=False):
     """
     Executes a given command as external process.
     
     :param command: The command that has to be executed.
     :type command: string
+ :param raw_out: Option which indicates wether the output should be decided to unicode.
+ :type raw_out: boolean
     
     :return: Returns the process output.
     :rtype: string
@@ -73,7 +75,7 @@
     
     process = subprocess.Popen(
         command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- output = _decode_to_unicode(p​rocess.communicate()​[0])
+ output = _decode_to_unicode(p​rocess.communicate()​[0], raw_out)
     exit_code = process.returncode
 
     if exit_code == 0:
@@ -81,7 +83,9 @@
     else:
         raise ProcessException(_de​code_to_unicode(comm​and), exit_code, output)
 
-def _decode_to_unicode(b​inary_string):
+def _decode_to_unicode(b​inary_string, raw_out=False):
+ if raw_out:
+ return binary_string
     if binary_string is None:
         return u""
     elif isinstance(binary_string, unicode):

Modified: trunk/repoguard/src/​repoguard/core/trans​action.py
Url: http://repoguard.tig​ris.org/source/brows​e/repoguard/trunk/re​poguard/src/repoguar​d/core/transaction.p​y?view=diff&path​rev=148&r1=147​&r2=148
====================​====================​====================​==================
--- trunk/repoguard/src/​repoguard/core/trans​action.py (original)
+++ trunk/repoguard/src/​repoguard/core/trans​action.py 2012-11-02 09:59:07-0700
@@ -55,7 +55,7 @@
         self.tmpdir = tempfile.mkdtemp()
         self.cache = {}
 
- def _execute_svn(self, command, arg="", split=False):
+ def _execute_svn(self, command, arg="", split=False, raw_out=False):
         if self.txn_name is None:
             command = 'svnlook %s "%s" %s' % (command, self.repos_path, arg)
         else:
@@ -65,7 +65,7 @@
             return self.cache[command]
         
         try:
- output = process.execute(command)
+ output = process.execute(command, raw_out)
         except process.ProcessException, error:
             if "Transaction '(null)'" in error.output: # Nothing bad happened we just have an empty repository
                 output = ""
@@ -142,7 +142,7 @@
         if os.path.exists(tmpfilename):
             return tmpfilename
 
- content = self._execute_svn("cat", "\"" + filename + "\"")
+ content = self._execute_svn("cat", "\"" + filename + "\"", raw_out=True)
 
         dirname = os.path.dirname(filename)
         tmpdirname = os.path.join(self.tmpdir, dirname)

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=148&r​1=147&r2=148
====================​====================​====================​==================
--- trunk/repoguard/test​/repoguard_test/core​/test_process.py (original)
+++ trunk/repoguard/test​/repoguard_test/core​/test_process.py 2012-11-02 09:59:07-0700
@@ -38,6 +38,17 @@
     finally:
         patcher.stop()
         
+def test_execute_raw_out():
+ patcher = mock.patch("repoguar​d.core.process.subpr​ocess.Popen")
+ popen_class = patcher.start()
+ try:
+ popen_class.return_v​alue.returncode = 0
+ popen_class.return_v​alue.communicate.ret​urn_value = ("output")
+ output = process.execute("svnlook help", raw_out=True)
+ assert isinstance(output, str)
+ finally:
+ patcher.stop()
+
 def test_execute_error():
     patcher = mock.patch("repoguar​d.core.process.subpr​ocess.Popen")
     popen_class = patcher.start()

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

Messages

Show all messages in topic

svn commit: r148 - trunk/repoguard: src/repoguard/core test/repoguard_test/core schlauch Tobias Schlauch 2012-11-02 09:59:07 PDT
Messages per page: