-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgentle.py
More file actions
44 lines (34 loc) · 1.45 KB
/
gentle.py
File metadata and controls
44 lines (34 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import subprocess
from tqdm import tqdm
container_name = "lowerquality-gentle"
image_name = "lowerquality/gentle"
def start():
container_status = check_if_container_exists(container_name)
if container_status == False:
create_container()
tqdm.write("Container does not exist. Creating container now...")
else:
start_container()
tqdm.write("Starting gentle docker container...")
def start_container():
cmd = f"docker start > /dev/null {container_name}" # "> /dev/null" sends the output into the dark abyss (gets rid it)
run_command_async(cmd)
def create_container():
cmd = f"docker run -p 8765:8765 --name {container_name} {image_name}"
run_command_async(cmd)
def check_if_container_exists(container_name):
try:
result = subprocess.run(
["docker", "ps", "-a", "--filter", f"name={container_name}", "--format", "{{.Names}}"],
capture_output=True, text=True, check=True
)
return container_name in result.stdout.strip().split("\n") # Should I just return true? Does the name need to be returned?
except subprocess.CalledProcessError:
return False
def stop_docker(container_name):
cmd = f"docker stop {container_name}"
run_command(cmd)
def run_command_async(cmd):
subprocess.Popen(cmd, shell=True, text=True)
def run_command(cmd):
return subprocess.run(cmd, capture_output=True, shell=True, text=True)