Browse code

* s3cmd: Rewritten gpg_command() to use subprocess.Popen() instead of os.popen4() deprecated in 2.6

git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@355 830e0280-6d2a-0410-9c65-932aecc39d9d

Michal Ludvig authored on 2009/01/24 21:52:08
Showing 2 changed files
... ...
@@ -3,6 +3,8 @@
3 3
 	* s3cmd: Enabled --dry-run and --exclude for 'put' and 'get'.
4 4
 	* S3/Exceptions.py: Remove DeprecationWarning about 
5 5
 	  BaseException.message in Python 2.6
6
+	* s3cmd: Rewritten gpg_command() to use subprocess.Popen()
7
+	  instead of os.popen4() deprecated in 2.6
6 8
 
7 9
 2009-01-22  Michal Ludvig  <michal@logix.cz>
8 10
 
... ...
@@ -15,6 +15,7 @@ import glob
15 15
 import traceback
16 16
 import codecs
17 17
 import locale
18
+import subprocess
18 19
 
19 20
 from copy import copy
20 21
 from optparse import OptionParser, Option, OptionValueError, IndentedHelpFormatter
... ...
@@ -1019,13 +1020,13 @@ def resolve_list(lst, args):
1019 1019
 	return retval
1020 1020
 
1021 1021
 def gpg_command(command, passphrase = ""):
1022
-	p_in, p_out = os.popen4(command)
1023
-	if command.count("--passphrase-fd"):
1024
-		p_in.write(passphrase+"\n")
1025
-		p_in.flush()
1026
-	for line in p_out:
1027
-		info(line.strip())
1028
-	p_pid, p_exitcode = os.wait()
1022
+	debug("GPG command: " + " ".join(command))
1023
+	p = subprocess.Popen(command, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
1024
+	p_stdout, p_stderr = p.communicate(passphrase + "\n")
1025
+	debug("GPG output:")
1026
+	for line in p_stdout.split("\n"):
1027
+		debug("GPG: " + line)
1028
+	p_exitcode = p.wait()
1029 1029
 	return p_exitcode
1030 1030
 
1031 1031
 def gpg_encrypt(filename):