Re: [Freeipa-devel] [PATCH] 011 Use sys.exit to quit scripts

2010-11-22 Thread Jakub Hrozek
On Thu, Nov 11, 2010 at 07:36:22AM +0100, Jakub Hrozek wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 On 11/09/2010 08:01 PM, Rob Crittenden wrote:
  Jakub Hrozek wrote:
  -BEGIN PGP SIGNED MESSAGE-
  Hash: SHA1
 
  Instead of print and return, use sys.exit() to quit scripts with an
  error message and a non zero return code.
 
  https://fedorahosted.org/freeipa/ticket/425
 
  
  This isn't applying for me. Can you try to rebase it?
  
  thanks
  
  rob
 
 It should apply cleanly once the remaining diff of the patch that logs
 install script options is pushed. Sorry, I did not mention there was a
 dependency earlier.
 

Attached patch rebased on top of the current master

Jakub
From 84a3b6335bf2b7082469bc9b048245e5605a5f55 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek jhro...@redhat.com
Date: Mon, 8 Nov 2010 23:13:48 +0100
Subject: [PATCH] Use sys.exit to quit scripts

Instead of print and return, use sys.exit() to quit scripts with an
error message and a non zero return code.

https://fedorahosted.org/freeipa/ticket/425
---
 install/tools/ipa-compat-manage   |   16 ---
 install/tools/ipa-dns-install |9 ++
 install/tools/ipa-nis-manage  |   13 +++--
 install/tools/ipa-server-certinstall  |5 +--
 install/tools/ipa-server-install  |   32 -
 ipa-client/ipa-install/ipa-client-install |   43 -
 6 files changed, 45 insertions(+), 73 deletions(-)

diff --git a/install/tools/ipa-compat-manage b/install/tools/ipa-compat-manage
index ded587d..508efd8 100755
--- a/install/tools/ipa-compat-manage
+++ b/install/tools/ipa-compat-manage
@@ -74,11 +74,9 @@ def main():
 loglevel = logging.DEBUG
 
 if len(args) != 1:
-print You must specify one action, either enable or disable
-sys.exit(1)
+sys.exit(You must specify one action, either enable or disable)
 elif args[0] != enable and args[0] != disable and args[0] != status:
-print Unrecognized action [ + args[0] + ]
-sys.exit(1)
+sys.exit(Unrecognized action [ + args[0] + ])
 
 logging.basicConfig(level=loglevel,
 format='%(levelname)s %(message)s')
@@ -102,9 +100,7 @@ def main():
 bind_dn='cn=directory manager', bind_pw=dirman_password
 )
 except errors.LDAPError, lde:
-print An error occurred while connecting to the server.
-print lde
-return 1
+sys.exit(An error occurred while connecting to the server.\n%s\n 
% str(lde))
 
 if args[0] == status:
 try:
@@ -142,9 +138,9 @@ def main():
 # We can't disable schema compat if the NIS plugin is enabled
 try:
 conn.get_entry(netgroup_compat_dn, normalize=False)
-print The NIS plugin is configured, cannot disable 
compatibility.
-print Run 'ipa-nis-manage disable' first.
-return 2
+print sys.stderr, The NIS plugin is configured, cannot 
disable compatibility.
+print sys.stderr, Run 'ipa-nis-manage disable' first.
+sys.exit(2)
 except errors.NotFound:
 pass
 # Make a quick hack for now, directly delete the entries by name,
diff --git a/install/tools/ipa-dns-install b/install/tools/ipa-dns-install
index b7db1be..5604931 100755
--- a/install/tools/ipa-dns-install
+++ b/install/tools/ipa-dns-install
@@ -80,8 +80,7 @@ def main():
 safe_options, options = parse_options()
 
 if os.getegid() != 0:
-print Must be root to setup server
-return 1
+sys.exit(Must be root to setup server)
 
 standard_logging_setup(/var/log/ipaserver-install.log, options.debug, 
filemode='a')
 print \nThe log file for this installation can be found in 
/var/log/ipaserver-install.log
@@ -103,8 +102,7 @@ def main():
 
 # Check bind packages are installed
 if not bindinstance.check_inst(options.unattended):
-print Aborting installation
-return 1
+sys.exit(Aborting installation)
 
 # Initialize the ipalib api
 cfg = dict(
@@ -124,8 +122,7 @@ def main():
 ip_address = resolve_host(api.env.host)
 if not ip_address or not verify_ip_address(ip_address):
 if options.unattended:
-print Unable to resolve IP address for host name
-return 1
+sys.exit(Unable to resolve IP address for host name)
 else:
 ip_address = read_ip_address(api.env.host, fstore)
 logging.debug(will use ip_address: %s\n, ip_address)
diff --git a/install/tools/ipa-nis-manage b/install/tools/ipa-nis-manage
index 6448d17..9151886 100755
--- a/install/tools/ipa-nis-manage
+++ b/install/tools/ipa-nis-manage
@@ -88,11 +88,9 @@ def main():
 loglevel = logging.DEBUG
 
 if len(args) != 1:
-print You must specify one action, either enable 

[Freeipa-devel] [PATCH] 011 Use sys.exit to quit scripts

2010-11-09 Thread Jakub Hrozek
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Instead of print and return, use sys.exit() to quit scripts with an
error message and a non zero return code.

https://fedorahosted.org/freeipa/ticket/425
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAkzZaiIACgkQHsardTLnvCUJpwCffqc36vpRNL9ZUg0Jk67UsWDD
eGAAnjMS5rIqfs4FHLHqZpPfRFtyDkUQ
=w11Y
-END PGP SIGNATURE-
From ede33b23c9f0368c5434ccfc6ff2c2522af11e5c Mon Sep 17 00:00:00 2001
From: Jakub Hrozek jhro...@redhat.com
Date: Mon, 8 Nov 2010 23:13:48 +0100
Subject: [PATCH] Use sys.exit to quit scripts

Instead of print and return, use sys.exit() to quit scripts with an
error message and a non zero return code.

https://fedorahosted.org/freeipa/ticket/425
---
 install/tools/ipa-compat-manage   |   16 ---
 install/tools/ipa-dns-install |9 ++
 install/tools/ipa-nis-manage  |   13 +++--
 install/tools/ipa-server-certinstall  |5 +--
 install/tools/ipa-server-install  |   29 +++
 ipa-client/ipa-install/ipa-client-install |   43 -
 6 files changed, 44 insertions(+), 71 deletions(-)

diff --git a/install/tools/ipa-compat-manage b/install/tools/ipa-compat-manage
index ded587d..508efd8 100755
--- a/install/tools/ipa-compat-manage
+++ b/install/tools/ipa-compat-manage
@@ -74,11 +74,9 @@ def main():
 loglevel = logging.DEBUG
 
 if len(args) != 1:
-print You must specify one action, either enable or disable
-sys.exit(1)
+sys.exit(You must specify one action, either enable or disable)
 elif args[0] != enable and args[0] != disable and args[0] != status:
-print Unrecognized action [ + args[0] + ]
-sys.exit(1)
+sys.exit(Unrecognized action [ + args[0] + ])
 
 logging.basicConfig(level=loglevel,
 format='%(levelname)s %(message)s')
@@ -102,9 +100,7 @@ def main():
 bind_dn='cn=directory manager', bind_pw=dirman_password
 )
 except errors.LDAPError, lde:
-print An error occurred while connecting to the server.
-print lde
-return 1
+sys.exit(An error occurred while connecting to the server.\n%s\n % str(lde))
 
 if args[0] == status:
 try:
@@ -142,9 +138,9 @@ def main():
 # We can't disable schema compat if the NIS plugin is enabled
 try:
 conn.get_entry(netgroup_compat_dn, normalize=False)
-print The NIS plugin is configured, cannot disable compatibility.
-print Run 'ipa-nis-manage disable' first.
-return 2
+print sys.stderr, The NIS plugin is configured, cannot disable compatibility.
+print sys.stderr, Run 'ipa-nis-manage disable' first.
+sys.exit(2)
 except errors.NotFound:
 pass
 # Make a quick hack for now, directly delete the entries by name,
diff --git a/install/tools/ipa-dns-install b/install/tools/ipa-dns-install
index b7db1be..5604931 100755
--- a/install/tools/ipa-dns-install
+++ b/install/tools/ipa-dns-install
@@ -80,8 +80,7 @@ def main():
 safe_options, options = parse_options()
 
 if os.getegid() != 0:
-print Must be root to setup server
-return 1
+sys.exit(Must be root to setup server)
 
 standard_logging_setup(/var/log/ipaserver-install.log, options.debug, filemode='a')
 print \nThe log file for this installation can be found in /var/log/ipaserver-install.log
@@ -103,8 +102,7 @@ def main():
 
 # Check bind packages are installed
 if not bindinstance.check_inst(options.unattended):
-print Aborting installation
-return 1
+sys.exit(Aborting installation)
 
 # Initialize the ipalib api
 cfg = dict(
@@ -124,8 +122,7 @@ def main():
 ip_address = resolve_host(api.env.host)
 if not ip_address or not verify_ip_address(ip_address):
 if options.unattended:
-print Unable to resolve IP address for host name
-return 1
+sys.exit(Unable to resolve IP address for host name)
 else:
 ip_address = read_ip_address(api.env.host, fstore)
 logging.debug(will use ip_address: %s\n, ip_address)
diff --git a/install/tools/ipa-nis-manage b/install/tools/ipa-nis-manage
index 706b0e6..222964c 100755
--- a/install/tools/ipa-nis-manage
+++ b/install/tools/ipa-nis-manage
@@ -88,11 +88,9 @@ def main():
 loglevel = logging.DEBUG
 
 if len(args) != 1:
-print You must specify one action, either enable or disable
-sys.exit(1)
+sys.exit(You must specify one action, either enable or disable)
 elif args[0] != enable and args[0] != disable:
-print Unrecognized action [ + args[0] + ]
-sys.exit(1)
+

Re: [Freeipa-devel] [PATCH] 011 Use sys.exit to quit scripts

2010-11-09 Thread Rob Crittenden

Jakub Hrozek wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Instead of print and return, use sys.exit() to quit scripts with an
error message and a non zero return code.

https://fedorahosted.org/freeipa/ticket/425



This isn't applying for me. Can you try to rebase it?

thanks

rob

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel