From c51fb90ce34ee7ba929fdbc5c38cb933deb9adf6 Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Sun, 7 Aug 2011 17:26:28 +0100 Subject: [PATCH] Add symbolic mode information to xstat output, i.e. (drwxr-xr-x). Signed-off-by: Rob Browning Reviewed-by: Zoran Zaric --- cmd/xstat-cmd.py | 3 ++- lib/bup/xstat.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/cmd/xstat-cmd.py b/cmd/xstat-cmd.py index 83d264f..edd01f6 100755 --- a/cmd/xstat-cmd.py +++ b/cmd/xstat-cmd.py @@ -85,7 +85,8 @@ for path in remainder: if 'path' in active_fields: print 'path:', m.path if 'mode' in active_fields: - print 'mode:', oct(m.mode) + print 'mode: %s (%s)' % (oct(m.mode), + xstat.mode_str(m.mode)) if 'link-target' in active_fields and stat.S_ISLNK(m.mode): print 'link-target:', m.symlink_target if 'rdev' in active_fields: diff --git a/lib/bup/xstat.py b/lib/bup/xstat.py index f3e11de..7fcbe8a 100644 --- a/lib/bup/xstat.py +++ b/lib/bup/xstat.py @@ -1,5 +1,6 @@ """Enhanced stat operations for bup.""" import os +import stat as pystat from bup import _helpers @@ -92,3 +93,32 @@ def fstat(path): def lstat(path): return stat_result.from_xstat_rep(_helpers.lstat(path)) + + +def mode_str(mode): + result = '' + if pystat.S_ISREG(mode): + result += '-' + elif pystat.S_ISDIR(mode): + result += 'd' + elif pystat.S_ISCHR(mode): + result += 'c' + elif pystat.S_ISBLK(mode): + result += 'b' + elif pystat.S_ISFIFO(mode): + result += 'p' + elif pystat.S_ISLNK(mode): + result += 'l' + else: + result += '?' + + result += 'r' if (mode & pystat.S_IRUSR) else '-' + result += 'w' if (mode & pystat.S_IWUSR) else '-' + result += 'x' if (mode & pystat.S_IXUSR) else '-' + result += 'r' if (mode & pystat.S_IRGRP) else '-' + result += 'w' if (mode & pystat.S_IWGRP) else '-' + result += 'x' if (mode & pystat.S_IXGRP) else '-' + result += 'r' if (mode & pystat.S_IROTH) else '-' + result += 'w' if (mode & pystat.S_IWOTH) else '-' + result += 'x' if (mode & pystat.S_IXOTH) else '-' + return result -- 2.39.2