mirror of
https://github.com/JDM170/comp_auto_restart
synced 2024-10-25 13:43:54 +07:00
Initial commit
Signed-off-by: JDM170 <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
10
computer_names.json
Normal file
10
computer_names.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"1" : [
|
||||||
|
"IT01",
|
||||||
|
"IT02"
|
||||||
|
],
|
||||||
|
"2" : [
|
||||||
|
"PIS09",
|
||||||
|
"PIS10"
|
||||||
|
]
|
||||||
|
}
|
||||||
27
filesio.py
Normal file
27
filesio.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from json import load, dump
|
||||||
|
from os.path import exists
|
||||||
|
from os import remove
|
||||||
|
|
||||||
|
|
||||||
|
class FilesIO:
|
||||||
|
def __init__(self, file_name, default_values):
|
||||||
|
self.file_name = file_name
|
||||||
|
self.default_values = default_values
|
||||||
|
|
||||||
|
def create_default_file(self):
|
||||||
|
if exists(self.file_name):
|
||||||
|
remove(self.file_name)
|
||||||
|
with open(self.file_name, encoding="utf-8", mode="w") as f:
|
||||||
|
dump(self.default_values, f, indent=4, separators=(",", " : "))
|
||||||
|
|
||||||
|
def get_data(self):
|
||||||
|
try:
|
||||||
|
with open(file_name, encoding="utf-8") as f:
|
||||||
|
ret_data = load(f)
|
||||||
|
except FileNotFoundError:
|
||||||
|
self.create_default_file()
|
||||||
|
ret_data = self.default_values
|
||||||
|
return ret_data
|
||||||
22
match_name.py
Normal file
22
match_name.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from re import match
|
||||||
|
|
||||||
|
# Список выражений по которым проводится проверка
|
||||||
|
# По дефолту стоит регион R54, индекс 630300
|
||||||
|
expr_list = [
|
||||||
|
[r"^[a-zA-Z]+\d+$", "R54-630300"], # THE01
|
||||||
|
[r"^\d+[a-zA-Z]+\d+$", "R54-"], # 630300THE01
|
||||||
|
[r"^[rR]\d*[-]\d+[a-zA-Z]+\d+$", ""] # R54-630300THE01
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def check_arm_name(pc_name):
|
||||||
|
for r in expr_list:
|
||||||
|
if match(r[0], pc_name):
|
||||||
|
pc_name = "{}{}".format(r[1], pc_name)
|
||||||
|
break
|
||||||
|
if match(expr_list[2][0], pc_name):
|
||||||
|
return pc_name
|
||||||
|
return False
|
||||||
48
prog.py
Normal file
48
prog.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from sys import exit, argv
|
||||||
|
# from os import system
|
||||||
|
from subprocess import Popen
|
||||||
|
from filesio import FilesIO
|
||||||
|
from match_name import check_arm_name
|
||||||
|
|
||||||
|
file_name = ".\\computer_names.json"
|
||||||
|
default_values = {
|
||||||
|
"1": [ # Пятидневка
|
||||||
|
"IT01",
|
||||||
|
"IT02"
|
||||||
|
],
|
||||||
|
"2": [ # Цех
|
||||||
|
"PIS09",
|
||||||
|
"PIS10"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
loaded_file = None
|
||||||
|
|
||||||
|
|
||||||
|
def main(prog_key):
|
||||||
|
global loaded_file
|
||||||
|
list_pc_names = loaded_file.get(prog_key)
|
||||||
|
if list_pc_names is not None:
|
||||||
|
for pc_name in list_pc_names:
|
||||||
|
formatted_pc_name = check_arm_name(pc_name)
|
||||||
|
if formatted_pc_name is not False:
|
||||||
|
# print("pc_name:", formatted_pc_name)
|
||||||
|
# system("shutdown /m \\{} /r /t 60 /c \"Плановая перезагрузка компьютера через 1 минуту!\"".format(formatted_pc_name))
|
||||||
|
# Popen("shutdown /m \\{} /r /t 60 /c \"Плановая перезагрузка компьютера через 1 минуту!\"".format(formatted_pc_name)).wait()
|
||||||
|
print("shutdown /m \\{} /r /t 60 /c \"Плановая перезагрузка компьютера через 1 минуту!\"".format(formatted_pc_name))
|
||||||
|
else:
|
||||||
|
print("Попробуйте еще раз выбрать область запуска скрипта!")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(argv) < 2:
|
||||||
|
print("Укажите номер запускаемой области!\n1 - Кабинеты; 2 - Цех")
|
||||||
|
exit()
|
||||||
|
try:
|
||||||
|
filesio = FilesIO(file_name, default_values)
|
||||||
|
loaded_file = filesio.get_data()
|
||||||
|
main(argv[1])
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
exit()
|
||||||
Reference in New Issue
Block a user