Skip to content

Commit

Permalink
refactor: rename snap_name
Browse files Browse the repository at this point in the history
Rename legacy variables to match snapd's definition:
snap_name->snap_instance_name (possibly aliased)
snap_store_name->snap_name (unaliased)

Signed-off-by: Callahan Kovacs <[email protected]>
  • Loading branch information
mr-cal committed Oct 4, 2024
1 parent 495c41f commit 78af8ea
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions snapcraft_legacy/internal/build_providers/_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ def __init__(
latest_revision: Optional[str],
inject_from_host: bool = True
) -> None:
self.snap_name = snap_name
# the local snap name may have a suffix if it was installed with `--name`
self.snap_store_name = snap_name.split("_")[0]
# name of the snap instance, which may have an alias
self.snap_instance_name = snap_name
# name of the snap (no alias)
self.snap_name = snap_name.split("_")[0]
self._remote_snap_dir = remote_snap_dir
self._inject_from_host = inject_from_host

Expand All @@ -74,7 +75,7 @@ def __init__(

def _get_snap_repo(self):
if self.__repo is None:
self.__repo = repo.snaps.SnapPackage(self.snap_name)
self.__repo = repo.snaps.SnapPackage(self.snap_instance_name)
return self.__repo

def get_op(self) -> _SnapOp:
Expand Down Expand Up @@ -125,7 +126,7 @@ def get_op(self) -> _SnapOp:
# This is a programmatic error
raise RuntimeError(
"Unhandled scenario for {!r} (host installed: {}, latest_revision {})".format(
self.snap_name, is_installed, self._latest_revision
self.snap_instance_name, is_installed, self._latest_revision
)
)

Expand All @@ -136,9 +137,9 @@ def push_host_snap(self, *, file_pusher: Callable[..., None]) -> None:
# TODO not being able to lock down on a snap revision can lead to races.
host_snap_repo = self._get_snap_repo()
with tempfile.TemporaryDirectory() as temp_dir:
snap_file_path = os.path.join(temp_dir, "{}.snap".format(self.snap_name))
snap_file_path = os.path.join(temp_dir, "{}.snap".format(self.snap_instance_name))
assertion_file_path = os.path.join(
temp_dir, "{}.assert".format(self.snap_name)
temp_dir, "{}.assert".format(self.snap_instance_name)
)
host_snap_repo.local_download(
snap_path=snap_file_path, assertion_path=assertion_file_path
Expand Down Expand Up @@ -171,7 +172,7 @@ def _set_data(self) -> None:
switch_cmd = [
"snap",
"switch",
self.snap_name,
self.snap_instance_name,
"--channel",
snap_channel,
]
Expand All @@ -198,17 +199,17 @@ def _set_data(self) -> None:

elif op == _SnapOp.INSTALL or op == _SnapOp.REFRESH:
install_cmd = ["snap", op.name.lower()]
snap_channel = _get_snap_channel(self.snap_store_name)
snap_channel = _get_snap_channel(self.snap_name)

store_snap_info = storeapi.SnapAPI().get_info(self.snap_store_name)
store_snap_info = storeapi.SnapAPI().get_info(self.snap_name)
snap_channel_map = store_snap_info.get_channel_mapping(
risk=snap_channel.risk, track=snap_channel.track
)
snap_revision = snap_channel_map.revision
if snap_channel_map.confinement == "classic":
install_cmd.append("--classic")
install_cmd.extend(["--channel", snap_channel_map.channel_details.name])
install_cmd.append(self.snap_store_name)
install_cmd.append(self.snap_name)

self.__install_cmd = install_cmd
self.__switch_cmd = switch_cmd
Expand All @@ -224,7 +225,7 @@ def get_revision(self) -> str:
# Shouldn't happen.
raise RuntimeError(
"Unhandled scenario for {!r} (revision {})".format(
self.snap_name, self.__revision
self.snap_instance_name, self.__revision
)
)

Expand All @@ -238,7 +239,7 @@ def get_snap_install_cmd(self) -> List[str]:
if self.__install_cmd is None:
raise RuntimeError(
"Unhandled scenario for {!r} (install_cmd {})".format(
self.snap_name, self.__install_cmd
self.snap_instance_name, self.__install_cmd
)
)

Expand All @@ -259,7 +260,7 @@ def get_assertion_ack_cmd(self) -> List[str]:
if self.__assertion_ack_cmd is None:
raise RuntimeError(
"Unhandled scenario for {!r} (assertion_ack_cmd {})".format(
self.snap_name, self.__assertion_ack_cmd
self.snap_instance_name, self.__assertion_ack_cmd
)
)

Expand Down Expand Up @@ -379,7 +380,7 @@ def apply(self) -> None:
return

# Allow using snapd from the snapd snap to leverage newer snapd features.
if any(s.snap_name == "snapd" for s in self._snaps):
if any(s.snap_instance_name == "snapd" for s in self._snaps):
self._enable_snapd_snap()

# Disable refreshes so they do not interfere with installation ops.
Expand All @@ -396,6 +397,6 @@ def apply(self) -> None:
self._runner(snap.get_snap_install_cmd())
if snap.get_channel_switch_cmd() is not None:
self._runner(snap.get_channel_switch_cmd())
self._record_revision(snap.snap_store_name, snap.get_revision())
self._record_revision(snap.snap_name, snap.get_revision())

_save_registry(self._registry_data, self._registry_filepath)

0 comments on commit 78af8ea

Please sign in to comment.