Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/config.py @ 417:83d537f1dfbb
Implement sub-jails: allow to get a jailed configuration from a jail
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 01 Dec 2021 23:10:20 +0100 |
| parents | 2abde0d3c735 |
| children | bb5f11abd12a |
comparison
equal
deleted
inserted
replaced
| 416:2abde0d3c735 | 417:83d537f1dfbb |
|---|---|
| 813 return self._base.getvar_s(self._pathstr + varname, default=default) | 813 return self._base.getvar_s(self._pathstr + varname, default=default) |
| 814 | 814 |
| 815 def getfirstvar_s(self, *varnames, **kwds): | 815 def getfirstvar_s(self, *varnames, **kwds): |
| 816 real_varnames = [self._pathstr + vn for vn in varnames] | 816 real_varnames = [self._pathstr + vn for vn in varnames] |
| 817 return self._base.getfirstvar_s(*real_varnames, **kwds) | 817 return self._base.getfirstvar_s(*real_varnames, **kwds) |
| 818 | |
| 819 def jailed(self, rootpath=None, root=None, bind_root=True): | |
| 820 """Return a "jailed" configuration that effectively is a | |
| 821 subjail of the current jail | |
| 822 | |
| 823 For a more complete description see :meth:`.Configuration.jailed`. | |
| 824 | |
| 825 """ | |
| 826 if rootpath is not None and root is not None: | |
| 827 raise ValueError("only one of `rootpath' or `root' can be given") | |
| 828 if rootpath is None and root is None: | |
| 829 raise ValueError("one of `rootpath' or `root' must be given") | |
| 830 if rootpath is not None and not isinstance(rootpath, (list, tuple)): | |
| 831 raise TypeError("`rootpath' must be a list or a tuple") | |
| 832 if root is not None: | |
| 833 # convert to path | |
| 834 varns, varname = self._base._split_ns(root) | |
| 835 if varns: | |
| 836 raise ValueError( | |
| 837 "sub-jails do not support namespaces") | |
| 838 if varname: | |
| 839 rootpath = [ | |
| 840 self._base.unquote(p) for p in varname.split( | |
| 841 self._base._HIER_SEPARATOR) | |
| 842 ] | |
| 843 else: | |
| 844 rootpath = tuple() | |
| 845 if self._path: | |
| 846 new_rootpath = self._path + tuple(rootpath) | |
| 847 else: | |
| 848 new_rootpath = rootpath | |
| 849 sjc = _JailedConfiguration(*new_rootpath) | |
| 850 if bind_root: | |
| 851 sjc.rebind(self._base) | |
| 852 return sjc |
