From 9dbd9d85933d2b220b1cf483b911bd0a56531335 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Tue, 17 Jun 2008 00:53:51 -0300 Subject: [PATCH] Add die() function to pymind for fatal errors. --- pymind | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/pymind b/pymind index ee586a4..bc164bb 100755 --- a/pymind +++ b/pymind @@ -80,29 +80,28 @@ def activate_ip_forward(): log.warning("Can't set ip_forward: %s", e) +def die(status, msg, *args): + log.critical(msg, *args) + sys.exit(status) + def get_config(paths, version, desc, add_options, defaults): global config_file_paths try: (config, args) = load_config(paths, version, desc, add_options, defaults) except ConfigError, e: - log.critical(str(e)) - sys.exit(EXIT_CONFIG_ERROR) + die(EXIT_CONFIG_ERROR, str(e)) except MissingSectionHeaderError, e: - log.critical("%s:%s: missing section header near: %s", e.filename, e.lineno, - e.line) - sys.exit(EXIT_CONFIG_ERROR) + dir(EXIT_CONFIG_ERROR, "%s:%s: missing section header near: %s", + e.filename, e.lineno, e.line) except ParsingError, e: for (lineno, line) in e.errors: log.critical("%s:%s: invalid syntax near: %s", e.filename, lineno, line) - log.critical(str(e.errors)) - sys.exit(EXIT_CONFIG_ERROR) + die(EXIT_CONFIG_ERROR, str(e.errors)) except Invalid, e: - log.critical(str(e.unpack_errors())) - sys.exit(EXIT_CONFIG_ERROR) + die(EXIT_CONFIG_ERROR, str(e.unpack_errors())) except LoadError, e: - log.critical("service '%s' not found (see option --services-dir)", - e.service_name) - sys.exit(EXIT_NO_SERVICE) + die(EXIT_NO_SERVICE, "service '%s' not found (see option " \ + "--services-dir)", e.service_name) return (config, args) -- 2.43.0