mirror of
https://github.com/JDM170/comp_auto_restart
synced 2024-10-25 13:43:54 +07:00
Update
* Some refactor in main.py, filesio.py * Fix settings.json * Update README.md * Fix indents in .gitmodules Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
43
main.py
43
main.py
@@ -2,7 +2,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from sys import exit, argv
|
||||
from os import system, getcwd
|
||||
from subprocess import Popen
|
||||
from filesio import FilesIO
|
||||
from m_match_name.main import MatchIO
|
||||
@@ -24,41 +23,41 @@ default_values = {
|
||||
}
|
||||
}
|
||||
loaded_file = None
|
||||
is_debug = False
|
||||
|
||||
|
||||
def main(comp_key, is_debug):
|
||||
global loaded_file
|
||||
def main(comp_key):
|
||||
global loaded_file, is_debug
|
||||
list_pc_names = loaded_file.get("pc").get(comp_key)
|
||||
if list_pc_names is not None:
|
||||
restart_time = loaded_file.get("restart_time")
|
||||
restart_message = loaded_file.get("restart_message")
|
||||
for pc_name in list_pc_names:
|
||||
formatted_pc_name = matchio.check_pc_name(pc_name)
|
||||
if formatted_pc_name is not False:
|
||||
if is_debug is False:
|
||||
# system("shutdown /m \\\{} /r /f /t 60 /c \"Плановая перезагрузка компьютера через 1 минуту!\"".format(formatted_pc_name))
|
||||
Popen("shutdown /m \\\{} /r /f /t {} /c {}".format(formatted_pc_name, restart_time, restart_message)).wait()
|
||||
sleep(2)
|
||||
else:
|
||||
print("shutdown /m \\\{} /r /f /t {} /c {}".format(formatted_pc_name, restart_time, restart_message))
|
||||
else:
|
||||
if list_pc_names is None:
|
||||
print("Попробуйте еще раз выбрать область запуска скрипта!")
|
||||
exit()
|
||||
restart_time = loaded_file.get("restart_time")
|
||||
restart_message = loaded_file.get("restart_message")
|
||||
for pc_name in list_pc_names:
|
||||
formatted_pc_name = matchio.check_pc_name(pc_name)
|
||||
if formatted_pc_name is False:
|
||||
continue
|
||||
if is_debug is False:
|
||||
Popen("shutdown /m \\\{} /r /f /t {} /c {}".format(formatted_pc_name, restart_time, restart_message)).wait()
|
||||
sleep(2)
|
||||
else:
|
||||
print("shutdown /m \\\{} /r /f /t {} /c {}".format(formatted_pc_name, restart_time, restart_message))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(argv)
|
||||
if len(argv) < 2:
|
||||
print("Укажите номер запускаемой области!\n1 - Кабинеты; 2 - Цех")
|
||||
exit()
|
||||
if len(argv) == 3:
|
||||
is_debug = argv[2].strip() == "debug"
|
||||
try:
|
||||
filesio = FilesIO(default_values=default_values)
|
||||
loaded_file, err_msg = filesio.get_data()
|
||||
if loaded_file is False:
|
||||
raise Exception(err_msg)
|
||||
print(err_msg)
|
||||
exit()
|
||||
matchio = MatchIO()
|
||||
main(argv[1], argv[2].strip() == "debug")
|
||||
except Exception as exc:
|
||||
print(exc)
|
||||
exit()
|
||||
main(argv[1])
|
||||
except KeyboardInterrupt:
|
||||
exit()
|
||||
|
||||
Reference in New Issue
Block a user