sam12345324 commited on
Commit
530d2a6
·
verified ·
1 Parent(s): 732e53f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+
3
+ import subprocess
4
+ import sys
5
+ import platform
6
+
7
+ IS_WINDOWS = platform.system() == 'Windows'
8
+
9
+ def check_docker_compose_up():
10
+ result = subprocess.run(
11
+ ["docker", "compose", "ps", "-q"],
12
+ capture_output=True,
13
+ text=True,
14
+ shell=IS_WINDOWS
15
+ )
16
+ return len(result.stdout.strip()) > 0
17
+
18
+ def main():
19
+ force = False
20
+ if "--help" in sys.argv:
21
+ print("Usage: ./script.py [OPTION]")
22
+ print("Manage docker-compose services interactively")
23
+ print("\nOptions:")
24
+ print(" -f\tForce start containers without confirmation")
25
+ print(" --help\tShow this help message")
26
+ return
27
+ if "-f" in sys.argv:
28
+ force = True
29
+ print("Force awakened. Skipping confirmation.")
30
+
31
+ is_up = check_docker_compose_up()
32
+
33
+ if is_up:
34
+ action = "stop"
35
+ msg = "🛑 Stop containers? [y/N] " # No default
36
+ else:
37
+ action = "start"
38
+ msg = "⚡ Start containers? [Y/n] " # Yes default
39
+
40
+ if not force:
41
+ response = input(msg).strip().lower()
42
+ if action == "stop":
43
+ # Only proceed if user explicitly types 'y'
44
+ if response != "y":
45
+ print("Aborting.")
46
+ return
47
+ else:
48
+ # Proceed unless user types 'n'
49
+ if response == "n":
50
+ print("Aborting.")
51
+ return
52
+
53
+ if action == "stop":
54
+ subprocess.run(["docker", "compose", "down"], shell=IS_WINDOWS)
55
+ else:
56
+ subprocess.run(["docker", "compose", "up", "-d"], shell=IS_WINDOWS)
57
+
58
+ if __name__ == "__main__":
59
+ main()