Sync progress

This commit is contained in:
askiiart 2022-12-15 15:24:19 -06:00
parent 795aa23c89
commit 4474ba5e29
3 changed files with 29 additions and 35 deletions

View file

@ -1,7 +1,6 @@
import os
from subprocess import getoutput
debug = True
from docker_wrapper import Docker
# Read config file and make variables
config = open('docker-composer.conf', 'rt')
@ -23,23 +22,20 @@ for dir in os.listdir(compose_path):
if os.path.isdir(compose_path + dir) and dir not in exclude_containers:
compose_dirs.append(compose_path + dir + '/')
# Print debug info
if debug:
print('Working directory: ' + working_dir)
print('Compose path: ' + compose_path)
print('Exclude containers: ' + str(exclude_containers))
print('Compose directories: ' + str(compose_dirs))
containers = []
for dir in compose_dirs:
containers.append()
# COMPOSE!
for dir in compose_dirs:
container_name = dir[:-1][dir[:-1].rfind('/')+1:]
if debug:
print('Compose dir: ' + dir)
print('Container name: ' + container_name)
getoutput(f'docker stop {container_name}')
getoutput(f'docker rm {container_name}')
os.chdir(dir)
output = getoutput('docker compose up -d')
if debug:
print(output)
for i in range(len(compose_dirs)):
dir = compose_dirs[i]
container = containers[i]
status = Docker.stop(container) # Assigned to vars so I can see
if status != 0:
print(f'Error in stopping {container}, skipping...')
status = Docker.rm(container)
if status != 0:
print(f'Error in removing {container}, skipping...')
status = Docker.compose(dir)
if status != 0:
print(f'Error in composing {container}, skipping...')

View file

@ -117,7 +117,7 @@ class Docker:
"""
cwd = os.getcwd()
os.chdir(dir)
status = getstatusoutput('docker ps')
status = getstatusoutput('docker compose up -d')
os.chdir(cwd)
return status

View file

@ -1,5 +1,5 @@
import os
from subprocess import getoutput
from docker_wrapper import Docker
debug = False
@ -23,6 +23,9 @@ for dir in os.listdir(compose_path):
if os.path.isdir(compose_path + dir) and dir not in exclude_containers:
compose_dirs.append(compose_path + dir + '/')
containers = [dir[:-1][dir[:-1].rfind('/')+1:] for dir in compose_dirs]
# Print debug info
if debug:
print('Working directory: ' + working_dir)
@ -32,28 +35,23 @@ if debug:
running = True
while running:
containers = [dir[:-1][dir[:-1].rfind('/')+1:] for dir in compose_dirs]
# Menu
print('What Docker container would you like to (re-)compose?')
print('(q) - quit')
for i in range(len(containers)):
print(f'({i}) - {containers[i]}')
print(f' {i} - {containers[i]}')
print(' q - quit')
to_compose_i = input()
if to_compose_i == 'q':
exit(0)
to_compose_i = int(to_compose_i)
# COMPOSE!
container_name = containers[to_compose_i]
if debug:
print('Container name: ' + container_name)
getoutput(f'docker stop {container_name}')
getoutput(f'docker rm {container_name}')
os.chdir(compose_dirs[to_compose_i])
output = getoutput('docker compose up -d')
if debug:
print(output)
container = containers[to_compose_i]
container_dir = compose_dirs[to_compose_i]
Docker.stop(container)
Docker.rm(container)
Docker.compose(container_dir)
print('\nWould you like to (re-)compose another container? (y/N)')
running = True if input() == 'y' else False