lid-cli 0.4__tar.gz → 0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lid-cli
3
- Version: 0.4
3
+ Version: 0.5
4
4
  Summary: gio-based volume mounting and unmounting tool.
5
5
  Author: Christian Heinze
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ requires = [ "uv-build>=0.10,<0.11" ]
4
4
 
5
5
  [project]
6
6
  name = "lid-cli"
7
- version = "0.4"
7
+ version = "0.5"
8
8
  description = "gio-based volume mounting and unmounting tool."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -79,11 +79,17 @@ async def mount(kw: str, /, env: types.Environment, runner: AsyncRunner) -> type
79
79
  log.exception("Failed to mount volume ID `%s`.", mount_id)
80
80
  raise types.GioError(f"failed to mount volume with ID`{mount_id}`") from err
81
81
 
82
+ # Update information to make sure mount information is present.
83
+ volume_info = await _query_matching_volume_info(
84
+ kw, include_details=True, env=env, runner=runner
85
+ )
86
+ volume = _extract_volume(kw, volume_info=volume_info)
87
+
82
88
  try:
83
89
  mp = await _find_mountpoint(
84
- volume.data["activation_root"], env=env, runner=runner
90
+ _extract_gio_location(volume.data), env=env, runner=runner
85
91
  )
86
- except types.GioError as err:
92
+ except (ValueError, types.GioError) as err:
87
93
  log.exception("Found no mount point for `%s`.", name)
88
94
  raise types.GioError(f"found no mount point for `{name}`") from err
89
95
 
@@ -112,9 +118,9 @@ async def umount(
112
118
 
113
119
  try:
114
120
  mountpoint = await _find_mountpoint(
115
- volume.data["activation_root"], env=env, runner=runner
121
+ _extract_gio_location(volume.data), env=env, runner=runner
116
122
  )
117
- except types.GioError as err:
123
+ except (ValueError, types.GioError) as err:
118
124
  log.exception("Found no mount point for `%s`.", name)
119
125
  raise types.GioError(f"found no mount point for `{name}`") from err
120
126
  else:
@@ -196,14 +202,31 @@ def _extract_volume(kw: str, /, volume_info: Sequence[dict[str, Any]]) -> _Volum
196
202
  raise types.GioError("unsupported gio output structure")
197
203
 
198
204
 
205
+ def _extract_gio_location(info: dict[str, Any], /) -> str:
206
+ try:
207
+ mount_info = next(v for k, v in info.items() if k.startswith("Mount"))
208
+ except StopIteration:
209
+ raise ValueError("no mount information found") from None
210
+ if not isinstance(mount_info, dict):
211
+ raise ValueError("invalid mount information found")
212
+
213
+ if (loc := mount_info.get("default_location")) is not None:
214
+ return loc
215
+ mount_name, loc_pattern = mount_info.get("__name__", ""), r"->\s*(?P<loc>.+?)$"
216
+ if (m := re.search(loc_pattern, mount_name)) is not None:
217
+ return m.group("loc")
218
+
219
+ raise ValueError("no mount location found")
220
+
221
+
199
222
  async def _find_mountpoint(
200
- id_: str, /, env: types.Environment, runner: AsyncRunner
223
+ loc: str, /, env: types.Environment, runner: AsyncRunner
201
224
  ) -> str:
202
225
  try:
203
226
  # Requires volume to be mounted.
204
227
  # Need to the US locale as the output key are adapted to that setting.
205
228
  gio_out = await runner(
206
- env.gio_bin, "info", "-a", "local", id_, env_mods={"LANG": "en_US-UTF-8"}
229
+ env.gio_bin, "info", "-a", "local", loc, env_mods={"LANG": "en_US-UTF-8"}
207
230
  )
208
231
  except types.SubprocessError as err:
209
232
  raise types.GioError(
@@ -214,7 +237,10 @@ async def _find_mountpoint(
214
237
  except types.GioError as err:
215
238
  raise types.GioError("failed to parse gio output for path discovery") from err
216
239
 
217
- return gio_out["local path"]
240
+ try:
241
+ return gio_out["local path"]
242
+ except KeyError:
243
+ raise types.GioError(f"`{loc}` has no local filesystem path") from None
218
244
 
219
245
 
220
246
  def _parse_output(text: str, /, header_name: str = "__name__") -> dict[str, Any]:
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes