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 78aeeb7 commit 11df1ac
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

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

View check run for this annotation

Codecov / codecov/patch

apport/packaging_impl/apt_dpkg.py#L1581-L1590

Added lines #L1581 - L1590 were not covered by tests

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 = (

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

View check run for this annotation

Codecov / codecov/patch

apport/packaging_impl/apt_dpkg.py#L1606-L1610

Added lines #L1606 - L1610 were not covered by tests
f"deb http://ppa.launchpad.net/{user}/{ppa_name}/{distro}"
f" {release_codename} main"
f" {codename} main"
)
debug_url = (

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

View check run for this annotation

Codecov / codecov/patch

apport/packaging_impl/apt_dpkg.py#L1614

Added line #L1614 was not covered by tests
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 = ""
return f"{ppa_line + add_debug}\ndeb-src{ppa_line[3:]}\n"
return [

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

View check run for this annotation

Codecov / codecov/patch

apport/packaging_impl/apt_dpkg.py#L1618-L1624

Added lines #L1618 - L1624 were not covered by tests
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)

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

View check run for this annotation

Codecov / codecov/patch

apport/packaging_impl/apt_dpkg.py#L1710

Added line #L1710 was not covered by tests
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:

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

View check run for this annotation

Codecov / codecov/patch

apport/packaging_impl/apt_dpkg.py#L1726-L1728

Added lines #L1726 - L1728 were not covered by tests
continue
user = line.split()[1].split("/")[3]
ppa = line.split()[1].split("/")[4]
user = elt.uri.split("/")[3]
ppa = elt.uri.split("/")[4]

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

View check run for this annotation

Codecov / codecov/patch

apport/packaging_impl/apt_dpkg.py#L1730-L1731

Added lines #L1730 - L1731 were not covered by tests
origin_data[origin] = (user, ppa)
else:
apport.logging.warning(
Expand Down

0 comments on commit 11df1ac

Please sign in to comment.