]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/util.py
Add support for a working dir in wizard.shell
[wizard.git] / wizard / util.py
index ce8d02ed3515809d34c9322a693618da4e8d6c0e..6c9764d317d88d4dd8f6f05b4546d91778665ec4 100644 (file)
@@ -19,6 +19,8 @@ import httplib
 import urllib
 import time
 import logging
+import random
+import string
 
 import wizard
 
@@ -372,23 +374,9 @@ def mixed_newlines(filename):
     f.close() # just to be safe
     return ret
 
-def assert_all_writable(dir="."):
-    """
-    Recursively checks if all directories are writable and all files are
-    readable.  Raises :exc:`PermissionsError` if this is not true.
-    """
-    for dirpath, dirname, filenames in os.walk(dir):
-        if not os.access(dirpath, os.R_OK):
-            logging.warning("Could not write %s", dirpath)
-            raise PermissionsError
-        for filename in filenames:
-            path = os.path.join(dirpath, filename)
-            if os.path.islink(path):
-                # assume it's ok
-                continue
-            if not os.access(path, os.R_OK):
-                logging.warning("Could not read %s", path)
-                raise PermissionsError
+def random_key(length=30):
+    """Generates a random alphanumeric key of ``length`` size."""
+    return ''.join(random.choice(string.letters + string.digits) for i in xrange(length))
 
 class NoOperatorInfo(wizard.Error):
     """No information could be found about the operator from Kerberos."""