From 4474ba5e2910e420804e9b4570a467291b4d9ce4 Mon Sep 17 00:00:00 2001 From: askiiart <--global> Date: Thu, 15 Dec 2022 15:24:19 -0600 Subject: [PATCH] Sync progress --- composer.py | 36 ++++++++++++++++-------------------- docker_wrapper.py | 2 +- re_compose.py | 26 ++++++++++++-------------- 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/composer.py b/composer.py index 5d962b8..674a49d 100644 --- a/composer.py +++ b/composer.py @@ -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...') diff --git a/docker_wrapper.py b/docker_wrapper.py index 4e07ef0..00d2f7f 100644 --- a/docker_wrapper.py +++ b/docker_wrapper.py @@ -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 diff --git a/re_compose.py b/re_compose.py index 4c230bd..ca1a87b 100644 --- a/re_compose.py +++ b/re_compose.py @@ -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