Function to recursively chmod a directory
authorFrederic Massart <fred@moodle.com>
Fri, 10 Aug 2012 06:41:52 +0000 (14:41 +0800)
committerFrederic Massart <fred@moodle.com>
Fri, 10 Aug 2012 06:41:52 +0000 (14:41 +0800)
lib/tools.py

index 039a7a0..fef1909 100644 (file)
@@ -2,6 +2,7 @@
 # -*- coding: utf-8 -*-
 
 import sys
+import os
 import subprocess, shlex
 import re
 
@@ -14,6 +15,16 @@ def yesOrNo(q):
                elif i == 'n':
                        return False
 
+def chmodRecursive(path, chmod):
+       os.chmod(path, chmod)
+       for (dirpath, dirnames, filenames) in os.walk(path):
+               for d in dirnames:
+                       dir = os.path.join(dirpath, d)
+                       os.chmod(dir, chmod)
+               for f in filenames:
+                       file = os.path.join(dirpath, f)
+                       os.chmod(file, chmod)
+
 def debug(str):
        print str
        sys.stdout.flush()