Коммит 72479c7e создал по автору Леляев Петр Алексеевич's avatar Леляев Петр Алексеевич
Просмотр файлов

Bug fix: при сохранении расписания не запршивается подтверждение закрытия окна

владелец 36322007
......@@ -2,6 +2,7 @@
import logging
import os
import subprocess
import sys
from PyQt5.QtGui import QIcon
......@@ -31,7 +32,7 @@ if __name__ == '__main__':
for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)
logging.basicConfig(
filename=f"{config_path}/log.txt",
filename=f"/home/user/.config/school-ringer/log.txt",
format=u'%(asctime)s %(filename)s [LINE:%(lineno)d] [%(funcName)s()] #%(levelname)-15s %(message)s',
level=logging.INFO,
)
......
......@@ -2,8 +2,8 @@ from school_ringer_modules.system import get_current_user_on_x
debug = False
config_path = f'/home/{get_current_user_on_x()}/.config/school-ringer' if not debug else './debug_config'
sound_path = f'/home/{get_current_user_on_x()}/.config/school-ringer/sound' if not debug else './debug_config'
config_path = f'/etc/ring_daemon/config' if not debug else './debug_config'
sound_path = f'/etc/ring-daemon/sound' if not debug else './debug_config'
icon_file = 'school-ringer.svg'
version = '1.05'
......@@ -5,6 +5,7 @@ from json import loads, dumps
from school_ringer_modules.config import config_path
from school_ringer_modules.sound import default_sound
from school_ringer_modules.system import run_command
@dataclass
......@@ -99,8 +100,12 @@ class AllGroupsOfCalls:
:return: None
"""
try:
with open(self.filename, 'w', encoding='utf-8') as file:
tempfile = run_command('mktemp').strip()
with open(tempfile, 'w', encoding='utf-8') as file:
file.write(dumps(value, indent=4, ensure_ascii=False))
logging.info(f'Группы звонков записаны в файл {tempfile}')
run_command(f'pkexec mv {tempfile} {self.filename}')
logging.info(f'Группы звонков перенесены в файл {self.filename}')
except KeyError:
logging.info('[error] Ключ не найден')
return None
......
......@@ -2,6 +2,7 @@ import logging
import re
import shutil
import subprocess
from json import dumps
import openpyxl
from PyQt5 import QtGui, QtCore
......@@ -14,6 +15,7 @@ from PyQt5.QtWidgets import QWidget, QGridLayout, QTableWidget, QTabWidget, QInp
from school_ringer_modules.config import config_path
from school_ringer_modules.groups_dataclasses import all_groups_of_calls
from school_ringer_modules.schedules_dataclasses import Schedule, schedules
from school_ringer_modules.system import run_command
from school_ringer_modules.time_functions import time_correct, time_string_to_minute
time_pattern = r'^(([0-1][0-9]|2[0-3]|[0-9]):([0-5][0-9]|[0-9])|-)$'
......@@ -725,23 +727,30 @@ class ScheduleEditor(ParentClassForAllSchedules):
Сигнал закрытия окна для обновления активных расписаний
@param a0:
"""
ret = QMessageBox.question(self, 'Внимание!', f"Сохранить изменения?",
QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)
if ret == QMessageBox.Cancel:
a0.ignore()
elif ret == QMessageBox.No:
schedules.open_read_from_file()
logging.info(f'Отмена сохранения изменений. Расписание считано из файла: {schedules.schedules}')
self.settings_window.schedule_editor = None
self.close()
elif ret == QMessageBox.Yes:
logging.info(
f'Сохранение расписаний в файл, обновление списка активных расписаний, '
'закрытие окна редактирования расписаний...')
schedules.save()
self.settings_window.schedule_editor = None
tempfile = run_command('mktemp').strip()
with open(tempfile, 'w', encoding='utf-8') as file:
file.write(dumps(schedules.schedules, indent=4, ensure_ascii=False))
diffs = run_command(f'diff {tempfile} {config_path}/schedule.json').strip()
if diffs == '':
self.close()
else:
ret = QMessageBox.question(self, 'Внимание!', f"Сохранить изменения?",
QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)
if ret == QMessageBox.Cancel:
a0.ignore()
elif ret == QMessageBox.No:
schedules.open_read_from_file()
logging.info(f'Отмена сохранения изменений. Расписание считано из файла: {schedules.schedules}')
self.settings_window.schedule_editor = None
self.close()
elif ret == QMessageBox.Yes:
logging.info(
f'Сохранение расписаний в файл, обновление списка активных расписаний, '
'закрытие окна редактирования расписаний...')
schedules.save()
self.settings_window.schedule_editor = None
self.close()
def switch_from_add_tab(self) -> None:
"""
......
......@@ -6,6 +6,7 @@ from dataclasses import dataclass
from json import loads, dumps
from school_ringer_modules.config import config_path
from school_ringer_modules.system import run_command
from school_ringer_modules.time_functions import time_before
......@@ -157,9 +158,12 @@ class AllSchedules:
Записывает расписания в файл json
"""
try:
with open(self.filename, 'w', encoding='utf-8') as file:
tempfile = run_command('mktemp').strip()
with open(tempfile, 'w', encoding='utf-8') as file:
file.write(dumps(value, indent=4, ensure_ascii=False))
logging.info(f'Расписания записаны в файл {self.filename}')
logging.info(f'Расписания записаны в файл {tempfile}')
run_command(f'pkexec mv {tempfile} {self.filename}')
logging.info(f'Расписания перенесены в {self.filename}')
except KeyError:
logging.info('[error] Ошибка записи в файл')
return None
......
......@@ -39,22 +39,14 @@ def ring_the_call(filename: str, play_music=False) -> None:
try:
subprocess.run('pkill play', shell=True)
logging.info(f'pkilled play')
# play_param = ' '.join(get_music_for_breaks())
# logging.info(f'play param: {play_param}')
sound_to_play = f'{sound_path}/{filename}'
if play_music and run_command(f'py-ini-config get {config_path}/school-ringer.conf Main '
f'is_breaks_music_on').strip() == 'true':
logging.info('play music: true')
sound_to_play += f' {get_music_for_breaks()}'
print('***', sound_to_play)
logging.info(f'Will be played: {sound_to_play}')
subprocess.run(f'play {sound_to_play}', shell=True)
# # logging.info(f'Play music: {play_music}')
# if play_music:
# logging.info('Playing music...')
# play_param = ' '.join(get_music_for_breaks())
# logging.info(f'play param: {play_param}')
# subprocess.run(f'play {play_param}', shell=True)
except Exception as e:
print('Программа запущена без прав суперпользователя', e)
logging.info(f'Вызван звонок')
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать