Skip to content

Commit

Permalink
feat: from_repo_line calls add-apt-repository instead of re-implmenti…
Browse files Browse the repository at this point in the history
…ng logic
  • Loading branch information
james-garner-canonical committed Dec 3, 2024
1 parent c102035 commit a0106bd
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions lib/charms/operator_libs_linux/v0/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ def _make_filename(self) -> str:
"""Construct a filename from uri and release.
For internal use when a filename isn't set.
Should match the filename written to by add-apt-repository.
"""
return "{}-{}.list".format(
DebianRepository.prefix_from_uri(self.uri),
Expand Down Expand Up @@ -1068,23 +1069,16 @@ def from_repo_line(repo_line: str, write_file: Optional[bool] = True) -> "Debian
Args:
repo_line: a string representing a repository entry
write_file: boolean to enable writing the new repo to disk
write_file: boolean to enable writing the new repo to disk. True by default.
Results in calling `add-apt-repository --no-update --sourceslist $repo_line`
"""
repo = RepositoryMapping._parse( # pyright: ignore[reportPrivateUsage]
repo_line, "UserInput"
repo_line, filename="UserInput" # temp filename
)
repo.filename = repo._make_filename()
repo_str = repo._to_line() + "\n"
if write_file:
logger.info(
"DebianRepository.from_repo_line('%s', write_file=True)\nWriting to '%s':\n%s",
repo_line,
repo.filename,
repo_str,
)
with open(repo.filename, "wb") as f:
f.write(repo_str.encode("utf-8"))

RepositoryMapping._add_apt_repository( # pyright: ignore[reportPrivateUsage])
repo, update_cache=False
)
return repo

def disable(self) -> None:
Expand Down Expand Up @@ -1499,8 +1493,8 @@ def _remove(self, repo: DebianRepository, update_cache: bool = False) -> "Reposi
self._repository_map.pop(repo_id, None)
return self

@staticmethod
def _add_apt_repository(
self,
repo: DebianRepository,
update_cache: bool = False,
remove: bool = False,
Expand Down

0 comments on commit a0106bd

Please sign in to comment.