serialize_profile(): simplify and cleanup

Drop `comment.replace('\\n', '\n')` because that doesn't make sense and
doesn't change anything - not even a comment that contains the literal
string '\n' (backslash + letter n).

Besides that, get rid of the 'string' variable and store everything in
'data'.
This commit is contained in:
Christian Boltz 2024-10-06 22:03:25 +02:00
parent 2e8a75195c
commit f5ed9cffe3
Failed to generate hash of commit

View file

@ -2007,7 +2007,8 @@ def write_piece(profile_data, depth, name, nhat):
def serialize_profile(profile_data, name, options): def serialize_profile(profile_data, name, options):
string = '' ''' combine the preamble and profiles in a file to a string (to be written to the profile file) '''
data = [] data = []
if not isinstance(options, dict): if not isinstance(options, dict):
@ -2016,12 +2017,11 @@ def serialize_profile(profile_data, name, options):
include_metadata = options.get('METADATA', False) include_metadata = options.get('METADATA', False)
if include_metadata: if include_metadata:
string = '# Last Modified: %s\n' % time.asctime() data.extend(['# Last Modified: %s' % time.asctime()])
# if profile_data[name].get('initial_comment', False): # if profile_data[name].get('initial_comment', False):
# comment = profile_data[name]['initial_comment'] # comment = profile_data[name]['initial_comment']
# comment.replace('\\n', '\n') # data.append(comment)
# string += comment + '\n'
if options.get('is_attachment'): if options.get('is_attachment'):
prof_filename = get_profile_filename_from_attachment(name, True) prof_filename = get_profile_filename_from_attachment(name, True)
@ -2035,23 +2035,22 @@ def serialize_profile(profile_data, name, options):
if active_profiles.profiles[prof]['parent']: if active_profiles.profiles[prof]['parent']:
continue # child profile or hat, already part of its parent profile continue # child profile or hat, already part of its parent profile
# aa-logprof asks to save each file separately. Therefore only update the given profile, and keep the original version of other profiles in the file
if prof != name: if prof != name:
if original_aa.get(prof, {}).get(prof, {}).get('initial_comment', False): if original_aa.get(prof, {}).get(prof, {}).get('initial_comment', False):
comment = original_aa[prof][prof]['initial_comment'] comment = original_aa[prof][prof]['initial_comment']
comment.replace('\\n', '\n') data.extend([comment, ''])
data.append(comment + '\n')
data.extend(write_piece(split_to_merged(original_aa), 0, prof, prof)) data.extend(write_piece(split_to_merged(original_aa), 0, prof, prof))
else: else:
if profile_data[name].get('initial_comment', False): if profile_data[name].get('initial_comment', False):
comment = profile_data[name]['initial_comment'] comment = profile_data[name]['initial_comment']
comment.replace('\\n', '\n') data.extend([comment, ''])
data.append(comment + '\n')
data.extend(write_piece(profile_data, 0, name, name)) data.extend(write_piece(profile_data, 0, name, name))
string += '\n'.join(data) return '\n'.join(data) + '\n'
return string + '\n'
def write_profile_ui_feedback(profile, is_attachment=False, out_dir=None): def write_profile_ui_feedback(profile, is_attachment=False, out_dir=None):