apt_repository: remove Python 2 support (#85212)

(cherry picked from commit f635a22d81)
pull/85255/head
Martin Krizek 6 months ago committed by Matt Davis
parent abb1de2780
commit df60504b93

@ -0,0 +1,2 @@
minor_changes:
- "apt_repository - remove Python 2 support"

@ -88,8 +88,8 @@ options:
description: description:
- Whether to automatically try to install the Python apt library or not, if it is not already installed. - Whether to automatically try to install the Python apt library or not, if it is not already installed.
Without this library, the module does not work. Without this library, the module does not work.
- Runs C(apt-get install python-apt) for Python 2, and C(apt-get install python3-apt) for Python 3. - Runs C(apt-get install python3-apt).
- Only works with the system Python 2 or Python 3. If you are using a Python on the remote that is not - Only works with the system Python. If you are using a Python on the remote that is not
the system Python, set O(install_python_apt=false) and ensure that the Python apt library the system Python, set O(install_python_apt=false) and ensure that the Python apt library
for your Python version is installed some other way. for your Python version is installed some other way.
type: bool type: bool
@ -98,8 +98,7 @@ author:
- Alexander Saltanov (@sashka) - Alexander Saltanov (@sashka)
version_added: "0.7" version_added: "0.7"
requirements: requirements:
- python-apt (python 2) - python3-apt
- python3-apt (python 3)
- apt-key or gpg - apt-key or gpg
""" """
@ -232,14 +231,15 @@ class SourcesList(object):
self.files_mapping = {} # internal DS for tracking symlinks self.files_mapping = {} # internal DS for tracking symlinks
# Repositories that we're adding -- used to implement mode param # Repositories that we're adding -- used to implement mode param
self.new_repos = set() self.new_repos = set()
self.default_file = self._apt_cfg_file('Dir::Etc::sourcelist') self.default_file = apt_pkg.config.find_file('Dir::Etc::sourcelist')
# read sources.list if it exists # read sources.list if it exists
if os.path.isfile(self.default_file): if os.path.isfile(self.default_file):
self.load(self.default_file) self.load(self.default_file)
# read sources.list.d # read sources.list.d
for file in glob.iglob('%s/*.list' % self._apt_cfg_dir('Dir::Etc::sourceparts')): self.sources_dir = apt_pkg.config.find_dir('Dir::Etc::sourceparts')
for file in glob.iglob(f'{self.sources_dir}/*.list'):
if os.path.islink(file): if os.path.islink(file):
self.files_mapping[file] = os.readlink(file) self.files_mapping[file] = os.readlink(file)
self.load(file) self.load(file)
@ -255,7 +255,7 @@ class SourcesList(object):
if '/' in filename: if '/' in filename:
return filename return filename
else: else:
return os.path.abspath(os.path.join(self._apt_cfg_dir('Dir::Etc::sourceparts'), filename)) return os.path.abspath(os.path.join(self.sources_dir, filename))
def _suggest_filename(self, line): def _suggest_filename(self, line):
def _cleanup_filename(s): def _cleanup_filename(s):
@ -313,28 +313,6 @@ class SourcesList(object):
return valid, enabled, source, comment return valid, enabled, source, comment
@staticmethod
def _apt_cfg_file(filespec):
"""
Wrapper for `apt_pkg` module for running with Python 2.5
"""
try:
result = apt_pkg.config.find_file(filespec)
except AttributeError:
result = apt_pkg.Config.FindFile(filespec)
return result
@staticmethod
def _apt_cfg_dir(dirspec):
"""
Wrapper for `apt_pkg` module for running with Python 2.5
"""
try:
result = apt_pkg.config.find_dir(dirspec)
except AttributeError:
result = apt_pkg.Config.FindDir(dirspec)
return result
def load(self, file): def load(self, file):
group = [] group = []
f = open(file, 'r') f = open(file, 'r')

Loading…
Cancel
Save