Skip to content

Commit

Permalink
apt_dpkg: create_ppa_source...: return SourceEntries rather than raw …
Browse files Browse the repository at this point in the history
…string

This will make things easier when we switch to produce deb822 sources
down the road, and makes the code in the main function a bit more
readable.
  • Loading branch information
schopin-pro committed Jul 12, 2023
1 parent a6a0799 commit c3a6a10
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions apport/packaging_impl/apt_dpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,9 @@ def _analyze_ppa_origin_string(
index = 2
return None

def create_ppa_source_from_origin(self, origin, distro, release_codename):
def create_ppa_source_from_origin(
self, origin: str, distro: str, codename: str
) -> Optional[list[SourceEntry]]:
"""For an origin from a Launchpad PPA create sources.list content.
distro is the distribution for which content is being created e.g.
Expand All @@ -1607,19 +1609,22 @@ def create_ppa_source_from_origin(self, origin, distro, release_codename):
user, ppa_name = ppa_data
ppa_line = (
f"deb http://ppa.launchpad.net/{user}/{ppa_name}/{distro}"
f" {release_codename} main"
f" {codename} main"
)
debug_url = (
f"http://ppa.launchpad.net/{user}/{ppa_name}/{distro}"
f"/dists/{release_codename}/main/debug"
f"/dists/{codename}/main/debug"
)
try:
with contextlib.closing(urllib.request.urlopen(debug_url)) as response:
response.read()
add_debug = " main/debug"
except (urllib.error.URLError, urllib.error.HTTPError):
add_debug = ""

Check warning on line 1623 in apport/packaging_impl/apt_dpkg.py

View check run for this annotation

Codecov / codecov/patch

apport/packaging_impl/apt_dpkg.py#L1622-L1623

Added lines #L1622 - L1623 were not covered by tests
return f"{ppa_line + add_debug}\ndeb-src{ppa_line[3:]}\n"
return [
SourceEntry(ppa_line + add_debug),
SourceEntry(f"deb-src {ppa_line[4:]}"),
]

@staticmethod
def _find_source_file_from_origin(origin: str, src_list_d: str) -> Optional[str]:
Expand Down Expand Up @@ -1695,7 +1700,6 @@ def _build_apt_sandbox(
os.makedirs(trusted_d)

Check warning on line 1700 in apport/packaging_impl/apt_dpkg.py

View check run for this annotation

Codecov / codecov/patch

apport/packaging_impl/apt_dpkg.py#L1700

Added line #L1700 was not covered by tests

if origins:
source_list_content = ""
# map an origin to a Launchpad username and PPA name
origin_data = {}
for origin in origins:
Expand All @@ -1706,7 +1710,7 @@ def _build_apt_sandbox(
origin_path = self._find_source_file_from_origin(origin, src_list_d)
if origin_path:
with open(origin_path, encoding="utf-8") as src_ext:
source_list_content = src_ext.read()
source_list_content = [SourceEntry(line) for line in src_ext]

Check warning on line 1713 in apport/packaging_impl/apt_dpkg.py

View check run for this annotation

Codecov / codecov/patch

apport/packaging_impl/apt_dpkg.py#L1713

Added line #L1713 was not covered by tests
else:
source_list_content = self.create_ppa_source_from_origin(
origin, distro_name, release_codename
Expand All @@ -1719,14 +1723,12 @@ def _build_apt_sandbox(
"a",
encoding="utf-8",
) as dest:
dest.write(source_list_content)
for line in source_list_content.splitlines():
if line.startswith("#"):
continue
if "ppa.launchpad.net" not in line:
dest.write("\n".join([str(elt) for elt in source_list_content]))
for elt in source_list_content:
if not elt.uri or "ppa.launchpad.net" not in elt.uri:
continue
user = line.split()[1].split("/")[3]
ppa = line.split()[1].split("/")[4]
user = elt.uri.split("/")[3]
ppa = elt.uri.split("/")[4]
origin_data[origin] = (user, ppa)
else:
apport.logging.warning(
Expand Down

0 comments on commit c3a6a10

Please sign in to comment.