aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRonan Amicel <ronan.amicel@gmail.com>2012-10-13 18:26:24 +0200
committerRonan Amicel <ronan.amicel@gmail.com>2012-10-13 18:26:24 +0200
commit4289f2c94be37797f9d70ca3efcc56c4c6c13bc4 (patch)
treee444ebeda42aac1656aac08bd33609a5f760c47d
parentrequire.directory should set ownership and mode on existing directories. (diff)
downloadfabtools-4289f2c94be37797f9d70ca3efcc56c4c6c13bc4.tar.xz
Add functions to get a file's owner, group and mode
-rw-r--r--fabtools/files.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/fabtools/files.py b/fabtools/files.py
index c90eca8..b4cf7c2 100644
--- a/fabtools/files.py
+++ b/fabtools/files.py
@@ -37,6 +37,36 @@ def is_link(path, use_sudo=False):
return func('[ -L "%(path)s" ]' % locals()).succeeded
+def owner(path, use_sudo=False):
+ """
+ Get the owner name of a file or directory.
+ """
+ func = use_sudo and sudo or run
+ with settings(hide('running', 'stdout')):
+ return func('stat -c %%U "%(path)s"' % locals())
+
+
+def group(path, use_sudo=False):
+ """
+ Get the group name of a file or directory.
+ """
+ func = use_sudo and sudo or run
+ with settings(hide('running', 'stdout')):
+ return func('stat -c %%G "%(path)s"' % locals())
+
+
+def mode(path, use_sudo=False):
+ """
+ Get the mode (permissions) of a file or directory.
+
+ Returns a string such as ``'0755'``, representing permissions as
+ an octal number.
+ """
+ func = use_sudo and sudo or run
+ with settings(hide('running', 'stdout')):
+ return func('stat -c %%a "%(path)s"' % locals())
+
+
def upload_template(filename, template, context=None, use_sudo=False,
user="root", mkdir=False, chown=False):
"""