[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Freeipa-devel] [PATCH] add verbose flag to admin tools



The python xmlrpclib library offers a verbose option to print the HTTP headers and the XML request and response. Added a --verbose flag to the admin tools and the client API to enable this.

Also fix the python imports. I had attempted to wrap everything in a try/except so we could catch a ^C without a backtrace during imports but this masked other errors.

rob
>From 4dda50bdd79b83a0b77640a10e1d45214792e1c8 Mon Sep 17 00:00:00 2001
From: Rob Crittenden <rcritten redhat com>
Date: Thu, 24 Apr 2008 10:25:30 -0400
Subject: [PATCH] Add --verbose option so the HTTP headers and XML request/response can be seen.

Also re-do the way modules are imported. I was attemping to have ^C handled
gracefully but the way I did it could mask other problems.

443987
---
 ipa-admintools/ipa-adddelegation  |   44 ++++++++++++++++++++-------------
 ipa-admintools/ipa-addgroup       |   42 ++++++++++++++++++++------------
 ipa-admintools/ipa-addservice     |   48 ++++++++++++++++++++++--------------
 ipa-admintools/ipa-adduser        |   44 ++++++++++++++++++++-------------
 ipa-admintools/ipa-deldelegation  |   40 +++++++++++++++++++-----------
 ipa-admintools/ipa-delgroup       |   34 +++++++++++++++++---------
 ipa-admintools/ipa-delservice     |   40 ++++++++++++++++++++----------
 ipa-admintools/ipa-deluser        |   34 +++++++++++++++++---------
 ipa-admintools/ipa-findgroup      |   36 +++++++++++++++++----------
 ipa-admintools/ipa-findservice    |   36 +++++++++++++++++----------
 ipa-admintools/ipa-finduser       |   41 ++++++++++++++++++++-----------
 ipa-admintools/ipa-listdelegation |   40 +++++++++++++++++++-----------
 ipa-admintools/ipa-lockuser       |   34 +++++++++++++++++---------
 ipa-admintools/ipa-moddelegation  |   44 ++++++++++++++++++++-------------
 ipa-admintools/ipa-modgroup       |   42 ++++++++++++++++++++------------
 ipa-admintools/ipa-moduser        |   40 +++++++++++++++++++-----------
 ipa-admintools/ipa-passwd         |   38 ++++++++++++++++++----------
 ipa-admintools/ipa-pwpolicy       |   36 +++++++++++++++++----------
 ipa-python/ipaclient.py           |    4 +-
 ipa-python/rpcclient.py           |   10 +++++--
 20 files changed, 457 insertions(+), 270 deletions(-)

diff --git a/ipa-admintools/ipa-adddelegation b/ipa-admintools/ipa-adddelegation
index bd55d05..a7748cc 100644
--- a/ipa-admintools/ipa-adddelegation
+++ b/ipa-admintools/ipa-adddelegation
@@ -17,10 +17,34 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
+import sys
+try:
+    from optparse import OptionParser
+    import ipa
+    import ipa.user
+    import ipa.ipaclient as ipaclient
+    import ipa.config
+    import ipa.aci
+    import ipa.ipaadminutil as ipaadminutil
+    import ipa.ipautil as ipautil
+
+    import xmlrpclib
+    import kerberos
+    import krbV
+    import ldap
+    import errno
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
 
 def usage():
     print "ipa-adddelegation [-l|--list]"
-    print "ipa-adddelegation [-a|--attributes attr1,attr2,..,attrn] [-s|--source STRING] [-t|--target STRING] name"
+    print "ipa-adddelegation [-a|--attributes attr1,attr2,..,attrn] [-s|--source STRING] [-t|--target STRING] [-v|--verbose] name"
     sys.exit(1)
 
 def parse_options():
@@ -33,6 +57,8 @@ def parse_options():
                       help="The target group name")
     parser.add_option("-l", "--list", dest="list", action="store_true",
                       help="List common attributes (this is not an exhaustive list)")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
     parser.add_option("--usage", action="store_true",
                       help="Program usage")
 
@@ -151,22 +177,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa
-    import ipa.user
-    import ipa.ipaclient as ipaclient
-    import ipa.config
-    import ipa.aci
-    import ipa.ipaadminutil as ipaadminutil
-    import ipa.ipautil as ipautil
-
-    import xmlrpclib
-    import kerberos
-    import krbV
-    import ldap
-    import errno
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-admintools/ipa-addgroup b/ipa-admintools/ipa-addgroup
index 58190c0..6bf35f6 100644
--- a/ipa-admintools/ipa-addgroup
+++ b/ipa-admintools/ipa-addgroup
@@ -17,9 +17,32 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
+import sys
+try:
+    from optparse import OptionParser
+    import ipa
+    import ipa.group
+    import ipa.ipaclient as ipaclient
+    import ipa.ipavalidate as ipavalidate
+    import ipa.ipautil as ipautil
+    import ipa.config
+    import ipa.ipaerror
+
+    import xmlrpclib
+    import kerberos
+    import ldap
+    import errno
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
 
 def usage():
-    print "ipa-addgroup [-d|--description STRING] [-g|--gid GID] group"
+    print "ipa-addgroup [-d|--description STRING] [-g|--gid GID] [-v|--verbose] group"
     sys.exit(1)
 
 def parse_options():
@@ -28,6 +51,8 @@ def parse_options():
                       help="A description of this group")
     parser.add_option("-g", "--gid", dest="gid",
                       help="The gid to use for this group. If not included one is automatically set.")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
     parser.add_option("--usage", action="store_true",
                       help="Program usage")
 
@@ -88,21 +113,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa
-    import ipa.group
-    import ipa.ipaclient as ipaclient
-    import ipa.ipavalidate as ipavalidate
-    import ipa.ipautil as ipautil
-    import ipa.config
-    import ipa.ipaerror
-
-    import xmlrpclib
-    import kerberos
-    import ldap
-    import errno
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-admintools/ipa-addservice b/ipa-admintools/ipa-addservice
index 1702069..67ec834 100644
--- a/ipa-admintools/ipa-addservice
+++ b/ipa-admintools/ipa-addservice
@@ -17,9 +17,35 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
+import sys
+try:
+    from optparse import OptionParser
+    import ipa
+    import ipa.user
+    import ipa.ipaclient as ipaclient
+    import ipa.ipavalidate as ipavalidate
+    import ipa.ipautil as ipautil
+    import ipa.config
+
+    import base64
+
+    import xmlrpclib
+    import kerberos
+    import krbV
+    import ldap
+    import getpass
+    import errno
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
 
 def usage():
-    print "ipa-addservice [--force] principal"
+    print "ipa-addservice [--force] [-v|--verbose] principal"
     sys.exit(1)
 
 def parse_options():
@@ -29,6 +55,8 @@ def parse_options():
                       help="Force a service principal name")
     parser.add_option("--usage", action="store_true",
                       help="Program usage")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
 
     args = ipa.config.init_config(sys.argv)
     options, args = parser.parse_args(args)
@@ -52,24 +80,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa
-    import ipa.user
-    import ipa.ipaclient as ipaclient
-    import ipa.ipavalidate as ipavalidate
-    import ipa.ipautil as ipautil
-    import ipa.config
-
-    import base64
-
-    import xmlrpclib
-    import kerberos
-    import krbV
-    import ldap
-    import getpass
-    import errno
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-admintools/ipa-adduser b/ipa-admintools/ipa-adduser
index e6ce0e5..be0912e 100644
--- a/ipa-admintools/ipa-adduser
+++ b/ipa-admintools/ipa-adduser
@@ -17,9 +17,33 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
+import sys
+try:
+    from optparse import OptionParser
+    import ipa
+    import ipa.user
+    import ipa.ipaclient as ipaclient
+    import ipa.ipavalidate as ipavalidate
+    import ipa.ipautil as ipautil
+    import ipa.config
+
+    import xmlrpclib
+    import kerberos
+    import krbV
+    import ldap
+    import getpass
+    import errno
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
 
 def usage():
-    print "ipa-adduser [-c|--gecos STRING] [-d|--directory STRING] [-f|--firstname STRING] [-l|--lastname STRING] [-s|--shell] [-g|--groups] [-k|krb-principal [-M|mailAddress] user"
+    print "ipa-adduser [-c|--gecos STRING] [-d|--directory STRING] [-f|--firstname STRING] [-l|--lastname STRING] [-s|--shell] [-g|--groups] [-k|krb-principal [-M|mailAddress] [-v|--verbose] user"
     sys.exit(1)
 
 def parse_options():
@@ -44,6 +68,8 @@ def parse_options():
                       help="Set user's e-mail address")
     parser.add_option("--usage", action="store_true",
                       help="Program usage")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
 
     args = ipa.config.init_config(sys.argv)
     options, args = parser.parse_args(args)
@@ -221,22 +247,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa
-    import ipa.user
-    import ipa.ipaclient as ipaclient
-    import ipa.ipavalidate as ipavalidate
-    import ipa.ipautil as ipautil
-    import ipa.config
-
-    import xmlrpclib
-    import kerberos
-    import krbV
-    import ldap
-    import getpass
-    import errno
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-admintools/ipa-deldelegation b/ipa-admintools/ipa-deldelegation
index fc33a9b..1eeb517 100644
--- a/ipa-admintools/ipa-deldelegation
+++ b/ipa-admintools/ipa-deldelegation
@@ -17,17 +17,41 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #   
+import sys
+try:
+    from optparse import OptionParser
+    import ipa.ipaclient as ipaclient
+    import ipa.config
+    import ipa.ipautil as ipautil
+
+    import xmlrpclib
+    import kerberos
+    import copy
+    import errno
+
+    import ipa.aci
+    from ipa import ipaerror
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
 
 aci_fields = ['*', 'aci']
 
 def usage():
-    print "ipa-deldelgation name"
+    print "ipa-deldelgation [-v|--verbose] name"
     sys.exit(1)
 
 def parse_options():
     parser = OptionParser()
     parser.add_option("--usage", action="store_true",
                       help="Program usage")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
 
     args = ipa.config.init_config(sys.argv)
     options, args = parser.parse_args(args)
@@ -92,20 +116,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa.ipaclient as ipaclient
-    import ipa.config
-    import ipa.ipautil as ipautil
-
-    import xmlrpclib
-    import kerberos
-    import copy
-    import errno
-
-    import ipa.aci
-    from ipa import ipaerror
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-admintools/ipa-delgroup b/ipa-admintools/ipa-delgroup
index 34f5f27..cf66ac1 100644
--- a/ipa-admintools/ipa-delgroup
+++ b/ipa-admintools/ipa-delgroup
@@ -17,15 +17,36 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
+import sys
+try:
+    from optparse import OptionParser
+    import ipa
+    import ipa.ipaclient as ipaclient
+    import ipa.config
+    import ipa.ipautil as ipautil
+    import errno
+
+    import xmlrpclib
+    import kerberos
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
 
 def usage():
-    print "ipa-delgroup group"
+    print "ipa-delgroup [-v|--verbose] group"
     sys.exit(1)
 
 def parse_options():
     parser = OptionParser()
     parser.add_option("--usage", action="store_true",
                       help="Program usage")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
 
     args = ipa.config.init_config(sys.argv)
     options, args = parser.parse_args(args)
@@ -60,17 +81,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa
-    import ipa.ipaclient as ipaclient
-    import ipa.config
-    import ipa.ipautil as ipautil
-    import errno
-
-    import xmlrpclib
-    import kerberos
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-admintools/ipa-delservice b/ipa-admintools/ipa-delservice
index 610d79b..d980762 100644
--- a/ipa-admintools/ipa-delservice
+++ b/ipa-admintools/ipa-delservice
@@ -17,13 +17,38 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
+import sys
+try:
+    from optparse import OptionParser
+    import ipa
+    import ipa.ipaclient as ipaclient
+    import ipa.config
+    import ipa.ipautil as ipautil
+
+    import xmlrpclib
+    import kerberos
+    import krbV
+    import ldap
+    import errno
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
 
 def usage():
-    print "ipa-delservice principal"
+    print "ipa-delservice [-v|--verbose] principal"
     sys.exit(1)
 
 def parse_options():
     parser = OptionParser()
+    parser.add_option("--usage", action="store_true",
+                      help="Program usage")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
 
     args = ipa.config.init_config(sys.argv)
     options, args = parser.parse_args(args)
@@ -60,19 +85,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa
-    import ipa.ipaclient as ipaclient
-    import ipa.config
-    import ipa.ipautil as ipautil
-
-    import xmlrpclib
-    import kerberos
-    import krbV
-    import ldap
-    import errno
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-admintools/ipa-deluser b/ipa-admintools/ipa-deluser
index 36f113d..39bdff9 100644
--- a/ipa-admintools/ipa-deluser
+++ b/ipa-admintools/ipa-deluser
@@ -17,15 +17,36 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
+import sys
+try:
+    from optparse import OptionParser
+    import ipa
+    import ipa.ipaclient as ipaclient
+    import ipa.ipautil as ipautil
+    import ipa.config
+    import errno
+
+    import xmlrpclib
+    import kerberos
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
 
 def usage():
-    print "ipa-deluser user"
+    print "ipa-deluser [-v|--verbose] user"
     sys.exit(1)
 
 def parse_options():
     parser = OptionParser()
     parser.add_option("--usage", action="store_true",
                       help="Program usage")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
 
     args = ipa.config.init_config(sys.argv)
     options, args = parser.parse_args(args)
@@ -45,17 +66,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa
-    import ipa.ipaclient as ipaclient
-    import ipa.ipautil as ipautil
-    import ipa.config
-    import errno
-
-    import xmlrpclib
-    import kerberos
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-admintools/ipa-findgroup b/ipa-admintools/ipa-findgroup
index 706e77a..0c0cf8e 100644
--- a/ipa-admintools/ipa-findgroup
+++ b/ipa-admintools/ipa-findgroup
@@ -17,9 +17,29 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
+import sys
+try:
+    from optparse import OptionParser
+    import ipa.ipaclient as ipaclient
+    import ipa.ipaadminutil as ipaadminutil
+    import ipa.ipautil as ipautil
+    import ipa.config
+
+    import errno
+    import sys
+    import xmlrpclib
+    import kerberos
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
 
 def usage():
-    print "ipa-findgroup [-a|--all] [-n|--notranslate] group"
+    print "ipa-findgroup [-a|--all] [-n|--notranslate] [-v|--verbose] group"
     sys.exit()
 
 def parse_options():
@@ -32,6 +52,8 @@ def parse_options():
                       help="Don't translate LDAP attributes into readable labels")
     parser.add_option("--usage", action="store_true",
                       help="Program usage")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
 
     args = ipa.config.init_config(sys.argv)
     options, args = parser.parse_args(args)
@@ -111,18 +133,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa.ipaclient as ipaclient
-    import ipa.ipaadminutil as ipaadminutil
-    import ipa.ipautil as ipautil
-    import ipa.config
-
-    import errno
-    import sys
-    import xmlrpclib
-    import kerberos
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-admintools/ipa-findservice b/ipa-admintools/ipa-findservice
index fc4aa8b..a5ae2be 100644
--- a/ipa-admintools/ipa-findservice
+++ b/ipa-admintools/ipa-findservice
@@ -17,9 +17,29 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
+import sys
+try:
+    from optparse import OptionParser
+    import ipa.ipaclient as ipaclient
+    import ipa.config
+    import ipa.ipautil as ipautil
+    import ipa.ipaadminutil as ipaadminutil
+
+    import errno
+    import sys
+    import xmlrpclib
+    import kerberos
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
 
 def usage():
-    print "ipa-findservice host"
+    print "ipa-findservice [-v|--verbose] host"
     sys.exit()
 
 def parse_options():
@@ -27,6 +47,8 @@ def parse_options():
 
     parser.add_option("--usage", action="store_true",
                       help="Program usage")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
 
     args = ipa.config.init_config(sys.argv)
     options, args = parser.parse_args(args)
@@ -59,18 +81,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa.ipaclient as ipaclient
-    import ipa.config
-    import ipa.ipautil as ipautil
-    import ipa.ipaadminutil as ipaadminutil
-
-    import errno
-    import sys
-    import xmlrpclib
-    import kerberos
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-admintools/ipa-finduser b/ipa-admintools/ipa-finduser
index e7754cc..c3b2177 100644
--- a/ipa-admintools/ipa-finduser
+++ b/ipa-admintools/ipa-finduser
@@ -18,8 +18,30 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
 
+import sys
+try:
+    from optparse import OptionParser
+    import ipa.ipaclient as ipaclient
+    import ipa.config
+    import ipa.ipautil as ipautil
+    import ipa.ipaadminutil as ipaadminutil
+    import base64
+
+    import errno
+    import sys
+    import xmlrpclib
+    import kerberos
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
+
 def usage():
-    print "ipa-finduser [-a|--all] [-n|--notranslate] user"
+    print "ipa-finduser [-a|--all] [-n|--notranslate] [-v|--verbose] user"
     sys.exit()
 
 def parse_options():
@@ -32,6 +54,8 @@ def parse_options():
                       help="Don't translate LDAP attributes into readable labels")
     parser.add_option("--usage", action="store_true",
                       help="Program usage")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
 
     args = ipa.config.init_config(sys.argv)
     options, args = parser.parse_args(args)
@@ -66,7 +90,7 @@ def main():
     if options.usage or len(args) != 2:
         usage()
 
-    client = ipaclient.IPAClient()
+    client = ipaclient.IPAClient(verbose=options.verbose)
     if options.all is None:
         users = client.find_users(args[1], sattrs=['uid','cn','homeDirectory','loginshell'])
     else:
@@ -120,19 +144,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa.ipaclient as ipaclient
-    import ipa.config
-    import ipa.ipautil as ipautil
-    import ipa.ipaadminutil as ipaadminutil
-    import base64
-
-    import errno
-    import sys
-    import xmlrpclib
-    import kerberos
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-admintools/ipa-listdelegation b/ipa-admintools/ipa-listdelegation
index 4dabc81..b734ccb 100644
--- a/ipa-admintools/ipa-listdelegation
+++ b/ipa-admintools/ipa-listdelegation
@@ -17,16 +17,40 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #   
+import sys
+try:
+    from optparse import OptionParser
+    import ipa.ipaclient as ipaclient
+    import ipa.config
+    import ipa.ipautil as ipautil
+
+    import operator
+    import xmlrpclib
+    import kerberos
+    import errno
+
+    import ipa.aci
+    from ipa import ipaerror
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
 
 aci_fields = ['*', 'aci']
 def usage():
-    print "ipa-listdelgation"
+    print "ipa-listdelgation [-v|--verbose]"
     sys.exit(1)
 
 def parse_options():
     parser = OptionParser()
     parser.add_option("--usage", action="store_true",
                       help="Program usage")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
 
     args = ipa.config.init_config(sys.argv)
     options, args = parser.parse_args(args)
@@ -74,20 +98,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa.ipaclient as ipaclient
-    import ipa.config
-    import ipa.ipautil as ipautil
-
-    import operator
-    import xmlrpclib
-    import kerberos
-    import errno
-
-    import ipa.aci
-    from ipa import ipaerror
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-admintools/ipa-lockuser b/ipa-admintools/ipa-lockuser
index 6e0361f..c11f1ea 100644
--- a/ipa-admintools/ipa-lockuser
+++ b/ipa-admintools/ipa-lockuser
@@ -17,9 +17,28 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
+import sys
+try:
+    from optparse import OptionParser
+    import ipa
+    import ipa.ipaclient as ipaclient
+    import ipa.config
+    import ipa.ipautil as ipautil
+    import errno
+
+    import xmlrpclib
+    import kerberos
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
 
 def usage():
-    print "ipa-lockuser [-u|--unlock] user"
+    print "ipa-lockuser [-u|--unlock] [-v|--verbose] user"
     sys.exit(1)
 
 def parse_options():
@@ -28,6 +47,8 @@ def parse_options():
                       help="Unlock a user's account")
     parser.add_option("--usage", action="store_true",
                       help="Program usage")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
 
     args = ipa.config.init_config(sys.argv)
     options, args = parser.parse_args(args)
@@ -64,17 +85,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa
-    import ipa.ipaclient as ipaclient
-    import ipa.config
-    import ipa.ipautil as ipautil
-    import errno
-
-    import xmlrpclib
-    import kerberos
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-admintools/ipa-moddelegation b/ipa-admintools/ipa-moddelegation
index 1c840e1..d6b09ff 100644
--- a/ipa-admintools/ipa-moddelegation
+++ b/ipa-admintools/ipa-moddelegation
@@ -17,12 +17,36 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
+import sys
+try:
+    from optparse import OptionParser
+    import ipa
+    import ipa.ipaclient as ipaclient
+    import ipa.ipaadminutil as ipaadminutil
+    import ipa.config
+    import ipa.aci
+    import ipa.ipautil as ipautil
+
+    import xmlrpclib
+    import kerberos
+    import krbV
+    import ldap
+    import copy
+    import errno
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
 
 aci_fields = ['*', 'aci']
 
 def usage():
     print "ipa-moddelegation [-l|--list]"
-    print "ipa-moddelegation [-a|--attributes attr1,attr2,..,attrn] [-s|--source STRING] [-t|--target STRING] name"
+    print "ipa-moddelegation [-a|--attributes attr1,attr2,..,attrn] [-s|--source STRING] [-t|--target STRING] [-v|--verbose] name"
     sys.exit(1)
 
 def parse_options():
@@ -37,6 +61,8 @@ def parse_options():
                       help="The target group name")
     parser.add_option("--usage", action="store_true",
                       help="Program usage")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
 
     args = ipa.config.init_config(sys.argv)
     options, args = parser.parse_args(args)
@@ -189,22 +215,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa
-    import ipa.ipaclient as ipaclient
-    import ipa.ipaadminutil as ipaadminutil
-    import ipa.config
-    import ipa.aci
-    import ipa.ipautil as ipautil
-
-    import xmlrpclib
-    import kerberos
-    import krbV
-    import ldap
-    import copy
-    import errno
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-admintools/ipa-modgroup b/ipa-admintools/ipa-modgroup
index a91d9a0..6905f50 100644
--- a/ipa-admintools/ipa-modgroup
+++ b/ipa-admintools/ipa-modgroup
@@ -17,12 +17,33 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
+import sys
+try:
+    from optparse import OptionParser
+    import ipa
+    import ipa.group
+    import ipa.ipaclient as ipaclient
+    import ipa.config
+    import ipa.ipaerror
+
+    import xmlrpclib
+    import kerberos
+    import ldap
+    import errno
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
 
 def usage():
     print "ipa-modgroup [-l|--list]"
-    print "ipa-modgroup [-a|--add] [-r|--remove] user group"
-    print "ipa-modgroup [-g|--groupadd] [-e|--groupdel] group group"
-    print "ipa-modgroup [-d|--desc description STRING] [--addattr attribute=value] [--delattr attribute] [--setattr attribute=value] group"
+    print "ipa-modgroup [-a|--add] [-r|--remove] [-v|--verbose] user group"
+    print "ipa-modgroup [-g|--groupadd] [-e|--groupdel] [-v|--verbose] group group"
+    print "ipa-modgroup [-d|--desc description STRING] [--addattr attribute=value] [--delattr attribute] [--setattr attribute=value] [-v|--verbose] group"
     sys.exit(1)
 
 def set_add_usage(which):
@@ -52,6 +73,8 @@ def parse_options():
                       help="List common attributes (this is not an exhaustive list)")
     parser.add_option("--usage", action="store_true",
                       help="Program usage")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
 
     args = ipa.config.init_config(sys.argv)
     options, args = parser.parse_args(args)
@@ -183,19 +206,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa
-    import ipa.group
-    import ipa.ipaclient as ipaclient
-    import ipa.config
-    import ipa.ipaerror
-
-    import xmlrpclib
-    import kerberos
-    import ldap
-    import errno
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-admintools/ipa-moduser b/ipa-admintools/ipa-moduser
index 906a40f..a9fd223 100644
--- a/ipa-admintools/ipa-moduser
+++ b/ipa-admintools/ipa-moduser
@@ -17,10 +17,32 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
+import sys
+try:
+    from optparse import OptionParser
+    import ipa
+    import ipa.user
+    import ipa.ipaclient as ipaclient
+    import ipa.ipavalidate as ipavalidate
+    import ipa.ipautil as ipautil
+    import ipa.config
+
+    import xmlrpclib
+    import kerberos
+    import ldap
+    import errno
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
 
 def usage():
     print "ipa-moduser [--list]"
-    print "ipa-moduser [-a|--activate] [-c|--gecos STRING] [-d|--directory STRING] [-f|--firstname STRING] [-l|--lastname STRING] [-s|--shell STRING] [--addattr attribute=value] [--delattr attribute] [--setattr attribute=value] user"
+    print "ipa-moduser [-a|--activate] [-c|--gecos STRING] [-d|--directory STRING] [-f|--firstname STRING] [-l|--lastname STRING] [-s|--shell STRING] [--addattr attribute=value] [--delattr attribute] [--setattr attribute=value] [-v|--verbose] user"
     sys.exit(1)
 
 def set_add_usage(which):
@@ -54,6 +76,8 @@ def parse_options():
                       help="Set user's e-mail address")
     parser.add_option("--usage", action="store_true",
                       help="Program usage")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
 
     args = ipa.config.init_config(sys.argv)
     options, args = parser.parse_args(args)
@@ -248,20 +272,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa
-    import ipa.user
-    import ipa.ipaclient as ipaclient
-    import ipa.ipavalidate as ipavalidate
-    import ipa.ipautil as ipautil
-    import ipa.config
-
-    import xmlrpclib
-    import kerberos
-    import ldap
-    import errno
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-admintools/ipa-passwd b/ipa-admintools/ipa-passwd
index 22cffca..fc39b7f 100644
--- a/ipa-admintools/ipa-passwd
+++ b/ipa-admintools/ipa-passwd
@@ -17,15 +17,38 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Tempal Place, Suite 330, Boston, MA 02111-1307 USA
 #
+import sys
+try:
+    from optparse import OptionParser
+    import ipa
+    import ipa.ipaclient as ipaclient
+    import ipa.config
+
+    import xmlrpclib
+    import kerberos
+    import krbV
+    import ldap
+    import getpass
+    import errno
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
 
 def usage():
-    print "ipa-passwd [user]"
+    print "ipa-passwd [-v|--verbose] [user]"
     sys.exit(1)
 
 def parse_options():
     parser = OptionParser()
     parser.add_option("--usage", action="store_true",
                       help="Program usage")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
 
     args = ipa.config.init_config(sys.argv)
     options, args = parser.parse_args(args)
@@ -98,19 +121,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa
-    import ipa.ipaclient as ipaclient
-    import ipa.config
-
-    import xmlrpclib
-    import kerberos
-    import krbV
-    import ldap
-    import getpass
-    import errno
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-admintools/ipa-pwpolicy b/ipa-admintools/ipa-pwpolicy
index 481c263..365444f 100644
--- a/ipa-admintools/ipa-pwpolicy
+++ b/ipa-admintools/ipa-pwpolicy
@@ -17,9 +17,29 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
+import sys
+try:
+    from optparse import OptionParser
+    import ipa
+    import ipa.entity
+    import ipa.ipaclient as ipaclient
+    import ipa.config
+
+    import xmlrpclib
+    import kerberos
+    import errno
+    import validate
+except ImportError:
+    print >> sys.stderr, """\
+There was a problem importing one of the required Python modules. The
+error was:
+
+    %s
+""" % sys.exc_value
+    sys.exit(1)
 
 def usage():
-    print "ipa-pwpolicy [--maxlife days] [--minlife hours] [--history number] [--minclasses number] [--minlength number]"
+    print "ipa-pwpolicy [--maxlife days] [--minlife hours] [--history number] [--minclasses number] [--minlength number] [-v|--verbose]"
     print "ipa-pwpolicy --show"
     sys.exit(1)
 
@@ -39,6 +59,8 @@ def parse_options():
                       help="Show the current password policy")
     parser.add_option("--usage", action="store_true",
                       help="Program usage")
+    parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
+                      help="Verbose output of the XML-RPC connection")
 
     args = ipa.config.init_config(sys.argv)
     options, args = parser.parse_args(args)
@@ -104,18 +126,6 @@ def main():
     return 0
 
 try:
-    import sys
-    from optparse import OptionParser
-    import ipa
-    import ipa.entity
-    import ipa.ipaclient as ipaclient
-    import ipa.config
-
-    import xmlrpclib
-    import kerberos
-    import errno
-    import validate
-
     if __name__ == "__main__":
         sys.exit(main())
 except SystemExit, e:
diff --git a/ipa-python/ipaclient.py b/ipa-python/ipaclient.py
index 4fc8369..1cd541c 100644
--- a/ipa-python/ipaclient.py
+++ b/ipa-python/ipaclient.py
@@ -25,13 +25,13 @@ import radius_util
 
 class IPAClient:
 
-    def __init__(self,transport=None):
+    def __init__(self,transport=None,verbose=False):
         if transport:
             self.local = True
             self.transport = transport
         else:
             self.local = False
-            self.transport = rpcclient.RPCClient()
+            self.transport = rpcclient.RPCClient(verbose)
 
     def set_principal(self,princ):
         """Set the name of the principal that will be used for
diff --git a/ipa-python/rpcclient.py b/ipa-python/rpcclient.py
index 1c8e751..aaaa5bb 100644
--- a/ipa-python/rpcclient.py
+++ b/ipa-python/rpcclient.py
@@ -31,13 +31,17 @@ from ipa import config
 
 class RPCClient:
 
-    def __init__(self):
+    def __init__(self, verbose=False):
         self.server = None
+        self.verbose = verbose
         config.init_config()
     
     def server_url(self, server):
         """Build the XML-RPC server URL from our configuration"""
-        return "https://"; + server + "/ipaxml"
+        url = "https://"; + server + "/ipaxml"
+        if self.verbose:
+            print "Connecting to IPA server: %s" % url
+        return url
     
     def setup_server(self):
         """Create our XML-RPC server connection using kerberos
@@ -59,7 +63,7 @@ class RPCClient:
                     else:
                         raise e
 
-        return xmlrpclib.ServerProxy(self.server_url(self.server), KerbTransport())
+        return xmlrpclib.ServerProxy(self.server_url(self.server), KerbTransport(), verbose=self.verbose)
     
 # Higher-level API
 
-- 
1.5.3.3

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]