Archived
0
This commit is contained in:
dedic-one
2022-02-17 15:17:45 +03:00
parent 1013f44d40
commit 214884d216

29
ctl.py
View File

@@ -17,6 +17,20 @@ def di_syscall(cmd, workdir='.'):
return (process.stdout.decode("utf-8").strip(), process.stderr.decode("utf-8").strip()) 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): def di_syscall_interactive(cmd):
#print('[dbg] CMD: %s' % (cmd)) #print('[dbg] CMD: %s' % (cmd))
pty.spawn(cmd) pty.spawn(cmd)
@@ -55,12 +69,12 @@ class Container:
if self.is_run(): if self.is_run():
print('%s running' % (self.conf['title'])) print('%s running' % (self.conf['title']))
out, err = di_syscall(['podman', 'logs', '--tail', '5', self.conf['name']])
if err: print(err)
else: else:
print('%s container down' % (self.conf['title'])) 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): def start(self):
@@ -77,8 +91,9 @@ class Container:
cmd.append('--env') cmd.append('--env')
cmd.append('%s=%s' % (env_name, self.conf['env'][env_name])) cmd.append('%s=%s' % (env_name, self.conf['env'][env_name]))
cmd.append(self.conf['image']) cmd.append(self.conf['image'])
for arg in self.conf['cmd']: if self.conf.get('cmd', None) is not None:
cmd.append('%s' % arg) for arg in self.conf['cmd']:
cmd.append('%s' % arg)
container_id, err = di_syscall(cmd, self.workdir) container_id, err = di_syscall(cmd, self.workdir)
if err: if err:
@@ -107,7 +122,7 @@ class Container:
def logs(self): def logs(self):
self.__require_exists() 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): def shell(self):