]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/util.py
Fix bug where php.ini not being rewritten for MediaWiki.
[wizard.git] / wizard / util.py
index 876f8a985cf257ecdddba2c305ce0c7aa8e70463..8f1d1ba4bff20ab9eb0ca7121febce9e4b51072f 100644 (file)
@@ -25,6 +25,25 @@ import string
 import wizard
 from wizard import user
 
+def boolish(val):
+    """
+    Parse the contents of an environment variable as a boolean.
+    This recognizes more values as ``False`` than :func:`bool` would.
+
+        >>> boolish("0")
+        False
+        >>> boolish("no")
+        False
+        >>> boolish("1")
+        True
+    """
+    try:
+        return bool(int(val))
+    except (ValueError, TypeError):
+        if val == "No" or val == "no" or val == "false" or val == "False":
+            return False
+        return bool(val)
+
 class ChangeDirectory(object):
     """
     Context for temporarily changing the working directory.
@@ -233,6 +252,8 @@ def set_operator_env():
     if op is None:
         return
     info = user.pwnam(op)
+    if not info.realname:
+        return
     os.putenv("GIT_COMMITTER_NAME", info.realname)
     os.putenv("GIT_COMMITTER_EMAIL", info.email)
 
@@ -245,6 +266,8 @@ def set_author_env():
     info = user.passwd()
     if info is None:
         return
+    if not info.realname:
+        return
     os.putenv("GIT_AUTHOR_NAME", "%s" % info.realname)
     os.putenv("GIT_AUTHOR_EMAIL", "%s" % info.email)
 
@@ -349,6 +372,22 @@ 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))
 
+def truncate(version):
+    """Truncates the Scripts specific version number."""
+    return str(version).partition('-scripts')[0]
+
+def init_wizard_dir():
+    """
+    Generates a .wizard directory and initializes it with some common
+    files.  This operation is idempotent.
+    """
+    # no harm in doing this repeatedly
+    wizard_dir = ".wizard"
+    if not os.path.isdir(wizard_dir):
+        os.mkdir(wizard_dir)
+    open(os.path.join(wizard_dir, ".htaccess"), "w").write("Deny from all\n")
+    open(os.path.join(wizard_dir, ".gitignore"), "w").write("*\n")
+
 class NoOperatorInfo(wizard.Error):
     """No information could be found about the operator from Kerberos."""
     pass