Skip to content

Commit

Permalink
Fix common file for Python 2.7 (#643)
Browse files Browse the repository at this point in the history
Signed-off-by: Sagi Shnaidman <[email protected]>
  • Loading branch information
sshnaidm authored Sep 6, 2023
1 parent 18a939a commit e025e92
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions plugins/module_utils/podman/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,29 @@ def generate_systemd(module, module_params, name, version):
result['changed'] = True
if result['diff'].get('before') is None:
result['diff'] = {'before': {}, 'after': {}}
result['diff']['before'].update({f'systemd_{file_name}.service': ''})
result['diff']['after'].update({f'systemd_{file_name}.service': file_content})
result['diff']['before'].update(
{'systemd_{file_name}.service'.format(file_name=file_name): ''})
result['diff']['after'].update(
{'systemd_{file_name}.service'.format(file_name=file_name): file_content})

else:
diff_ = compare_systemd_file_content(os.path.join(full_path, file_name), file_content)
if diff_:
result['changed'] = True
if result['diff'].get('before') is None:
result['diff'] = {'before': {}, 'after': {}}
result['diff']['before'].update({f'systemd_{file_name}.service': "\n".join(diff_[0])})
result['diff']['after'].update({f'systemd_{file_name}.service': "\n".join(diff_[1])})
result['diff']['before'].update(
{'systemd_{file_name}.service'.format(file_name=file_name): "\n".join(diff_[0])})
result['diff']['after'].update(
{'systemd_{file_name}.service'.format(file_name=file_name): "\n".join(diff_[1])})
with open(os.path.join(full_path, file_name), 'w') as f:
f.write(file_content)
diff_before = "\n".join(
[f"{j} - {k}" for j, k in result['diff'].get('before', {}).items() if 'PIDFile' not in k]).strip()
["{j} - {k}".format(j=j, k=k)
for j, k in result['diff'].get('before', {}).items() if 'PIDFile' not in k]).strip()
diff_after = "\n".join(
[f"{j} - {k}" for j, k in result['diff'].get('after', {}).items() if 'PIDFile' not in k]).strip()
["{j} - {k}".format(j=j, k=k)
for j, k in result['diff'].get('after', {}).items() if 'PIDFile' not in k]).strip()
if diff_before or diff_after:
result['diff']['before'] = diff_before + "\n"
result['diff']['after'] = diff_after + "\n"
Expand Down

0 comments on commit e025e92

Please sign in to comment.