Mercurial > libervia-backend
comparison sat/tools/common/async_process.py @ 3040:fee60f17ebac
jp: jp asyncio port:
/!\ this commit is huge. Jp is temporarily not working with `dbus` bridge /!\
This patch implements the port of jp to asyncio, so it is now correctly using the bridge
asynchronously, and it can be used with bridges like `pb`. This also simplify the code,
notably for things which were previously implemented with many callbacks (like pagination
with RSM).
During the process, some behaviours have been modified/fixed, in jp and backends, check
diff for details.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 25 Sep 2019 08:56:41 +0200 |
parents | 0d55a52056f7 |
children | 9d0df638c8b4 |
comparison
equal
deleted
inserted
replaced
3039:a1bc34f90fa5 | 3040:fee60f17ebac |
---|---|
74 self.err_data.append(data) | 74 self.err_data.append(data) |
75 | 75 |
76 def processEnded(self, reason): | 76 def processEnded(self, reason): |
77 data = b''.join(self.data) | 77 data = b''.join(self.data) |
78 if (reason.value.exitCode == 0): | 78 if (reason.value.exitCode == 0): |
79 log.debug(_('{name!r} command succeed').format( | 79 log.debug(_(f'{self.command_name!r} command succeed')) |
80 name=self.command_name.decode('utf-8', 'ignore'))) | |
81 # we don't use "replace" on purpose, we want an exception if decoding | 80 # we don't use "replace" on purpose, we want an exception if decoding |
82 # is not working properly | 81 # is not working properly |
83 self._deferred.callback(data) | 82 self._deferred.callback(data) |
84 else: | 83 else: |
85 err_data = b''.join(self.err_data) | 84 err_data = b''.join(self.err_data) |
104 otherwise, first argument must be the path | 103 otherwise, first argument must be the path |
105 @param **kwargs: can be: | 104 @param **kwargs: can be: |
106 - stdin(unicode, None): data to push to standard input | 105 - stdin(unicode, None): data to push to standard input |
107 - verbose(bool): if True stdout and stderr will be logged | 106 - verbose(bool): if True stdout and stderr will be logged |
108 other keyword arguments will be used in reactor.spawnProcess | 107 other keyword arguments will be used in reactor.spawnProcess |
109 @return ((D)): stdout in case of success | 108 @return ((D)bytes): stdout in case of success |
110 @raise RuntimeError: command returned a non zero status | 109 @raise RuntimeError: command returned a non zero status |
111 stdin and stdout will be given as arguments | 110 stdin and stdout will be given as arguments |
112 | 111 |
113 """ | 112 """ |
114 stdin = kwargs.pop('stdin', None) | 113 stdin = kwargs.pop('stdin', None) |
115 if stdin is not None: | 114 if stdin is not None: |
116 stdin = stdin.encode('utf-8') | 115 stdin = stdin.encode('utf-8') |
117 verbose = kwargs.pop('verbose', False) | 116 verbose = kwargs.pop('verbose', False) |
118 if 'path' in kwargs: | |
119 kwargs['path'] = kwargs['path'].encode('utf-8') | |
120 args = [a.encode('utf-8') for a in args] | 117 args = [a.encode('utf-8') for a in args] |
121 kwargs = {k:v.encode('utf-8') for k,v in list(kwargs.items())} | 118 kwargs = {k:v.encode('utf-8') for k,v in list(kwargs.items())} |
122 d = defer.Deferred() | 119 d = defer.Deferred() |
123 prot = cls(d, stdin=stdin) | 120 prot = cls(d, stdin=stdin) |
124 if verbose: | 121 if verbose: |