Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deb822 default sources list d #4437

Merged
merged 10 commits into from
Sep 27, 2023
43 changes: 26 additions & 17 deletions cloudinit/config/cc_apt_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,9 @@ def is_deb822_sources_format(apt_src_content: str) -> bool:


DEFAULT_APT_CFG = {
"sourcelist": "/etc/apt/sources.list",
"sourceparts": "/etc/apt/sources.list.d/",
"Dir::Etc": "etc/apt",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactoring code that hasn't landed yet adds churn / noise in the commit log. To avoid this, please squash the changes in this commit into the commit that introduced these lines of code prior to merging.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes agreed on this point, which had prompted my overall squash merge for this PR given some of the overlap and churn I had introduced when handling review comments and iterations. I left these separate commits in a less than desirable state after handling initial reviews which made separate commits for this effort a bit more work than I wanted to spend on this particular PR.

"Dir::Etc::sourcelist": "sources.list",
"Dir::Etc::sourceparts": "sources.list.d",
}

APT_CFG_RE = (
Expand All @@ -596,31 +597,39 @@ def get_apt_cfg() -> Dict[str, str]:
import apt_pkg # type: ignore
TheRealFalcon marked this conversation as resolved.
Show resolved Hide resolved

apt_pkg.init_config()
sourcelist = apt_pkg.config.find_file(
"Dir::Etc::sourcelist", DEFAULT_APT_CFG["sourcelist"]
etc = apt_pkg.config.get("Dir::Etc", DEFAULT_APT_CFG["Dir::Etc"])
sourcelist = apt_pkg.config.get(
"Dir::Etc::sourcelist", DEFAULT_APT_CFG["Dir::Etc::sourcelist"]
)
sourceparts = apt_pkg.config.find_dir(
"Dir::Etc::sourceparts", DEFAULT_APT_CFG["sourceparts"]
sourceparts = apt_pkg.config.get(
"Dir::Etc::sourceparts", DEFAULT_APT_CFG["Dir::Etc::sourceparts"]
)
except ImportError:

try:
apt_dump, _ = subp.subp(["apt-config", "dump"])
except subp.ProcessExecutionError:
# No apt-config, return defaults
return DEFAULT_APT_CFG
etc = DEFAULT_APT_CFG["Dir::Etc"]
sourcelist = DEFAULT_APT_CFG["Dir::Etc::sourcelist"]
sourceparts = DEFAULT_APT_CFG["Dir::Etc::sourceparts"]
return {
"sourcelist": f"/{etc}/{sourcelist}",
"sourceparts": f"/{etc}/{sourceparts}/",
}
matched_cfg = re.findall(APT_CFG_RE, apt_dump)
apt_cmd_config = dict(matched_cfg)
etc = apt_cmd_config.get("Dir::Etc", "etc/apt")
if apt_cmd_config.get("Dir::Etc::sourcelist"):
sourcelist = f"/{etc}/{apt_cmd_config['Dir::Etc::sourcelist']}"
else:
sourcelist = DEFAULT_APT_CFG["sourcelist"]
if apt_cmd_config.get("Dir::Etc::sourceparts"):
sourceparts = f"/{etc}/{apt_cmd_config['Dir::Etc::sourceparts']}/"
else:
sourceparts = DEFAULT_APT_CFG["sourceparts"]
return {"sourcelist": sourcelist, "sourceparts": sourceparts}
etc = apt_cmd_config.get("Dir::Etc", DEFAULT_APT_CFG["Dir::Etc"])
sourcelist = apt_cmd_config.get(
"Dir::Etc::sourcelist", DEFAULT_APT_CFG["Dir::Etc::sourcelist"]
)
sourceparts = apt_cmd_config.get(
"Dir::Etc::sourceparts", DEFAULT_APT_CFG["Dir::Etc::sourceparts"]
)
return {
"sourcelist": f"/{etc}/{sourcelist}",
"sourceparts": f"/{etc}/{sourceparts}/",
}


def generate_sources_list(cfg, release, mirrors, cloud):
Expand Down