~ubuntuone-control-tower/software-center/trunk

« back to all changes in this revision

Viewing changes to softwarecenter/backend/spawn_helper.py

  • Committer: Michael Vogt
  • Date: 2012-03-19 15:03:38 UTC
  • mfrom: (2876.1.1 pep8-test)
  • Revision ID: michael.vogt@ubuntu.com-20120319150338-e6joddw13792l2fh
merged     lp:~elachuni/software-center/pep8-test-part21

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
# py3 compat
23
23
try:
24
24
    import cPickle as pickle
25
 
    pickle # pyflakes
 
25
    pickle  # pyflakes
26
26
except ImportError:
27
27
    import pickle
28
28
 
37
37
 
38
38
LOG = logging.getLogger(__name__)
39
39
 
 
40
 
40
41
class SpawnHelper(GObject.GObject):
41
 
    
 
42
 
42
43
    __gsignals__ = {
43
 
        "data-available" : (GObject.SIGNAL_RUN_LAST,
44
 
                            GObject.TYPE_NONE, 
45
 
                            (GObject.TYPE_PYOBJECT,),
46
 
                            ),
47
 
        "exited" : (GObject.SIGNAL_RUN_LAST,
48
 
                    GObject.TYPE_NONE, 
49
 
                    (int,),
50
 
                    ),
51
 
        "error" : (GObject.SIGNAL_RUN_LAST,
52
 
                   GObject.TYPE_NONE, 
53
 
                   (str,),
54
 
                  ),
 
44
        "data-available": (GObject.SIGNAL_RUN_LAST,
 
45
                           GObject.TYPE_NONE,
 
46
                           (GObject.TYPE_PYOBJECT,),
 
47
                           ),
 
48
        "exited": (GObject.SIGNAL_RUN_LAST,
 
49
                   GObject.TYPE_NONE,
 
50
                   (int,),
 
51
                   ),
 
52
        "error": (GObject.SIGNAL_RUN_LAST,
 
53
                  GObject.TYPE_NONE,
 
54
                  (str,),
 
55
                 ),
55
56
        }
56
57
 
57
58
    def __init__(self, format="pickle"):
87
88
    def run(self, cmd):
88
89
        self._cmd = cmd
89
90
        (pid, stdin, stdout, stderr) = GObject.spawn_async(
90
 
            cmd, flags = GObject.SPAWN_DO_NOT_REAP_CHILD, 
 
91
            cmd, flags=GObject.SPAWN_DO_NOT_REAP_CHILD,
91
92
            standard_output=True, standard_error=True)
92
93
        LOG.debug("running: '%s' as pid: '%s'" % (cmd, pid))
93
94
        self._child_watch = GObject.child_watch_add(
104
105
        else:
105
106
            LOG.warn("exit code %s from helper for '%s'" % (res, self._cmd))
106
107
            # check stderr
107
 
            err = os.read(stderr, 4*1024)
 
108
            err = os.read(stderr, 4 * 1024)
108
109
            self._stderr = err
109
110
            if err:
110
111
                LOG.warn("got error from helper: '%s'" % err)
122
123
        data = ""
123
124
        while True:
124
125
            s = os.read(stdout, 1024)
125
 
            if not s: break
 
126
            if not s:
 
127
                break
126
128
            data += s
127
129
        os.close(stdout)
128
130
        self._stdout = data