mirror of
https://github.com/DYefremov/DemonEditor.git
synced 2025-12-21 16:09:41 +01:00
added app settings read exception
This commit is contained in:
@@ -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!")
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user