From 056633efaa306040df87f9992f66b9f6b2a9935c Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Sun, 12 Oct 2025 19:56:05 +1300 Subject: [PATCH] launchd: remove conditional code for Python < 3.4 (#10909) * launchd: remove conditional code for Python < 3.4 * add changelog frag --- changelogs/fragments/10909-launchd-plistlib.yml | 2 ++ plugins/modules/launchd.py | 11 ----------- 2 files changed, 2 insertions(+), 11 deletions(-) create mode 100644 changelogs/fragments/10909-launchd-plistlib.yml diff --git a/changelogs/fragments/10909-launchd-plistlib.yml b/changelogs/fragments/10909-launchd-plistlib.yml new file mode 100644 index 0000000000..fc798c9ddb --- /dev/null +++ b/changelogs/fragments/10909-launchd-plistlib.yml @@ -0,0 +1,2 @@ +minor_changes: + - launchd - remove conditional code supporting Python versions prior to 3.4 (https://github.com/ansible-collections/community.general/pull/10909). diff --git a/plugins/modules/launchd.py b/plugins/modules/launchd.py index 89aada92d6..668388d7b6 100644 --- a/plugins/modules/launchd.py +++ b/plugins/modules/launchd.py @@ -160,9 +160,6 @@ class Plist: state, pid, dummy, dummy = LaunchCtlList(module, self.__service).run() - # Check if readPlist is available or not - self.old_plistlib = hasattr(plistlib, 'readPlist') - self.__file = self.__find_service_plist(self.__filename) if self.__file is None: msg = 'Unable to find the plist file %s for service %s' % ( @@ -201,10 +198,6 @@ class Plist: def __read_plist_file(self, module): service_plist = {} - if self.old_plistlib: - return plistlib.readPlist(self.__file) - - # readPlist is deprecated in Python 3 and onwards try: with open(self.__file, 'rb') as plist_fp: service_plist = plistlib.load(plist_fp) @@ -217,10 +210,6 @@ class Plist: if not service_plist: service_plist = {} - if self.old_plistlib: - plistlib.writePlist(service_plist, self.__file) - return - # writePlist is deprecated in Python 3 and onwards try: with open(self.__file, 'wb') as plist_fp: plistlib.dump(service_plist, plist_fp)