diff options
Diffstat (limited to 'src/lib/Bcfg2/Compat.py')
-rw-r--r-- | src/lib/Bcfg2/Compat.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/lib/Bcfg2/Compat.py b/src/lib/Bcfg2/Compat.py index 23f7ef784..b0f0ef5cf 100644 --- a/src/lib/Bcfg2/Compat.py +++ b/src/lib/Bcfg2/Compat.py @@ -245,3 +245,18 @@ except ImportError: def wraps(wrapped): # pylint: disable=W0613 """ implementation of functools.wraps() for python 2.4 """ return lambda f: f + + +def oct_mode(mode): + """ Convert a decimal number describing a POSIX permissions mode + to a string giving the octal mode. In Python 2, this is a synonym + for :func:`oct`, but in Python 3 the octal format has changed to + ``0o000``, which cannot be used as an octal permissions mode, so + we need to strip the 'o' from the output. I.e., this function + acts like the Python 2 :func:`oct` regardless of what version of + Python is in use. + + :param mode: The decimal mode to convert to octal + :type mode: int + :returns: string """ + return oct(mode).replace('o', '') |