This commit is contained in:
2022-03-23 18:06:16 +07:00
committed by GitHub
parent 008148229f
commit 65afbacb58
6 changed files with 188 additions and 191 deletions

View File

@@ -1,2 +1,2 @@
@echo off @echo off
pyinstaller build.spec --upx-dir=upx\ pyinstaller build.spec --upx-dir=upx\

View File

@@ -1,40 +1,40 @@
# -*- mode: python ; coding: utf-8 -*- # -*- mode: python ; coding: utf-8 -*-
block_cipher = None block_cipher = None
a = Analysis(['main.py'], a = Analysis(['main.py'],
pathex=[], pathex=[],
binaries=[], binaries=[],
datas=[], datas=[],
hiddenimports=[], hiddenimports=[],
hookspath=[], hookspath=[],
hooksconfig={}, hooksconfig={},
runtime_hooks=[], runtime_hooks=[],
excludes=[], excludes=[],
win_no_prefer_redirects=False, win_no_prefer_redirects=False,
win_private_assemblies=False, win_private_assemblies=False,
cipher=block_cipher, cipher=block_cipher,
noarchive=False) noarchive=False)
pyz = PYZ(a.pure, a.zipped_data, pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher) cipher=block_cipher)
exe = EXE(pyz, exe = EXE(pyz,
a.scripts, a.scripts,
a.binaries, a.binaries,
a.zipfiles, a.zipfiles,
a.datas, a.datas,
[], [],
name='Scheduled computer restart', name='Scheduled computer restart',
debug=False, debug=False,
bootloader_ignore_signals=False, bootloader_ignore_signals=False,
strip=False, strip=False,
upx=True, upx=True,
upx_exclude=[], upx_exclude=[],
runtime_tmpdir=None, runtime_tmpdir=None,
console=True, console=True,
disable_windowed_traceback=False, disable_windowed_traceback=False,
target_arch=None, target_arch=None,
codesign_identity=None, codesign_identity=None,
entitlements_file=None) entitlements_file=None)

View File

@@ -1,29 +1,29 @@
#!/usr/bin/python3 #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from json import load, dump from json import load, dump
from os.path import exists from os.path import exists
from os import remove from os import remove
class FilesIO: class FilesIO:
def __init__(self, file_name=".\\settings.json", default_values=None): def __init__(self, file_name=".\\settings.json", default_values=None):
self.file_name = file_name self.file_name = file_name
self.default_values = default_values self.default_values = default_values
def create_default_file(self): def create_default_file(self):
if self.default_values is not None: if self.default_values is not None:
if exists(self.file_name): if exists(self.file_name):
remove(self.file_name) remove(self.file_name)
with open(self.file_name, encoding="utf-8", mode="w") as f: with open(self.file_name, encoding="utf-8", mode="w") as f:
dump(self.default_values, f, indent=4, separators=(",", " : ")) dump(self.default_values, f, indent=4, separators=(",", " : "))
def get_data(self): def get_data(self):
try: try:
with open(self.file_name, encoding="utf-8", mode="r") as f: with open(self.file_name, encoding="utf-8", mode="r") as f:
ret_data = load(f) ret_data = load(f)
except FileNotFoundError: return ret_data
self.create_default_file() except FileNotFoundError:
# ret_data = self.default_values self.create_default_file()
return False # ret_data = self.default_values
return ret_data return False

127
main.py
View File

@@ -1,65 +1,62 @@
#!/usr/bin/python3 #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from sys import exit, argv from sys import exit, argv
from os import system from os import system
from subprocess import Popen from subprocess import Popen
from time import sleep from filesio import FilesIO
from filesio import FilesIO from match_name import MatchIO
from match_name import MatchIO
default_values = {
default_values = { "expr_list": [
"expr_list": [ [r"^[a-zA-Z]+\d+$", "R54-630300"], # THE01
[r"^[a-zA-Z]+\d+$", "R54-630300"], # THE01 [r"^\d+[a-zA-Z]+\d+$", "R54-"], # 630300THE01
[r"^\d+[a-zA-Z]+\d+$", "R54-"], # 630300THE01 [r"^[rR]\d*[-]\d+[a-zA-Z]+\d+$", ""] # R54-630300THE01
[r"^[rR]\d*[-]\d+[a-zA-Z]+\d+$", ""] # R54-630300THE01 ],
], "pc": {
"pc": { "2": [ # Пятидневка
"2": [ # Пятидневка "IT01",
"IT01", "IT02"
"IT02" ],
], "7": [ # Цех
"7": [ # Цех "PIS09",
"PIS09", "PIS10"
"PIS10" ]
] }
} }
} loaded_file = None
loaded_file = None
def main(comp_key, is_debug):
def main(comp_key, is_prod): global loaded_file
global loaded_file list_pc_names = loaded_file.get("pc").get(comp_key)
list_pc_names = loaded_file.get("pc").get(comp_key) if list_pc_names is not None:
if list_pc_names is not None: for pc_name in list_pc_names:
for pc_name in list_pc_names: formatted_pc_name = matchio.check_arm_name(pc_name)
formatted_pc_name = matchio.check_arm_name(pc_name) if formatted_pc_name is not False:
if formatted_pc_name is not False: if is_debug is False:
# print("pc_name:", formatted_pc_name) # system("shutdown /m \\\{} /r /f /t 60 /c \"Плановая перезагрузка компьютера через 1 минуту!\"".format(formatted_pc_name))
if is_prod is True: Popen("shutdown /m \\\{} /r /f /t 60 /c \"Плановая перезагрузка компьютера через 1 минуту!\"".format(formatted_pc_name)).wait()
# system("shutdown /m \\\{} /r /f /t 60 /c \"Плановая перезагрузка компьютера через 1 минуту!\"".format(formatted_pc_name)) else:
Popen("shutdown /m \\\{} /r /f /t 60 /c \"Плановая перезагрузка компьютера через 1 минуту!\"".format(formatted_pc_name)).wait() print("shutdown /m \\\{} /r /f /t 60 /c \"Плановая перезагрузка компьютера через 1 минуту!\"".format(formatted_pc_name))
else: else:
print("shutdown /m \\\{} /r /f /t 60 /c \"Плановая перезагрузка компьютера через 1 минуту!\"".format(formatted_pc_name)) print("Попробуйте еще раз выбрать область запуска скрипта!")
else:
print("Попробуйте еще раз выбрать область запуска скрипта!")
if __name__ == "__main__":
if len(argv) < 3:
if __name__ == "__main__": print("Укажите номер запускаемой области!\n2 - Кабинеты; 7 - Цех")
if len(argv) < 3: exit()
print("Укажите номер запускаемой области!\n2 - Кабинеты; 7 - Цех") try:
exit() filesio = FilesIO(default_values=default_values)
try: loaded_file = filesio.get_data()
filesio = FilesIO(default_values=default_values) if loaded_file is False:
loaded_file = filesio.get_data() raise OSError
if loaded_file is False: matchio = MatchIO(loaded_file.get("expr_list"))
raise OSError main(argv[1], argv[2].strip() == "debug")
matchio = MatchIO(loaded_file.get("expr_list")) except OSError:
main(argv[1], argv[2].strip() == "prod") print("Файл с настройками не найден. Создан файл со стандартными настройками.")
except OSError: exit()
print("Файл с настройками не найден. Создан файл со стандартными настройками.") except KeyboardInterrupt:
sleep(20) exit()
exit()
except KeyboardInterrupt:
exit()

View File

@@ -1,26 +1,26 @@
#!/usr/bin/python3 #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from re import match from re import match
# Список выражений по которым проводится проверка # Список выражений по которым проводится проверка
# По дефолту стоит регион R54, индекс 630300 # По дефолту стоит регион R54, индекс 630300
default_expr_list = [ default_expr_list = [
[r"^[a-zA-Z]+\d+$", "R54-630300"], # THE01 [r"^[a-zA-Z]+\d+$", "R54-630300"], # THE01
[r"^\d+[a-zA-Z]+\d+$", "R54-"], # 630300THE01 [r"^\d+[a-zA-Z]+\d+$", "R54-"], # 630300THE01
[r"^[rR]\d*[-]\d+[a-zA-Z]+\d+$", ""] # R54-630300THE01 [r"^[rR]\d*[-]\d+[a-zA-Z]+\d+$", ""] # R54-630300THE01
] ]
class MatchIO: class MatchIO:
def __init__(self, expr_list=None): def __init__(self, expr_list=None):
self.expr_list = expr_list is None and default_expr_list or expr_list self.expr_list = expr_list is None and default_expr_list or expr_list
def check_arm_name(self, pc_name): def check_arm_name(self, pc_name):
for r in self.expr_list: for r in self.expr_list:
if match(r[0], pc_name): if match(r[0], pc_name):
pc_name = "{}{}".format(r[1], pc_name) pc_name = "{}{}".format(r[1], pc_name)
break break
if match(self.expr_list[2][0], pc_name): if match(self.expr_list[2][0], pc_name):
return pc_name return pc_name
return False return False

View File

@@ -1,30 +1,30 @@
{ {
"expr_list" : [ "expr_list" : [
[ [
"^[a-zA-Z]+\\d+$", "^[a-zA-Z]+\\d+$",
"R54-630300" "R54-630300"
], ],
[ [
"^\\d+[a-zA-Z]+\\d+$", "^\\d+[a-zA-Z]+\\d+$",
"R54-" "R54-"
], ],
[ [
"^[rR]\\d*[-]\\d+[a-zA-Z]+\\d+$", "^[rR]\\d*[-]\\d+[a-zA-Z]+\\d+$",
"" ""
] ]
], ],
"pc" : { "pc" : {
"2" : [ "2" : [
"IT01", "IT01",
"IT02", "IT02",
"630870MMP01", "630870MMP01",
"R54-630870MMP02" "R54-630870MMP02"
], ],
"7" : [ "7" : [
"PIS09", "PIS09",
"PIS10", "PIS10",
"630870THE01", "630870THE01",
"R54-630870THE02" "R54-630870THE02"
] ]
} }
} }