summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Compat.py
diff options
context:
space:
mode:
authorJason Kincl <kincljc@ornl.gov>2012-12-04 08:14:33 -0500
committerJason Kincl <kincljc@ornl.gov>2012-12-04 08:14:33 -0500
commit09a45d745269a419b0c5da0664912e061dc8e5d3 (patch)
treec5c0af33093087f10f0caf5ce021aa4cb0b4a879 /src/lib/Bcfg2/Compat.py
parent648c8f6e313e684d5fadc1fdbc97e08d83eb2b16 (diff)
parentf35c38e87eafffb497338b9273fe84f284a41dcf (diff)
downloadbcfg2-09a45d745269a419b0c5da0664912e061dc8e5d3.tar.gz
bcfg2-09a45d745269a419b0c5da0664912e061dc8e5d3.tar.bz2
bcfg2-09a45d745269a419b0c5da0664912e061dc8e5d3.zip
Merge remote branch 'upstream/master' into jasons-hacking
Diffstat (limited to 'src/lib/Bcfg2/Compat.py')
-rw-r--r--src/lib/Bcfg2/Compat.py15
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', '')