-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_python.py
144 lines (116 loc) · 4.28 KB
/
docker_python.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import os
import speech_recognition as sr
def design_1():
os.system(" tput setaf 1 ")
os.system(" tput bold ")
print(" \t\t\t========================================================")
os.system(" espeak-ng -a 170 -s 150 ' Docker Automation' ")
print(" \t\t\t!!----------->> Docker Menu Automation <<-------------!!")
os.system(" tput setaf 2 ")
print(" \t\t\t========================================================")
os.system(" tput setaf 4 ")
def design_2():
print(" \t\t/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/")
os.system(" tput setaf 1 ")
os.system(" tput bold ")
print(" \t\t\t\t\t***** Python Set up ***** ")
os.system(" espeak-ng -a 170 -s 150 ' Docker Automation' ")
os.system(" tput setaf 2 ")
print(" \t\t\t\t______________________________________\n")
os.system(" tput setaf 4 ")
def docker():
print("""
Services:
\t-------> Install Python on Docker
\t-------> Write Code in Python
\t-------> Show Python Code
\t-------> Run Python Code
\t-------> Back to Main Menu
""")
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print()
print("\t\t\t\tI am listening, tell me your requirements...!!!\n")
os.system(" espeak-ng -a 170 -s 150 'Start Saying' ")
r.pause_threshold = 2
audio = r.listen(source)
try:
print('\t\t\t\t Just wait I am recognising...!!!\n')
os.system(" espeak-ng -a 170 -s 150 ' I got it, please wait' ")
query = r.recognize_google(audio, language='en-in')
#print(query)
except Exception as e:
print(e)
print('Say that again please...')
return query
design_1()
design_2()
docker()
os.system(" tput setaf 2 ")
r = input("How do you want to run the program ? ( local or remote ) : ")
print()
os.system(" tput setaf 4 ")
if r == 'remote':
ip = input("\t\t\tEnter the IP of your remote host : ")
print()
k_name = input("\t\t\tEnter the name of private key: ")
print()
cont_name = input(' \t\t\tEnter the name of container: ')
while True:
os.system(" clear ")
docker()
query = takeCommand().lower()
os.system(" tput setaf 8 ")
if r == 'local':
if "install python" in query:
cont_name = input(' \t\t\tEnter the name of container: ')
os.system(" docker exec -it {} yum install python3 ".format(cont_name))
os.system(" tput setaf 2 ")
print(" \t\t\t\tPython Installed Successfully \n")
os.system(" tput setaf 4 ")
elif "write python code" in query:
file_name = input(" \t\t\tGive the name of file: ")
os.system(" docker exec -it {} vi {} ".format(cont_name, file_name))
print()
elif "show python code" in query:
os.system(" docker exec -it {} cat {} ".format(cont_name, file_name))
print()
elif "run python code" in query:
os.system(" docker exec -it {} python3 {} ".format(cont_name, file_name))
os.system(" tput setaf 2 ")
print(" \t\t\t\tPython Code is Working Good\n")
os.system(" tput setaf 4 ")
elif "menu" in query:
break
os.system(" tput setaf 19 ")
input(" \t\t\t\tPress Enter to Continue......")
elif r == 'remote':
if "install python" in query:
os.system(" ssh -i {}.pem root@{} docker exec {} yum install python3 -y ".format(k_name, ip, cont_name))
os.system(" tput setaf 2 ")
print(" \t\t\t\tPython Installed Successfully \n")
os.system(" tput setaf 4 ")
elif "write python code" in query:
file_name = input(" Give the name of file: ")
os.system(' vi {} '.format(file_name))
os.system(" scp -i {}.pem {} root@{}:/root ".format(k_name, file_name, ip))
os.system(' rm -rf {} '.format(file_name))
os.system(" ssh -i {}.pem root@{} docker cp {} {}:/root ".format(k_name, ip, file_name, cont_name))
os.system(" ssh -i {}.pem root@{} rm -rf {} ".format(k_name, ip, file_name))
print()
elif "show python code" in query:
read_file = input(' \t\t\tEnter the name of file to read: ')
os.system(" ssh -i {}.pem root@{} docker exec {} cat /root/{} ".format(k_name, ip, cont_name, read_file))
print()
elif "run python code" in query:
os.system("ssh -i {}.pem root@{} docker exec {} python3 /root/{}".format(k_name, ip, cont_name, file_name))
os.system(" tput setaf 2 ")
print(" \t\t\t\tPython Code is Working Good\n")
os.system(" tput setaf 4 ")
elif "menu" in query:
break
os.system(" tput setaf 23 ")
input(" \t\t\t\tPress Enter to Continue......")
else:
break