comparison libervia/backend/tools/common/async_process.py @ 4273:9308b2d15fd2

tools (common/async_process): accept `Path` instances as command path.
author Goffi <goffi@goffi.org>
date Thu, 20 Jun 2024 14:47:09 +0200
parents 0d7bb4df2343
children
comparison
equal deleted inserted replaced
4272:89a0999884ac 4273:9308b2d15fd2
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 """tools to launch process in a async way (using Twisted)""" 20 """tools to launch process in a async way (using Twisted)"""
21 21
22 import os.path 22 import os.path
23 from pathlib import Path
23 from typing import Any 24 from typing import Any
24 from twisted.internet import defer, reactor, protocol 25 from twisted.internet import defer, reactor, protocol
25 from twisted.python.failure import Failure 26 from twisted.python.failure import Failure
26 from libervia.backend.core.i18n import _ 27 from libervia.backend.core.i18n import _
27 from libervia.backend.core import exceptions 28 from libervia.backend.core import exceptions
141 raise ValueError( 142 raise ValueError(
142 "You must either specify cls.command or use a full path to command " 143 "You must either specify cls.command or use a full path to command "
143 "to execute as first argument" 144 "to execute as first argument"
144 ) 145 )
145 command = args.pop(0) 146 command = args.pop(0)
147 if isinstance(command, Path):
148 command = str(command)
146 if prot.name is None: 149 if prot.name is None:
147 name = os.path.splitext(os.path.basename(command))[0] 150 name = os.path.splitext(os.path.basename(command))[0]
148 prot.name = name 151 prot.name = name
149 else: 152 else:
150 command = cls.command 153 command = cls.command