gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-bank] 04/10: config parser catches exception for con


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] 04/10: config parser catches exception for config file not found
Date: Wed, 12 Jul 2017 12:55:40 +0200

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository bank.

commit b6c8487d2c3b496ee464bbee52460da98f522cef
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon May 29 16:08:56 2017 +0200

    config parser catches exception for config file not found
---
 Makefile.am              |  3 +-
 talerbank/talerconfig.py | 73 ++++++++++++++++++++++++++----------------------
 2 files changed, 41 insertions(+), 35 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 7db62d4..8e2032c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -28,7 +28,8 @@ check:
 #      @export DJANGO_SETTINGS_MODULE="talerbank.settings" 
TALER_PREFIX="@prefix@" TALER_CONFIG_FILE="bank-check.conf" && python3 -m 
django test talerbank.app.tests
 
 check_with_wrapper:
-       @export DJANGO_SETTINGS_MODULE="talerbank.settings" 
TALER_PREFIX="@prefix@" TALER_CONFIG_FILE="bank-check.conf" && python3 
run_tests.py
+       @export DJANGO_SETTINGS_MODULE="talerbank.settings" 
TALER_PREFIX="@prefix@" TALER_CONFIG_FILE="bank-check-alt.conf" && python3 
run_tests_err.py
+#      @export DJANGO_SETTINGS_MODULE="talerbank.settings" 
TALER_PREFIX="@prefix@" TALER_CONFIG_FILE="bank-check.conf" && python3 
run_tests.py
 
 # install into prefix
 install-exec-hook:
diff --git a/talerbank/talerconfig.py b/talerbank/talerconfig.py
index ba4dfbb..3eab795 100644
--- a/talerbank/talerconfig.py
+++ b/talerbank/talerconfig.py
@@ -25,6 +25,7 @@ import logging
 import collections
 import os
 import weakref
+import sys
 
 logger = logging.getLogger(__name__)
 
@@ -249,40 +250,44 @@ class TalerConfig:
 
     def load_file(self, filename):
         sections = self.sections
-        with open(filename, "r") as file:
-            lineno = 0
-            current_section = None
-            for line in file:
-                lineno += 1
-                line = line.strip()
-                if len(line) == 0:
-                    # empty line
-                    continue
-                if line.startswith("#"):
-                    # comment
-                    continue
-                if line.startswith("["):
-                    if not line.endswith("]"):
-                        logger.error("invalid section header in line %s: %s", 
lineno, repr(line))
-                    section_name = line.strip("[]").strip().strip('"')
-                    current_section = section_name
-                    continue
-                if current_section is None:
-                    logger.error("option outside of section in line %s: %s", 
lineno, repr(line))
-                    continue
-                kv = line.split("=", 1)
-                if len(kv) != 2:
-                    logger.error("invalid option in line %s: %s", lineno, 
repr(line))
-                key = kv[0].strip()
-                value = kv[1].strip()
-                if value.startswith('"'):
-                    value = value[1:]
-                    if not value.endswith('"'):
-                        logger.error("mismatched quotes in line %s: %s", 
lineno, repr(line))
-                    else:
-                        value = value[:-1]
-                e = Entry(self.sections, current_section, key, value, 
filename, lineno)
-                sections[current_section][key] = e
+        try:
+            with open(filename, "r") as file:
+                lineno = 0
+                current_section = None
+                for line in file:
+                    lineno += 1
+                    line = line.strip()
+                    if len(line) == 0:
+                        # empty line
+                        continue
+                    if line.startswith("#"):
+                        # comment
+                        continue
+                    if line.startswith("["):
+                        if not line.endswith("]"):
+                            logger.error("invalid section header in line %s: 
%s", lineno, repr(line))
+                        section_name = line.strip("[]").strip().strip('"')
+                        current_section = section_name
+                        continue
+                    if current_section is None:
+                        logger.error("option outside of section in line %s: 
%s", lineno, repr(line))
+                        continue
+                    kv = line.split("=", 1)
+                    if len(kv) != 2:
+                        logger.error("invalid option in line %s: %s", lineno, 
repr(line))
+                    key = kv[0].strip()
+                    value = kv[1].strip()
+                    if value.startswith('"'):
+                        value = value[1:]
+                        if not value.endswith('"'):
+                            logger.error("mismatched quotes in line %s: %s", 
lineno, repr(line))
+                        else:
+                            value = value[:-1]
+                    e = Entry(self.sections, current_section, key, value, 
filename, lineno)
+                    sections[current_section][key] = e
+        except FileNotFoundError:
+            logger.error("Configuration file (%s) not found", filename)
+            sys.exit(1)
 
 
     def dump(self):

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]