Finish re_compose.py

This commit is contained in:
--global 2022-12-14 10:48:51 -06:00
parent 16c7ba3335
commit de91a99fb0
4 changed files with 62 additions and 1 deletions

View file

@ -6,7 +6,7 @@ This is a simple program to manage docker containers. It works similarly to Umbr
## How to use ## How to use
- **Note:** All scrips must be run in the same directory as the `.config` file. - **Note:** All scrips must be run in the same directory as the `.config` file.
- If you want to re-compose your containers on boot, you can run `composer.py` on boot - If you want to re-compose your containers on boot, you can run `composer.py` on boot
- If you want to re-compose your containers on demand, you can run `re-compose.py` manually - If you want to re-compose your containers on demand, you can run `re_compose.py` manually
- If you just want to do basic management, like stopping, starting, removing docker containers, etc, then use `basic-management.py`. It's essentially an interactive wrapper for the basics of docker. - If you just want to do basic management, like stopping, starting, removing docker containers, etc, then use `basic-management.py`. It's essentially an interactive wrapper for the basics of docker.
@ -24,3 +24,7 @@ I'll get to this later once this program is actually usable.
## Dev Notes ## Dev Notes
- Maybe later expand this to an interactive docker manager. - Maybe later expand this to an interactive docker manager.
## Status
- `composer.py` and `re_compose` are finished
- Haven't started on `basic_management.py`

View file

View file

57
re_compose.py Normal file
View file

@ -0,0 +1,57 @@
import os
from subprocess import getoutput
debug = False
# Read config file and make variables
config = open('docker-composer.conf', 'rt')
working_dir = os.getcwd()
compose_path = config.readline()
compose_path = compose_path[compose_path.find('=')+1:].strip()
if compose_path[-1:] != '/':
compose_path += '/'
exclude_containers = config.readline()
exclude_containers = [container.strip() for container \
in exclude_containers[exclude_containers.find('=')+1:].split(',')]
compose_dirs = []
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))
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]}')
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)
print('\nWould you like to (re-)compose another container? (y/N)')
running = True if input() == 'y' else False