83
83
84
84
# Increment this PATCH version before using `charmcraft publish-lib` or reset
85
85
# to 0 if you are raising the major API version
86
- LIBPATCH = 3
86
+ LIBPATCH = 4
87
87
88
88
89
89
# Regex to locate 7-bit C1 ANSI sequences
@@ -214,7 +214,7 @@ class Snap(object):
214
214
- state: a `SnapState` representation of its install status
215
215
- channel: "stable", "candidate", "beta", and "edge" are common
216
216
- revision: a string representing the snap's revision
217
- - confinement: "classic" or "strict "
217
+ - confinement: "classic", "strict", or "devmode "
218
218
"""
219
219
220
220
def __init__ (
@@ -475,6 +475,8 @@ def _install(
475
475
args = []
476
476
if self .confinement == "classic" :
477
477
args .append ("--classic" )
478
+ if self .confinement == "devmode" :
479
+ args .append ("--devmode" )
478
480
if channel :
479
481
args .append ('--channel="{}"' .format (channel ))
480
482
if revision :
@@ -489,6 +491,7 @@ def _refresh(
489
491
channel : Optional [str ] = "" ,
490
492
cohort : Optional [str ] = "" ,
491
493
revision : Optional [str ] = None ,
494
+ devmode : bool = False ,
492
495
leave_cohort : Optional [bool ] = False ,
493
496
) -> None :
494
497
"""Refresh a snap.
@@ -497,6 +500,7 @@ def _refresh(
497
500
channel: the channel to install from
498
501
cohort: optionally, specify a cohort.
499
502
revision: optionally, specify the revision of the snap to refresh
503
+ devmode: optionally, specify devmode confinement
500
504
leave_cohort: leave the current cohort.
501
505
"""
502
506
args = []
@@ -506,6 +510,9 @@ def _refresh(
506
510
if revision :
507
511
args .append ('--revision="{}"' .format (revision ))
508
512
513
+ if devmode :
514
+ args .append ("--devmode" )
515
+
509
516
if not cohort :
510
517
cohort = self ._cohort
511
518
@@ -530,6 +537,7 @@ def ensure(
530
537
self ,
531
538
state : SnapState ,
532
539
classic : Optional [bool ] = False ,
540
+ devmode : bool = False ,
533
541
channel : Optional [str ] = "" ,
534
542
cohort : Optional [str ] = "" ,
535
543
revision : Optional [str ] = None ,
@@ -539,6 +547,7 @@ def ensure(
539
547
Args:
540
548
state: a `SnapState` to reconcile to.
541
549
classic: an (Optional) boolean indicating whether classic confinement should be used
550
+ devmode: an (Optional) boolean indicating whether devmode confinement should be used
542
551
channel: the channel to install from
543
552
cohort: optional. Specify the key of a snap cohort.
544
553
revision: optional. the revision of the snap to install/refresh
@@ -549,7 +558,15 @@ def ensure(
549
558
Raises:
550
559
SnapError if an error is encountered
551
560
"""
552
- self ._confinement = "classic" if classic or self ._confinement == "classic" else ""
561
+ if classic and devmode :
562
+ raise ValueError ("Cannot set both classic and devmode confinement" )
563
+
564
+ if classic or self ._confinement == "classic" :
565
+ self ._confinement = "classic"
566
+ elif devmode or self ._confinement == "devmode" :
567
+ self ._confinement = "devmode"
568
+ else :
569
+ self ._confinement = ""
553
570
554
571
if state not in (SnapState .Present , SnapState .Latest ):
555
572
# We are attempting to remove this snap.
@@ -566,7 +583,7 @@ def ensure(
566
583
self ._install (channel , cohort , revision )
567
584
else :
568
585
# The snap is installed, but we are changing it (e.g., switching channels).
569
- self ._refresh (channel , cohort , revision )
586
+ self ._refresh (channel = channel , cohort = cohort , revision = revision , devmode = devmode )
570
587
571
588
self ._update_snap_apps ()
572
589
self ._state = state
@@ -892,6 +909,7 @@ def add(
892
909
state : Union [str , SnapState ] = SnapState .Latest ,
893
910
channel : Optional [str ] = "" ,
894
911
classic : Optional [bool ] = False ,
912
+ devmode : bool = False ,
895
913
cohort : Optional [str ] = "" ,
896
914
revision : Optional [str ] = None ,
897
915
) -> Union [Snap , List [Snap ]]:
@@ -904,6 +922,8 @@ def add(
904
922
channel: an (Optional) channel as a string. Defaults to 'latest'
905
923
classic: an (Optional) boolean specifying whether it should be added with classic
906
924
confinement. Default `False`
925
+ devmode: an (Optional) boolean specifying whether it should be added with devmode
926
+ confinement. Default `False`
907
927
cohort: an (Optional) string specifying the snap cohort to use
908
928
revision: an (Optional) string specifying the snap revision to use
909
929
@@ -920,7 +940,7 @@ def add(
920
940
if isinstance (state , str ):
921
941
state = SnapState (state )
922
942
923
- return _wrap_snap_operations (snap_names , state , channel , classic , cohort , revision )
943
+ return _wrap_snap_operations (snap_names , state , channel , classic , devmode , cohort , revision )
924
944
925
945
926
946
@_cache_init
@@ -936,8 +956,13 @@ def remove(snap_names: Union[str, List[str]]) -> Union[Snap, List[Snap]]:
936
956
snap_names = [snap_names ] if isinstance (snap_names , str ) else snap_names
937
957
if not snap_names :
938
958
raise TypeError ("Expected at least one snap to add, received zero!" )
939
-
940
- return _wrap_snap_operations (snap_names , SnapState .Absent , "" , False )
959
+ return _wrap_snap_operations (
960
+ snap_names = snap_names ,
961
+ state = SnapState .Absent ,
962
+ channel = "" ,
963
+ classic = False ,
964
+ devmode = False ,
965
+ )
941
966
942
967
943
968
@_cache_init
@@ -946,6 +971,7 @@ def ensure(
946
971
state : str ,
947
972
channel : Optional [str ] = "" ,
948
973
classic : Optional [bool ] = False ,
974
+ devmode : bool = False ,
949
975
cohort : Optional [str ] = "" ,
950
976
revision : Optional [int ] = None ,
951
977
) -> Union [Snap , List [Snap ]]:
@@ -957,6 +983,8 @@ def ensure(
957
983
channel: an (Optional) channel as a string. Defaults to 'latest'
958
984
classic: an (Optional) boolean specifying whether it should be added with classic
959
985
confinement. Default `False`
986
+ devmode: an (Optional) boolean specifying whether it should be added with devmode
987
+ confinement. Default `False`
960
988
cohort: an (Optional) string specifying the snap cohort to use
961
989
revision: an (Optional) integer specifying the snap revision to use
962
990
@@ -970,7 +998,15 @@ def ensure(
970
998
channel = "latest"
971
999
972
1000
if state in ("present" , "latest" ) or revision :
973
- return add (snap_names , SnapState (state ), channel , classic , cohort , revision )
1001
+ return add (
1002
+ snap_names = snap_names ,
1003
+ state = SnapState (state ),
1004
+ channel = channel ,
1005
+ classic = classic ,
1006
+ devmode = devmode ,
1007
+ cohort = cohort ,
1008
+ revision = revision ,
1009
+ )
974
1010
else :
975
1011
return remove (snap_names )
976
1012
@@ -980,6 +1016,7 @@ def _wrap_snap_operations(
980
1016
state : SnapState ,
981
1017
channel : str ,
982
1018
classic : bool ,
1019
+ devmode : bool ,
983
1020
cohort : Optional [str ] = "" ,
984
1021
revision : Optional [str ] = None ,
985
1022
) -> Union [Snap , List [Snap ]]:
@@ -995,7 +1032,12 @@ def _wrap_snap_operations(
995
1032
snap .ensure (state = SnapState .Absent )
996
1033
else :
997
1034
snap .ensure (
998
- state = state , classic = classic , channel = channel , cohort = cohort , revision = revision
1035
+ state = state ,
1036
+ classic = classic ,
1037
+ devmode = devmode ,
1038
+ channel = channel ,
1039
+ cohort = cohort ,
1040
+ revision = revision ,
999
1041
)
1000
1042
snaps ["success" ].append (snap )
1001
1043
except SnapError as e :
@@ -1014,13 +1056,17 @@ def _wrap_snap_operations(
1014
1056
1015
1057
1016
1058
def install_local (
1017
- filename : str , classic : Optional [bool ] = False , dangerous : Optional [bool ] = False
1059
+ filename : str ,
1060
+ classic : Optional [bool ] = False ,
1061
+ devmode : Optional [bool ] = False ,
1062
+ dangerous : Optional [bool ] = False ,
1018
1063
) -> Snap :
1019
1064
"""Perform a snap operation.
1020
1065
1021
1066
Args:
1022
1067
filename: the path to a local .snap file to install
1023
1068
classic: whether to use classic confinement
1069
+ devmode: whether to use devmode confinement
1024
1070
dangerous: whether --dangerous should be passed to install snaps without a signature
1025
1071
1026
1072
Raises:
@@ -1033,6 +1079,8 @@ def install_local(
1033
1079
]
1034
1080
if classic :
1035
1081
args .append ("--classic" )
1082
+ if devmode :
1083
+ args .append ("--devmode" )
1036
1084
if dangerous :
1037
1085
args .append ("--dangerous" )
1038
1086
try :
0 commit comments