added app settings read exception

This commit is contained in:
DYefremov
2020-05-29 13:24:55 +03:00
parent 5352d87b82
commit bcf69231a8
2 changed files with 13 additions and 4 deletions

View File

@@ -39,8 +39,6 @@ class Defaults(Enum):
def get_settings():
os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True)
if not os.path.isfile(CONFIG_FILE) or os.stat(CONFIG_FILE).st_size == 0:
write_settings(get_default_settings())
@@ -77,6 +75,7 @@ def get_default_transcoding_presets():
def write_settings(config):
os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True)
with open(CONFIG_FILE, "w") as config_file:
json.dump(config, config_file, indent=" ")
@@ -125,6 +124,10 @@ class SettingsException(Exception):
pass
class SettingsReadException(SettingsException):
pass
class PlayStreamsMode(IntEnum):
""" Behavior mode when opening streams. """
BUILT_IN = 0
@@ -137,7 +140,10 @@ class Settings:
__VERSION = 1
def __init__(self, ext_settings=None):
try:
settings = ext_settings or get_settings()
except PermissionError as e:
raise SettingsReadException(e)
if self.__VERSION > settings.get("version", 0):
raise SettingsException("Outdated version of the settings format!")

View File

@@ -16,7 +16,7 @@ from app.eparser.ecommons import CAS, Flag, BouquetService
from app.eparser.enigma.bouquets import BqServiceType
from app.eparser.iptv import export_to_m3u
from app.eparser.neutrino.bouquets import BqType
from app.settings import SettingsType, Settings, SettingsException, PlayStreamsMode
from app.settings import SettingsType, Settings, SettingsException, PlayStreamsMode, SettingsReadException
from app.tools.media import Player, Recorder, HttpPlayer
from app.ui.epg_dialog import EpgDialog
from app.ui.transmitter import LinksTransmitter
@@ -2624,6 +2624,9 @@ class Application(Gtk.Application):
def start_app():
try:
Settings.get_instance()
except SettingsReadException as e:
msg = "{}\n {}".format(get_message("Error reading or writing program settings!"), e)
show_dialog(DialogType.INFO, transient=Gtk.Dialog(), text=msg)
except SettingsException as e:
msg = "{} \n{}".format(e, get_message("All setting were reset. Restart the program!"))
show_dialog(DialogType.INFO, transient=Gtk.Dialog(), text=msg)