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 13, 2023
1 parent e2c6f7e commit 57ea4c2
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions apport/packaging_impl/apt_dpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,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, release_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 @@ -1599,9 +1601,8 @@ def create_ppa_source_from_origin(self, origin, distro, release_codename):
release_codename is the codename of the release for which content is
being created e.g. trusty.
Return a string containing content suitable for writing to a
sources.list file, or None if the origin is not a Launchpad PPA.
"""
Returns None if the origin is not a Launchpad PPA, a list of source
entry objects otherwise."""
ppa_data = self._analyze_ppa_origin_string(origin, distro)
if not ppa_data:
return None
Expand All @@ -1620,7 +1621,10 @@ def create_ppa_source_from_origin(self, origin, distro, release_codename):
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 @@ -1696,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 @@ -1707,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 @@ -1720,14 +1723,14 @@ 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(entry) for entry in source_list_content])
)
for entry in source_list_content:
if not entry.uri or "ppa.launchpad.net" not in entry.uri:
continue
user = line.split()[1].split("/")[3]
ppa = line.split()[1].split("/")[4]
user = entry.uri.split("/")[3]
ppa = entry.uri.split("/")[4]
origin_data[origin] = (user, ppa)
else:
apport.logging.warning(
Expand Down

0 comments on commit 57ea4c2

Please sign in to comment.