From 214884d216b6ee894f9a95ea20de12b376ddf476 Mon Sep 17 00:00:00 2001 From: dedic-one Date: Thu, 17 Feb 2022 15:17:45 +0300 Subject: [PATCH] update --- ctl.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/ctl.py b/ctl.py index 9c554fd..3110bd7 100755 --- a/ctl.py +++ b/ctl.py @@ -17,6 +17,20 @@ def di_syscall(cmd, workdir='.'): return (process.stdout.decode("utf-8").strip(), process.stderr.decode("utf-8").strip()) +def di_syscall_follow(cmd): + #print('[dbg] CMD: %s' % (cmd)) + process = Popen(cmd, stdout=PIPE, stderr=STDOUT) + try: + while True: + line = process.stdout.readline() + if not line: + break + else: + print(line.decode('utf-8').strip()) + except KeyboardInterrupt: + print('') + + def di_syscall_interactive(cmd): #print('[dbg] CMD: %s' % (cmd)) pty.spawn(cmd) @@ -55,12 +69,12 @@ class Container: if self.is_run(): print('%s running' % (self.conf['title'])) - out, err = di_syscall(['podman', 'logs', '--tail', '5', self.conf['name']]) - if err: print(err) else: print('%s container down' % (self.conf['title'])) - out, err = di_syscall(['podman', 'logs', '--tail', '5', self.conf['name']]) - if err: print(err) + + out, err = di_syscall(['podman', 'logs', '--tail', '5', self.conf['name']]) + if err: print(err) + else: print(out) def start(self): @@ -77,8 +91,9 @@ class Container: cmd.append('--env') cmd.append('%s=%s' % (env_name, self.conf['env'][env_name])) cmd.append(self.conf['image']) - for arg in self.conf['cmd']: - cmd.append('%s' % arg) + if self.conf.get('cmd', None) is not None: + for arg in self.conf['cmd']: + cmd.append('%s' % arg) container_id, err = di_syscall(cmd, self.workdir) if err: @@ -107,7 +122,7 @@ class Container: def logs(self): self.__require_exists() - di_syscall_interactive(['podman', 'logs', '--tail', '10', '-f', self.conf['name']]) + di_syscall_follow(['podman', 'logs', '--tail', '10', '-f', self.conf['name']]) def shell(self):