-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
114 lines (79 loc) · 3.3 KB
/
main.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
import win32com.client
# start_vmbox(vm_name, 1) - gui
# start_vmbox(vm_name, ...) - heandless
def start_vmbox(vm_name, state):
# Подключаемся к VirtualBox
vbox = win32com.client.Dispatch("VirtualBox.VirtualBox")
session = win32com.client.Dispatch("VirtualBox.Session")
machine = vbox.FindMachine(vm_name)
if state == 1:
# Подключаемся к машине
progress = machine.LaunchVMProcess(session, "gui", None)
elif state == 0:
progress = machine.LaunchVMProcess(session, "headless", None)
# Ожидаем завершения запуска
progress.WaitForCompletion(-1)
# Закрываем сессию после завершения
session.UnlockMachine()
# try to open a virtual box
try:
start_vmbox("slava3", 0)
except:
print("\"Yor virtual box is alredy work, continue write\"")
# create the data.txt file with answear
import os
import time
answear = None
logical_issue = 0
# really correct file direction
def CorrectFileDir(name_of_file):
current_dir = os.path.dirname(os.path.abspath(__file__))
new_file_name = name_of_file
return os.path.join(current_dir, new_file_name)
# if you close your program in the half a progress
try:
with open(CorrectFileDir("dataOutput.txt"), 'r+', encoding='utf-8') as file2:
answear = file2.read()
except:
pass
# main
while True:
print("Answear:", answear)
answear = None
hell_python = 0
answear = str(answear)
word = str(input())
with open(CorrectFileDir("data.txt"), 'w') as file:
file.write(word)
# while open(CorrectFileDir("dataOutput.txt"), 'r+', encoding='utf-8'):
# with open(CorrectFileDir("dataOutput.txt"), 'r+', encoding='utf-8') as file2:
# answear = file2.read()
#input("stop")
while hell_python != 1:
time.sleep(1)
try:
if open(CorrectFileDir("dataOutput.txt"), 'r+', encoding='utf-8') and logical_issue == 0:
print("1")
os.remove(CorrectFileDir("dataOutput.txt"))
logical_issue = 1
while logical_issue == 1:
time.sleep(1)
try:
if open(CorrectFileDir("dataOutput.txt"), 'r+', encoding='utf-8') and logical_issue == 1:
print("2")
with open(CorrectFileDir("dataOutput.txt"), 'r+', encoding='utf-8') as file2:
answear = file2.read()
os.remove(CorrectFileDir("dataOutput.txt"))
logical_issue = 0
hell_python = 1
except:
pass
except:
pass
# for i in range(2):
# while (open(CorrectFileDir("dataOutput.txt"), 'r+', encoding='utf-8')):
# time.sleep(1)
# os.remove(CorrectFileDir("dataOutput.txt"))
# with open(CorrectFileDir("dataOutput.txt"), 'r+', encoding='utf-8') as file2:
# answear = file2.read()
# os.remove(CorrectFileDir("dataOutput.txt"))