add chmod method

This commit is contained in:
agnewee 2017-12-19 23:56:57 +08:00
parent 0475d0c57d
commit e8d80d03e1
1 changed files with 12 additions and 0 deletions

View File

@ -231,3 +231,15 @@ if not WINDOWS:
except: except:
if not ignore_errors: if not ignore_errors:
raise OSError('Link {} to {} error'.format(dst, src)) 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)