1
0
mirror of https://github.com/altlinux/gpupdate.git synced 2025-03-21 18:50:38 +03:00

Added handling of missing files

This commit is contained in:
Valery Sinelnikov 2023-09-19 11:17:29 +04:00
parent 78815c5ecd
commit 5c0fc9bed0
3 changed files with 26 additions and 25 deletions

View File

@ -69,12 +69,6 @@ class kde_applier_user(applier_frontend):
__module_enabled = False
__hkcu_branch = 'Software\\BaseALT\\Policies\\KDE\\'
__hkcu_lock_branch = 'Software\\BaseALT\\Policies\\KDELocks\\'
widget_utilities = {
'colorscheme': 'plasma-apply-colorscheme',
'cursortheme': 'plasma-apply-cursortheme',
'desktoptheme': 'plasma-apply-desktoptheme',
'wallpaperimage': 'plasma-apply-wallpaperimage'
}
def __init__(self, storage, sid=None, username=None, file_cache = None):
self.storage = storage
@ -133,6 +127,7 @@ def create_dict(kde_settings, all_kde_settings, locks_settings, locks_dict, file
log('W16', logdata)
def apply(all_kde_settings, locks_dict, username = None):
logdata = dict()
if username is None:
for file_name, sections in all_kde_settings.items():
file_path = f'/etc/xdg/{file_name}'
@ -179,22 +174,24 @@ def apply(all_kde_settings, locks_dict, username = None):
subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except OSError as exc:
logdata['exc'] = exc
log('W18', exc)
log('W18', logdata)
except Exception as exc:
logdata = dict()
logdata['command'] = command
log('E68', logdata)
new_content = []
file_path = os.path.expanduser(f'{get_homedir(username)}/.config/{file_name}')
with open(file_path, 'r') as file:
for line in file:
line = line.replace('/$i/', '[$i]').replace(')(', '][')
new_content.append(line)
with open(file_path, 'w') as file:
file.writelines(new_content)
logdata = dict()
logdata['file'] = file_name
log('D202', logdata)
file_path = f'{get_homedir(username)}/.config/{file_name}'
try:
with open(file_path, 'r') as file:
for line in file:
line = line.replace('/$i/', '[$i]').replace(')(', '][')
new_content.append(line)
with open(file_path, 'w') as file:
file.writelines(new_content)
logdata['file'] = file_name
log('D202', logdata)
except Exception as exc:
logdata['exc'] = exc
log('W19', logdata)
def clear_locks_settings(username, file_name, key):
'''
@ -217,6 +214,7 @@ def apply_for_widget(value, data, file_cache):
'''
Method for changing graphics settings in plasma context
'''
logdata = dict()
try:
if value in widget_utilities:
if value == 'wallpaperimage':
@ -233,7 +231,6 @@ def apply_for_widget(value, data, file_cache):
command = [f"{widget_utilities[value]}", f"{data}"]
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
stdout = proc.communicate()
logdata = dict()
logdata['Conclusion'] = stdout
if proc.returncode == 0:
log('D203', logdata)

View File

@ -886,14 +886,17 @@ msgstr "Не удалось создать допустимый список к
msgid "Failed to copy file"
msgstr "Не удалось скопировать файл"
msgid "Failed to create settings list"
msgstr "Не удалось создать список настроек"
msgid "Failed to create KDE settings list"
msgstr "Не удалось создать список настроек KDE"
msgid "Could not find application tools"
msgstr "Не удалось найти инструменты применения"
msgid "Failed to open settings"
msgstr "Не удалось открыть настройки"
msgid "Failed to open KDE settings"
msgstr "Не удалось открыть настройки KDE"
msgid "Failed to change KDE configuration file"
msgstr "Не удалось изменить файл конфигурации KDE"
# Fatal
msgid "Unable to refresh GPO list"

View File

@ -335,9 +335,10 @@ def warning_code(code):
warning_ids[13] = 'Failed to caching the file'
warning_ids[14] = 'Could not create a valid list of keys'
warning_ids[15] = 'Failed to copy file'
warning_ids[16] = 'Failed to create settings list'
warning_ids[16] = 'Failed to create KDE settings list'
warning_ids[17] = 'Could not find application tools'
warning_ids[18] = 'Failed to open settings'
warning_ids[18] = 'Failed to open KDE settings'
warning_ids[19] = 'Failed to change KDE configuration file'
return warning_ids.get(code, 'Unknown warning code')