You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Daniel Shahaf <d....@daniel.shahaf.name> on 2008/08/12 10:04:57 UTC

Re: [PATCH] hooks-scripts: fix svn2feed.py on Windows

(Patch manager hat on.  I was about to file this, but then...)

Niels de Vos wrote on Mon, 28 Jul 2008 at 10:39 +0200:
> Okay, here it is. This patch replaces the non-Windows popen2 usage with
> the platform independent subprocess module. As discussed, this requires
> at least Pyhon-2.4 as earlier versions do not contain the subprocess
> module.
> 
> Thanks,
> Niels
> 
> Index: svn2feed.py
> ===================================================================
> --- svn2feed.py	(revision 32316)
> +++ svn2feed.py	(working copy)
> @@ -78,7 +78,7 @@
>  
>  import getopt
>  import os
> -import popen2
> +import subprocess
>  import cPickle as pickle
>  import datetime
>  import time
> @@ -127,18 +127,14 @@
>          revision = str(revision)
>  
>          cmd = [self.svnlook_cmd, 'info', '-r', revision, self.repos_path]
> -        child_out, child_in, child_err = popen2.popen3(cmd)
> -        info_lines = child_out.readlines()
> -        child_out.close()
> -        child_in.close()
> -        child_err.close()
> +        proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
> +        proc.wait()
> +        info_lines = proc.stdout.readlines()
>  
>          cmd = [self.svnlook_cmd, 'changed', '-r', revision, self.repos_path]
> -        child_out, child_in, child_err = popen2.popen3(cmd)
> -        changed_data = child_out.read()
> -        child_out.close()
> -        child_in.close()
> -        child_err.close()
> +        proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
> +        proc.wait()
> +        changed_data = proc.stdout.readlines()
>  
>          desc = ("\nRevision: %s\nLog: %sModified: \n%s"
>                  % (revision, info_lines[3], changed_data))
> @@ -411,13 +407,10 @@
>          svnlook_cmd = 'svnlook'
>          if svn_path is not None:
>              svnlook_cmd = os.path.join(svn_path, 'svnlook')
> -        child_out, child_in, child_err = popen2.popen3([svnlook_cmd,
> -                                                        'youngest',
> -                                                        repos_path])
> -        cmd_out = child_out.readlines()
> -        child_out.close()
> -        child_in.close()
> -        child_err.close()
> +        cmd = [svnlook_cmd, 'youngest', repos_path]
> +        proc = subprocess.Popen(cmd)
> +        proc.wait()
> +        cmd_out = proc.stdout.readlines()

I got an error with the patched version:

    tools\hook-scripts> python -V
    Python 2.5.1

    tools\hook-scripts> python svn2feed.py -F atom -u http://bar -U http://bar C:\tmp\svn\repos1
    1
    Traceback (most recent call last):
      File "svn2feed.py", line 452, in <module>
        main()
      File "svn2feed.py", line 413, in main
        cmd_out = proc.stdout.readlines()
    AttributeError: 'NoneType' object has no attribute 'readlines'

>          try:
>              revisions = [int(cmd_out[0])]
>          except IndexError, msg:
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] hooks-scripts: fix svn2feed.py on Windows

Posted by Daniel Shahaf <d....@daniel.shahaf.name>.
Daniel Shahaf wrote on Wed, 13 Aug 2008 at 06:42 +0300:
> I'll commit in a few days if no one objects.
> 

r32513.  I wrote a log message; next time please remember to provide 
one.

> Thanks for the patch,
> 
> Daniel
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] hooks-scripts: fix svn2feed.py on Windows

Posted by Daniel Shahaf <d....@daniel.shahaf.name>.
Niels de Vos wrote on Tue, 12 Aug 2008 at 15:10 +0200:
> Ups, I' very sorry. Somehow this slipped through :(
> You should not have any problems with the patch below. I only needed to
> add 'stdout=subprocess.PIPE' to subprocess.Popen().
> 

Yes, works now.  (Well, sort of; the <author><name> tag has a ^M
character that doesn't exist in the repository, and the 'Modified' list 
is printed as a repr()'d array -- with [] and without newlines -- but I 
assume that's not due to your patch.)

I'll commit in a few days if no one objects.

Thanks for the patch,

Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] hooks-scripts: fix svn2feed.py on Windows

Posted by Niels de Vos <ni...@wincor-nixdorf.com>.
Daniel Shahaf wrote:
> (Patch manager hat on.  I was about to file this, but then...)

Ups, I' very sorry. Somehow this slipped through :(
You should not have any problems with the patch below. I only needed to
add 'stdout=subprocess.PIPE' to subprocess.Popen().

Thanks again, Niels

> Niels de Vos wrote on Mon, 28 Jul 2008 at 10:39 +0200:
>> Okay, here it is. This patch replaces the non-Windows popen2 usage with
>> the platform independent subprocess module. As discussed, this requires
>> at least Pyhon-2.4 as earlier versions do not contain the subprocess
>> module.


Index: svn2feed.py
===================================================================
--- svn2feed.py	(revision 32448)
+++ svn2feed.py	(working copy)
@@ -78,7 +78,7 @@
 
 import getopt
 import os
-import popen2
+import subprocess
 import cPickle as pickle
 import datetime
 import time
@@ -127,18 +127,14 @@
         revision = str(revision)
 
         cmd = [self.svnlook_cmd, 'info', '-r', revision, self.repos_path]
-        child_out, child_in, child_err = popen2.popen3(cmd)
-        info_lines = child_out.readlines()
-        child_out.close()
-        child_in.close()
-        child_err.close()
+        proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+        proc.wait()
+        info_lines = proc.stdout.readlines()
 
         cmd = [self.svnlook_cmd, 'changed', '-r', revision, self.repos_path]
-        child_out, child_in, child_err = popen2.popen3(cmd)
-        changed_data = child_out.read()
-        child_out.close()
-        child_in.close()
-        child_err.close()
+        proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+        proc.wait()
+        changed_data = proc.stdout.readlines()
 
         desc = ("\nRevision: %s\nLog: %sModified: \n%s"
                 % (revision, info_lines[3], changed_data))
@@ -411,13 +407,10 @@
         svnlook_cmd = 'svnlook'
         if svn_path is not None:
             svnlook_cmd = os.path.join(svn_path, 'svnlook')
-        child_out, child_in, child_err = popen2.popen3([svnlook_cmd,
-                                                        'youngest',
-                                                        repos_path])
-        cmd_out = child_out.readlines()
-        child_out.close()
-        child_in.close()
-        child_err.close()
+        cmd = [svnlook_cmd, 'youngest', repos_path]
+        proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+        proc.wait()
+        cmd_out = proc.stdout.readlines()
         try:
             revisions = [int(cmd_out[0])]
         except IndexError, msg: