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.
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)
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)
"""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