1- __version__ = '1.7.3 '
1+ __version__ = '1.8.1 '
22__author__ = 'desultory'
33
44
5- from zenlib .util import check_dict
5+ from zenlib .util import contains , unset
66
77
88class SubvolNotFound (Exception ):
@@ -25,16 +25,17 @@ def _get_mount_subvol(self, mountpoint: str) -> list:
2525 raise SubvolNotFound ("No subvolume detected." )
2626
2727
28- @check_dict ('validate' , value = True , message = "Validate is not set, skipping root subvolume validation." )
29- @check_dict ('root_subvol' , not_empty = True , message = "root_subvol is not set, skipping validation." )
28+ @contains ('validate' , "validate is not enabled, skipping root subvolume validation." )
3029def _validate_root_subvol (self ) -> None :
3130 """ Validates the root subvolume. """
3231 try :
3332 detected_subvol = _get_mount_subvol (self , '/' )
3433 except SubvolNotFound :
35- raise ValueError ("Current root mount is not using a subvolume, but root_subvol is set: %s" % self ['root_subvol' ])
34+ if self ['root_subvol' ]:
35+ raise ValueError ("Current root mount is not using a subvolume, but root_subvol is set: %s" % self ['root_subvol' ])
3636 except SubvolIsRoot :
37- raise ValueError ("Current root mount is not using a subvolume, but root_subvol is set: %s" % self ['root_subvol' ])
37+ if self ['root_subvol' ] != '/' :
38+ raise ValueError ("Current root mount is not using a subvolume, but root_subvol is set: %s" % self ['root_subvol' ])
3839
3940 if self ['root_subvol' ] != detected_subvol :
4041 raise ValueError ("[%s] Root subvolume does not match detected subvolume: %s" % (self ['root_subvol' ], detected_subvol ))
@@ -62,10 +63,10 @@ def btrfs_scan(self) -> str:
6263 return 'einfo "$(btrfs device scan)"'
6364
6465
65- @check_dict ('subvol_selector' , value = False , log_level = 20 , message = "subvol_selector enabled, skipping." )
66- @check_dict ('autodetect_root_subvol' , value = True , message = "autodetect_root_subvol not enabled, skipping." )
67- @check_dict ('root_subvol' , unset = True , message = "root_subvol is set, skipping." )
68- @check_dict ('hostonly' , value = True , message = "hostonly is not set , skipping." )
66+ @unset ('subvol_selector' , message = "subvol_selector is enabled, skipping." , log_level = 20 )
67+ @contains ('autodetect_root_subvol' , "autodetect_root_subvol is not enabled, skipping." , log_level = 30 )
68+ @unset ('root_subvol' , message = "root_subvol is set, skipping." )
69+ @contains ('hostonly' , "hostonly is not enabled , skipping." , log_level = 30 )
6970def autodetect_root_subvol (self ):
7071 """ Detects the root subvolume. """
7172 try :
@@ -78,8 +79,8 @@ def autodetect_root_subvol(self):
7879 self .logger .debug ("Root mount is not using a subvolume." )
7980
8081
81- @check_dict ('subvol_selector' , value = True , message = "subvol_selector not enabled, skipping" )
82- @check_dict ('root_subvol' , unset = True , message = "root_subvol is set, skipping." )
82+ @contains ('subvol_selector' , message = "subvol_selector is not enabled, skipping. " )
83+ @unset ('root_subvol' , message = "root_subvol is set, skipping." )
8384def select_subvol (self ) -> str :
8485 """ Returns a bash script to list subvolumes on the root volume. """
8586 # TODO: Figure out a way to make the case prompt more standard
@@ -106,7 +107,7 @@ def select_subvol(self) -> str:
106107 f"umount -l { self ['_base_mount_path' ]} " ]
107108
108109
109- @check_dict ('root_subvol' , not_empty = True , message = "root_subvol is not set, skipping." )
110+ @contains ('root_subvol' , message = "root_subvol is not set, skipping." )
110111def set_root_subvol (self ) -> str :
111112 """ Adds the root_subvol to the root_mount options. """
112113 _validate_root_subvol (self )
0 commit comments