comparison configmix/config.py @ 405:af367e1d0950

Allow to rebind a jailed configuration to another "similar" base
author Franz Glasner <f.glasner@feldmann-mg.com>
date Fri, 19 Nov 2021 13:26:53 +0100
parents 6a5aea02f3d0
children 5286df5aeefe
comparison
equal deleted inserted replaced
404:6a5aea02f3d0 405:af367e1d0950
714 is_jail = True 714 is_jail = True
715 """Flag to show that this is a jail for another configuration""" 715 """Flag to show that this is a jail for another configuration"""
716 716
717 def __init__(self, config, *path): 717 def __init__(self, config, *path):
718 super(_JailedConfiguration, self).__init__() 718 super(_JailedConfiguration, self).__init__()
719 self._base = config
720 self._path = path 719 self._path = path
721 if path: 720 if path:
722 self._pathstr = \ 721 self._pathstr = \
723 Configuration._HIER_SEPARATOR.join( 722 Configuration._HIER_SEPARATOR.join(
724 [Configuration.quote(p) for p in path]) \ 723 [Configuration.quote(p) for p in path]) \
725 + Configuration._HIER_SEPARATOR 724 + Configuration._HIER_SEPARATOR
726 else: 725 else:
727 self._pathstr = '' 726 self._pathstr = ''
727 self.rebind(config)
728
729 def rebind(self, new_base):
730 """Bind the jail to a new unjailed configuration `new_base`.
731
732 The new configuration base also must have an existing path to
733 the root.
734
735 :param Configuration new_base: the new base
736
737 """
738 if new_base.is_jail:
739 raise TypeError("can only bind to an unjailed configuration")
740 self._base = new_base
728 # 741 #
729 # Early error out if the chroot does not exist but allow 742 # Early error out if the chroot does not exist but allow
730 # degenerated case if `self._path` is empty. 743 # degenerated case if `self._path` is empty.
731 # 744 #
732 if self._path: 745 if self._path:
733 self._base.getvarl(*self._path) 746 new_base.getvarl(*self._path)
734 747
735 def getvarl(self, *path, **kwds): 748 def getvarl(self, *path, **kwds):
736 return self._base.getvarl(*(self._path + path), **kwds) 749 return self._base.getvarl(*(self._path + path), **kwds)
737 750
738 def getfirstvarl(self, *paths, **kwds): 751 def getfirstvarl(self, *paths, **kwds):