Use subprocess instead of deprecated popen2 module
authorThomas Leonard <talex5@gmail.com>
Sun, 28 Dec 2008 14:29:38 +0000 (28 14:29 +0000)
committerThomas Leonard <talex5@gmail.com>
Sun, 28 Dec 2008 14:35:00 +0000 (28 14:35 +0000)
tests/allpython.sh
zeroinstall/0launch-gui/compile.py
zeroinstall/gtkui/addbox.py
zeroinstall/helpers.py
zeroinstall/injector/iface_cache.py
zeroinstall/zerostore/manifest.py

index bfbb995..0acad3a 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/sh
 set -e -x
-for version in 2.4 2.5 2.6; do
+for version in 2.4 2.5 "2.6 -3"; do
   python$version ./testall.py
 done
index a12a912..cfcf1cf 100644 (file)
@@ -1,7 +1,7 @@
 # Copyright (C) 2008, Thomas Leonard
 # See the README file for details, or visit http://0install.net.
 
-import os, popen2
+import os, subprocess
 import gobject
 import dialog
 from logging import info
@@ -19,9 +19,10 @@ class Command:
        def run(self, command, success):
                assert self.child is None
                self.success = success
-               self.child = popen2.Popen4(command)
-               self.child.tochild.close()
-               gobject.io_add_watch(self.child.fromchild, gobject.IO_IN | gobject.IO_HUP, self.got_data)
+               self.child = subprocess.Popen(command,
+                                               stdout = subprocess.PIPE,
+                                               stderr = subprocess.STDOUT)
+               gobject.io_add_watch(self.child.stdout, gobject.IO_IN | gobject.IO_HUP, self.got_data)
        
        def got_data(self, src, cond):
                data = os.read(src.fileno(), 100)
index 455407e..e235bea 100644 (file)
@@ -108,11 +108,12 @@ class AddBox:
                                        return
                                self.window.set_sensitive(False)
                                self.set_keep_above(False)
-                               import popen2
-                               child = popen2.Popen4(['0launch',
+                               import subprocess
+                               child = subprocess.Popen(['0launch',
                                                  '--gui', '--download-only',
-                                                 '--', iface])
-                               child.tochild.close()
+                                                 '--', iface],
+                                                 stdout = subprocess.PIPE,
+                                                 stderr = subprocess.STDOUT)
                                errors = ['']
                                def output_ready(src, cond):
                                        got = os.read(src.fileno(), 100)
@@ -135,7 +136,7 @@ class AddBox:
                                                        box.destroy()
                                                return False
                                        return True
-                               gobject.io_add_watch(child.fromchild,
+                               gobject.io_add_watch(child.stdout,
                                                           gobject.IO_IN | gobject.IO_HUP,
                                                           output_ready)
                        elif resp == gtk.RESPONSE_OK:
index f73b966..3eacfcc 100644 (file)
@@ -88,7 +88,7 @@ def get_selections_gui(iface_uri, gui_args, test_callback = None):
                                                output = test_callback(sels)
                                        logging.info("Sending results to GUI...")
                                        output = ('Length:%8x\n' % len(output)) + output
-                                       logging.debug("Sending: %s" % `output`)
+                                       logging.debug("Sending: %s", repr(output))
                                        while output:
                                                sent = cli.send(output)
                                                output = output[sent:]
index 6a69c3c..62d2492 100644 (file)
@@ -156,7 +156,7 @@ class PendingFeed(object):
                        self.sigs = sigs
                except:
                        self.signed_data.seek(0)
-                       info("Failed to check GPG signature. Data received was:\n" + `self.signed_data.read()`)
+                       info("Failed to check GPG signature. Data received was:\n" + repr(self.signed_data.read()))
                        raise
 
 class IfaceCache(object):
index 7302706..266ae75 100644 (file)
@@ -25,13 +25,15 @@ A top-level ".manifest" file is ignored.
 
 from __future__ import generators
 import os, stat
-import sha
 from zeroinstall import SafeException
 from zeroinstall.zerostore import BadDigest
 
 try:
        import hashlib
+       sha1_new = hashlib.sha1
 except:
+       import sha
+       sha1_new = sha.new
        hashlib = None
 
 class Algorithm:
@@ -82,13 +84,13 @@ class OldSHA1(Algorithm):
                        assert sub[1:]
                        leaf = os.path.basename(sub[1:])
                        if stat.S_ISREG(m):
-                               d = sha.new(file(full).read()).hexdigest()
+                               d = sha1_new(file(full).read()).hexdigest()
                                if m & 0111:
                                        yield "X %s %s %s %s" % (d, int(info.st_mtime) ,info.st_size, leaf)
                                else:
                                        yield "F %s %s %s %s" % (d, int(info.st_mtime) ,info.st_size, leaf)
                        elif stat.S_ISLNK(m):
-                               d = sha.new(os.readlink(full)).hexdigest()
+                               d = sha1_new(os.readlink(full)).hexdigest()
                                # Note: Can't use utime on symlinks, so skip mtime
                                yield "S %s %s %s" % (d, info.st_size, leaf)
                        else:
@@ -97,7 +99,7 @@ class OldSHA1(Algorithm):
                for x in recurse('/'): yield x
        
        def new_digest(self):
-               return sha.new()
+               return sha1_new()
 
        def getID(self, digest):
                return 'sha1=' + digest.hexdigest()
@@ -402,7 +404,7 @@ class HashLibAlgorithm(Algorithm):
 
        def __init__(self, name):
                if name == 'sha1':
-                       self.new_digest = sha.new
+                       self.new_digest = sha1_new
                        self.name = 'sha1new'
                else:
                        self.new_digest = getattr(hashlib, name)