summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Compat.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-12-04 06:57:50 -0600
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-12-04 06:57:55 -0600
commitf35c38e87eafffb497338b9273fe84f284a41dcf (patch)
treef919f37b971b0d32dd098efba945a20c14a3a0df /src/lib/Bcfg2/Compat.py
parentd052c66c5d5e561f2b5de4ebebd60dba7b78b1cc (diff)
downloadbcfg2-f35c38e87eafffb497338b9273fe84f284a41dcf.tar.gz
bcfg2-f35c38e87eafffb497338b9273fe84f284a41dcf.tar.bz2
bcfg2-f35c38e87eafffb497338b9273fe84f284a41dcf.zip
fixed conversion to octal in py3k
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', '')