charmlibs-snap 1.0.0__py3-none-any.whl
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.
- charmlibs/snap/__init__.py +98 -0
- charmlibs/snap/_snap.py +1335 -0
- charmlibs/snap/_version.py +15 -0
- charmlibs/snap/py.typed +0 -0
- charmlibs_snap-1.0.0.dist-info/METADATA +29 -0
- charmlibs_snap-1.0.0.dist-info/RECORD +7 -0
- charmlibs_snap-1.0.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Copyright 2025 Canonical Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Representations of the system's Snaps, and abstractions around managing them.
|
|
16
|
+
|
|
17
|
+
The ``snap`` package provides convenience methods for listing, installing, refreshing, and removing
|
|
18
|
+
Snap packages, in addition to setting and getting configuration options for them.
|
|
19
|
+
|
|
20
|
+
In the ``snap`` package, ``SnapCache`` creates a ``dict``-like mapping of ``Snap`` objects when
|
|
21
|
+
instantiated. Installed snaps are fully populated, and available snaps are lazily-loaded upon
|
|
22
|
+
request. This module relies on an installed and running ``snapd`` daemon to perform operations over
|
|
23
|
+
the ``snapd`` HTTP API.
|
|
24
|
+
|
|
25
|
+
``SnapCache`` objects can be used to install or modify nnap packages by name in a manner similar to
|
|
26
|
+
using the ``snap`` command from the commandline.
|
|
27
|
+
|
|
28
|
+
An example of adding Juju to the system with ``SnapCache`` and setting a config value::
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
cache = snap.SnapCache()
|
|
32
|
+
juju = cache["juju"]
|
|
33
|
+
|
|
34
|
+
if not juju.present:
|
|
35
|
+
juju.ensure(snap.SnapState.Latest, channel="beta")
|
|
36
|
+
juju.set({"some.key": "value", "some.key2": "value2"})
|
|
37
|
+
except snap.SnapError as e:
|
|
38
|
+
logger.error("An exception occurred when installing charmcraft. Reason: %s", e.message)
|
|
39
|
+
|
|
40
|
+
In addition, the ``snap`` module provides "bare" methods which can act on Snap packages as
|
|
41
|
+
simple function calls. :meth:`add`, :meth:`remove`, and :meth:`ensure` are provided, as
|
|
42
|
+
well as :meth:`add_local` for installing directly from a local ``.snap`` file. These return
|
|
43
|
+
``Snap`` objects.
|
|
44
|
+
|
|
45
|
+
As an example of installing several Snaps and checking details::
|
|
46
|
+
|
|
47
|
+
try:
|
|
48
|
+
nextcloud, charmcraft = snap.add(["nextcloud", "charmcraft"])
|
|
49
|
+
if nextcloud.get("mode") != "production":
|
|
50
|
+
nextcloud.set({"mode": "production"})
|
|
51
|
+
except snap.SnapError as e:
|
|
52
|
+
logger.error("An exception occurred when installing snaps. Reason: %s" % e.message)
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
from ._snap import (
|
|
56
|
+
Error,
|
|
57
|
+
JSONAble,
|
|
58
|
+
JSONType,
|
|
59
|
+
MetaCache,
|
|
60
|
+
Snap,
|
|
61
|
+
SnapAPIError,
|
|
62
|
+
SnapCache,
|
|
63
|
+
SnapClient,
|
|
64
|
+
SnapError,
|
|
65
|
+
SnapNotFoundError,
|
|
66
|
+
SnapService,
|
|
67
|
+
SnapServiceDict,
|
|
68
|
+
SnapState,
|
|
69
|
+
add,
|
|
70
|
+
ansi_filter,
|
|
71
|
+
ensure,
|
|
72
|
+
hold_refresh,
|
|
73
|
+
install_local,
|
|
74
|
+
remove,
|
|
75
|
+
)
|
|
76
|
+
from ._version import __version__ as __version__
|
|
77
|
+
|
|
78
|
+
__all__ = [
|
|
79
|
+
'Error',
|
|
80
|
+
'JSONAble',
|
|
81
|
+
'JSONType',
|
|
82
|
+
'MetaCache',
|
|
83
|
+
'Snap',
|
|
84
|
+
'SnapAPIError',
|
|
85
|
+
'SnapCache',
|
|
86
|
+
'SnapClient',
|
|
87
|
+
'SnapError',
|
|
88
|
+
'SnapNotFoundError',
|
|
89
|
+
'SnapService',
|
|
90
|
+
'SnapServiceDict',
|
|
91
|
+
'SnapState',
|
|
92
|
+
'add',
|
|
93
|
+
'ansi_filter',
|
|
94
|
+
'ensure',
|
|
95
|
+
'hold_refresh',
|
|
96
|
+
'install_local',
|
|
97
|
+
'remove',
|
|
98
|
+
]
|