[PR #8987/29a2df8e backport][stable-8] udm_user, homectl: use legacycrypt on Python 3.13+ (#8992)

udm_user, homectl: use legacycrypt on Python 3.13+ (#8987)

Use legacycrypt on Python 3.13+.

(cherry picked from commit 29a2df8e6b)

Co-authored-by: Felix Fontein <felix@fontein.de>
pull/9006/head
patchback[bot] 2024-10-07 22:19:18 +02:00 committed by GitHub
parent d9d9148510
commit 5362908efb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 43 additions and 13 deletions

View File

@ -0,0 +1,3 @@
bugfixes:
- "homectl - the module now tries to use ``legacycrypt`` on Python 3.13+ (https://github.com/ansible-collections/community.general/issues/4691, https://github.com/ansible-collections/community.general/pull/8987)."
- "udm_user - the module now tries to use ``legacycrypt`` on Python 3.13+ (https://github.com/ansible-collections/community.general/issues/4690, https://github.com/ansible-collections/community.general/pull/8987)."

View File

@ -18,11 +18,11 @@ version_added: 4.4.0
description:
- Manages a user's home directory managed by systemd-homed.
notes:
- This module does B(not) work with Python 3.13 or newer. It uses the deprecated L(crypt Python module,
https://docs.python.org/3.12/library/crypt.html) from the Python standard library, which was removed
from Python 3.13.
- This module requires the deprecated L(crypt Python module,
https://docs.python.org/3.12/library/crypt.html) library which was removed from Python 3.13.
For Python 3.13 or newer, you need to install L(legacycrypt, https://pypi.org/project/legacycrypt/).
requirements:
- Python 3.12 or earlier
- legacycrypt (on Python 3.13 or newer)
extends_documentation_fragment:
- community.general.attributes
attributes:
@ -284,6 +284,17 @@ else:
HAS_CRYPT = True
CRYPT_IMPORT_ERROR = None
try:
import legacycrypt
if not HAS_CRYPT:
crypt = legacycrypt
except ImportError:
HAS_LEGACYCRYPT = False
LEGACYCRYPT_IMPORT_ERROR = traceback.format_exc()
else:
HAS_LEGACYCRYPT = True
LEGACYCRYPT_IMPORT_ERROR = None
class Homectl(object):
'''#TODO DOC STRINGS'''
@ -606,9 +617,9 @@ def main():
]
)
if not HAS_CRYPT:
if not HAS_CRYPT and not HAS_LEGACYCRYPT:
module.fail_json(
msg=missing_required_lib('crypt (part of Python 3.13 standard library)'),
msg=missing_required_lib('crypt (part of standard library up to Python 3.12) or legacycrypt (PyPI)'),
exception=CRYPT_IMPORT_ERROR,
)

View File

@ -21,11 +21,11 @@ description:
server (UCS).
It uses the python API of the UCS to create a new object or edit it."
notes:
- This module does B(not) work with Python 3.13 or newer. It uses the deprecated L(crypt Python module,
https://docs.python.org/3.12/library/crypt.html) from the Python standard library, which was removed
from Python 3.13.
- This module requires the deprecated L(crypt Python module,
https://docs.python.org/3.12/library/crypt.html) library which was removed from Python 3.13.
For Python 3.13 or newer, you need to install L(legacycrypt, https://pypi.org/project/legacycrypt/).
requirements:
- Python 3.12 or earlier
- legacycrypt (on Python 3.13 or newer)
extends_documentation_fragment:
- community.general.attributes
attributes:
@ -350,6 +350,17 @@ else:
HAS_CRYPT = True
CRYPT_IMPORT_ERROR = None
try:
import legacycrypt
if not HAS_CRYPT:
crypt = legacycrypt
except ImportError:
HAS_LEGACYCRYPT = False
LEGACYCRYPT_IMPORT_ERROR = traceback.format_exc()
else:
HAS_LEGACYCRYPT = True
LEGACYCRYPT_IMPORT_ERROR = None
def main():
expiry = date.strftime(date.today() + timedelta(days=365), "%Y-%m-%d")
@ -467,10 +478,10 @@ def main():
])
)
if not HAS_CRYPT:
if not HAS_CRYPT and not HAS_LEGACYCRYPT:
module.fail_json(
msg=missing_required_lib('crypt (part of Python 3.13 standard library)'),
exception=CRYPT_IMPORT_ERROR,
msg=missing_required_lib('crypt (part of standard library up to Python 3.12) or legacycrypt (PyPI)'),
exception=LEGACYCRYPT_IMPORT_ERROR,
)
username = module.params['username']

View File

@ -15,6 +15,11 @@
ignore_errors: true
- block:
- name: Install legacycrypt on Python 3.13+
pip:
name: legacycrypt
when: ansible_python_version is version("3.13", ">=")
- name: Check and start systemd-homed service
service:
name: systemd-homed.service