From e8d80d03e1ad148549d67b7fea623f782dda5bf8 Mon Sep 17 00:00:00 2001 From: agnewee Date: Tue, 19 Dec 2017 23:56:57 +0800 Subject: [PATCH] add chmod method --- pydu/file.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pydu/file.py b/pydu/file.py index 26a8781..f9eafc2 100644 --- a/pydu/file.py +++ b/pydu/file.py @@ -231,3 +231,15 @@ if not WINDOWS: except: if not ignore_errors: raise OSError('Link {} to {} error'.format(dst, src)) + + + def chmod(src, mode=0o755): + if not os.path.exists(src): + raise OSError('%s is not exists' % src) + + if os.path.isfile(src): + os.chmod(src, mode) + else: + for root, _, files in os.walk(src): + for file_ in files: + os.chmod(os.path.join(os.path.abspath(root), file_), mode)