From 4a1e59744dd00e35bae6c32b44a3708113b3bdfe Mon Sep 17 00:00:00 2001 From: Jean Raby Date: Mon, 27 Jun 2011 22:43:48 +0000 Subject: [PATCH] Add options handling to sogoLogin.py The script can now be used from the CLI to get the SOGo auth cookie. Monotone-Parent: a7450cb20f9b7540324748f847e35d9eb3e1ba15 Monotone-Revision: da943d19b66326d6a44506dad61363238c96ca37 Monotone-Author: jraby@inverse.ca Monotone-Date: 2011-06-27T22:43:48 Monotone-Branch: ca.inverse.sogo --- Tests/Integration/sogoLogin.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/Tests/Integration/sogoLogin.py b/Tests/Integration/sogoLogin.py index 7a387f1b1..6eef104c9 100644 --- a/Tests/Integration/sogoLogin.py +++ b/Tests/Integration/sogoLogin.py @@ -1,6 +1,7 @@ #!/usr/bin/python from config import hostname, port, username, password +import sys, getopt import webdavlib import urllib import urllib2 @@ -14,10 +15,9 @@ def getAuthCookie(hostname, port, username, password) : urllib2.install_opener(opener) creds = urllib.urlencode([("userName",username), ("password", password)]) - req = urllib2.Request("http://%s/SOGo/connect" % hostname, creds) + req = urllib2.Request("http://%s:%s/SOGo/connect" % (hostname, port), creds) fd = urllib2.urlopen(req) - #print fd.info() for cookie in cjar : if cookie.name == "0xHIGHFLYxSOGo": @@ -25,5 +25,32 @@ def getAuthCookie(hostname, port, username, password) : break return "0xHIGHFLYxSOGo="+authinfo + +def usage() : + msg ="""Usage: +%s [-h] [-H | --host=hostname] [-p|--passwd=password] \ +[-P|--port=port] [-u|--user=username]\n""" % sys.argv[0] + + sys.stderr.write(msg); + if __name__ == "__main__" : - getAuthCookie() + try: + opts, args = getopt.getopt (sys.argv[1:], "hH:p:P:u:", \ + ("host=", "passwd=", "port=", "user=")); + except getopt.GetoptError: + usage() + exit(1) + for o, v in opts : + if o == "-h" : + usage() + exit(1) + elif o == "-H" or o == "--host" : + hostname = v + elif o == "-p" or o == "--passwd" : + password = v + elif o == "-P" or o == "--port" : + port = v + elif o == "-u" or o == "--user" : + username = v + + print getAuthCookie(hostname, port, username, password)