rdiff-backup-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [rdiff-backup-users] DeprecationWarning: os.popen2 is deprecated. Us


From: Andreas Olsson
Subject: Re: [rdiff-backup-users] DeprecationWarning: os.popen2 is deprecated. Use the subprocess module. + patch
Date: Wed, 24 Mar 2010 14:55:23 +0100

ons 2010-03-24 klockan 14:34 +0100 skrev Danilo Godec:
> >  DeprecationWarning: os.popen2 is deprecated.  Use the subprocess module.
> 
> It looks harmless and rdiff-backup still work as I'm used to, but it
> caught my attention pretty much every day which started to get on my nerve.

See also http://savannah.nongnu.org/bugs/?26064

(The solutions proposed there are along the same line as your idea.)

// Andreas

> So I searched for a solution or work-around and came up with this patch
> (I'm no programmer though, so this might be a really bad way of 'fixing'
> it):
> 
> ---- START ---
> diff -Nur rdiff-backup-1.2.8-orig//rdiff_backup/SetConnections.py
> rdiff-backup-1.2.8//rdiff_backup/SetConnections.py
> --- rdiff-backup-1.2.8-orig//rdiff_backup/SetConnections.py    
> 2009-03-16 15:36:21.000000000 +0100
> +++ rdiff-backup-1.2.8//rdiff_backup/SetConnections.py  2010-03-24
> 13:57:32.000000000 +0100
> @@ -145,7 +145,14 @@
>                 except OSError:
>                         (stdin, stdout) = (None, None)
>         else:
> -               stdin, stdout = os.popen2(remote_cmd)
> +               import subprocess
> +               try:
> +                       process = subprocess.Popen(remote_cmd,
> shell=True, bufsize=0,
> +                                                              
> stdin=subprocess.PIPE,
> +                                                              
> stdout=subprocess.PIPE)
> +                       (stdin, stdout) = (process.stdin, process.stdout)
> +               except OSError:
> +                       (stdin, stdout) = (None, None)
>         conn_number = len(Globals.connections)
>         conn = connection.PipeConnection(stdout, stdin, conn_number)
> ---- END ---
> 
> I noticed that the 'subprocess' module is already used for Windows ('if
> os.name == "nt"), so I tried to use the same code instead 'os.popen2'. I
> had to change 'shell=false' to 'shell=true' to make it work.
> 
> I did a couple of test runs and it seems to work, so I'll put it in use
> on my systems and keep an eye on them. If anything comes up, I'll report.
> 
>  Regards, Danilo
> 
> 
> 
> _______________________________________________
> rdiff-backup-users mailing list at address@hidden
> http://lists.nongnu.org/mailman/listinfo/rdiff-backup-users
> Wiki URL: http://rdiff-backup.solutionsfirst.com.au/index.php/RdiffBackupWiki

Attachment: signature.asc
Description: Detta är en digitalt signerad meddelandedel


reply via email to

[Prev in Thread] Current Thread [Next in Thread]