summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-03-20 16:49:08 (GMT)
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-03-20 16:49:08 (GMT)
commit3322a02b5e6240f754cce529bc3ae331a1c18bac (patch)
treee575938e94bbb46b0ea74ba4401c4a15447c5a4b
parent796413f66f681d6735245f99fcb2c7c082f749de (diff)
downloadpykolab-3322a02b5e6240f754cce529bc3ae331a1c18bac.tar.gz
Add utils.generate_password() for setup-kolab.py
-rw-r--r--pykolab/utils.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/pykolab/utils.py b/pykolab/utils.py
index 9198c82..e3e2e7b 100644
--- a/pykolab/utils.py
+++ b/pykolab/utils.py
@@ -36,7 +36,10 @@ def ask_question(question, default="", password=False):
Usage: pykolab.utils.ask_question("What is the server?", default="localhost")
"""
if password:
- answer = getpass.getpass("%s: " % (question))
+ if default == "":
+ answer = getpass.getpass("%s: " % (question))
+ else:
+ answer = getpass.getpass("%s [%s]: " % (question, default))
else:
if default == "":
answer = raw_input("%s: " % (question))
@@ -90,6 +93,18 @@ def ask_confirmation(question, default="y", all_inclusive_no=True):
print >> sys.stderr, _("Please answer 'yes' or 'no'.")
sys.stderr.flush()
+def generate_password():
+ import subprocess
+
+ p1 = subprocess.Popen(['head', '-c', '200', '/dev/urandom'], stdout=subprocess.PIPE)
+ p2 = subprocess.Popen(['tr', '-dc', '_A-Z-a-z-0-9'], stdin=p1.stdout, stdout=subprocess.PIPE)
+ p3 = subprocess.Popen(['head', '-c', '15'], stdin=p2.stdout, stdout=subprocess.PIPE)
+ p1.stdout.close()
+ p2.stdout.close()
+ output = p3.communicate()[0]
+
+ return output
+
def normalize(_object):
if type(_object) == list:
result = []