Skip to content

Commit 7c87106

Browse files
committed
Update __init__.py
1 parent 6cf4066 commit 7c87106

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

philh_myftp_biz/__init__.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ def __stdout(self) -> None:
279279

280280
#
281281
self.stdout = ''
282+
283+
#
284+
self.stdcomb = ''
282285

283286
#
284287
if not self.__hide:
@@ -289,6 +292,8 @@ def __stdout(self) -> None:
289292
#
290293
self.stdout += line
291294

295+
self.stdcomb += line
296+
292297
#
293298
if not self.__hide:
294299
terminal.write(line, 'out')
@@ -305,6 +310,8 @@ def __stderr(self) -> None:
305310

306311
self.stderr += line
307312

313+
self.stdcomb += line
314+
308315
if not self.__hide:
309316
terminal.write(line, 'err')
310317

@@ -337,6 +344,8 @@ def start(self) -> None:
337344
"""Process Runtime"""
338345
self.__stopwatch.start()
339346

347+
self.stdcomb = ''
348+
340349
# Start Output Manager
341350
thread(self.__stdout)
342351

@@ -355,6 +364,12 @@ def finished(self) -> bool:
355364
Check if the subprocess is finished
356365
"""
357366
return (not self.__task.exists())
367+
368+
def running(self) -> bool:
369+
"""
370+
Check if the subprocess is still running
371+
"""
372+
return self.__task.exists()
358373

359374
def restart(self) -> None:
360375
"""
@@ -386,15 +401,18 @@ def stop(self) -> None:
386401
self.__stopwatch.stop()
387402

388403
def output(self,
389-
format: Literal['json', 'hex'] = None
404+
format: Literal['json', 'hex'] = None,
405+
stream: Literal['out', 'err', 'comb'] = 'comb'
390406
) -> 'str | dict | list | bool | Any':
391407
"""
392408
Read the output from the Subprocess
393409
"""
394410
from . import json
395411
from .text import hex
396412

397-
output = self.stdout.encode().strip()
413+
stream: str = getattr(self, 'std'+stream)
414+
415+
output = stream.encode().strip()
398416

399417
if format == 'json':
400418
return json.loads(output)

philh_myftp_biz/modules.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,7 @@ class Service:
301301

302302
def __init__(self,
303303
module: Module,
304-
path: str,
305-
*args
304+
path: str
306305
):
307306

308307
self.__mod = module
@@ -312,8 +311,6 @@ def __init__(self,
312311
else:
313312
self.__path = path+'/'
314313

315-
self.__args = args
316-
317314
def Start(self,
318315
force: bool = True
319316
):
@@ -322,10 +319,18 @@ def Start(self,
322319
323320
Will do nothing if already running unless force is True
324321
"""
325-
if force or (not self.Running()):
326-
self.__mod.runH(
327-
self.__path+'Start', *self.__args
328-
)
322+
323+
arg = self.__path+'Start'
324+
325+
if force:
326+
327+
self.Stop()
328+
329+
self.__mod.runH(arg)
330+
331+
elif not self.Running():
332+
333+
self.__mod.runH(arg)
329334

330335
def Running(self) -> bool:
331336
"""
@@ -342,6 +347,4 @@ def Stop(self) -> None:
342347
"""
343348
Stop the Service
344349
"""
345-
self.__mod.runH(
346-
self.__path+'Stop', *self.__args
347-
)
350+
self.__mod.runH(self.__path+'Stop')

0 commit comments

Comments
 (0)