1
0
mirror of https://github.com/altlinux/gpupdate.git synced 2025-01-25 02:04:18 +03:00

Added method to clear old blocked policies. Added logs for exceptions.

This commit is contained in:
Данила Скачедубов 2023-09-05 17:07:21 +04:00 committed by danila
parent e402d399e9
commit 1f32d4efae

View File

@ -165,12 +165,21 @@ def apply(all_kde_settings, locks_dict, username = None):
'--type', 'string',
value
]
subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
try:
subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except Exception as exc:
clear_locks_settings(username, file_name, key)
try:
subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
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]')
line = line.replace('/$i/', '[$i]').replace(')(', '][')
new_content.append(line)
with open(file_path, 'w') as file:
file.writelines(new_content)
@ -178,6 +187,23 @@ def apply(all_kde_settings, locks_dict, username = None):
logdata['file'] = file_name
log('D202', logdata)
def clear_locks_settings(username, file_name, key):
'''
Method to remove old locked settings
'''
file_path = f'{get_homedir(username)}/.config/{file_name}'
with open(file_path, 'r') as file:
lines = file.readlines()
with open(file_path, 'w') as file:
for line in lines:
if f'{key}[$i]=' not in line:
file.write(line)
for line in lines:
if f'{key}[$i]=' in line:
logdata = dict()
logdata['line'] = line.strip()
log('I10', logdata)
def apply_for_widget(value, data):
'''
Method for changing graphics settings in plasma context