From 44eb2cafdbd475a5d0f613007205373f8bc47f0b Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Mon, 21 Sep 2015 11:42:51 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D1=87=D1=82=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B8=D0=B7=20calculate?= =?UTF-8?q?.env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/calculate/lib/configparser.py | 4 ++-- pym/calculate/lib/datavars.py | 31 ++++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/pym/calculate/lib/configparser.py b/pym/calculate/lib/configparser.py index 4e5639e..81eeb8d 100644 --- a/pym/calculate/lib/configparser.py +++ b/pym/calculate/lib/configparser.py @@ -19,7 +19,7 @@ ConfigParser -- responsible for parsing a list of __init__(defaults=None, dict_type=_default_dict, allow_no_value=False, delimiters=('=', ':'), comment_prefixes=('#', ';'), - inline_comment_prefixes=None, strict=True, + inline_comment_prefixes=None, strict=False, empty_lines_in_values=True): Create the parser. When `defaults' is given, it is initialized into the dictionary or intrinsic defaults. The keys must be strings, the values @@ -612,7 +612,7 @@ class RawConfigParser(MutableMapping): if 'empty_lines_in_values' in _3to2kwargs: empty_lines_in_values = _3to2kwargs['empty_lines_in_values']; del _3to2kwargs['empty_lines_in_values'] else: empty_lines_in_values = True if 'strict' in _3to2kwargs: strict = _3to2kwargs['strict']; del _3to2kwargs['strict'] - else: strict = True + else: strict = False if 'inline_comment_prefixes' in _3to2kwargs: inline_comment_prefixes = _3to2kwargs['inline_comment_prefixes']; del _3to2kwargs['inline_comment_prefixes'] else: inline_comment_prefixes = None if 'comment_prefixes' in _3to2kwargs: comment_prefixes = _3to2kwargs['comment_prefixes']; del _3to2kwargs['comment_prefixes'] diff --git a/pym/calculate/lib/datavars.py b/pym/calculate/lib/datavars.py index fc8e2e0..8d439a8 100644 --- a/pym/calculate/lib/datavars.py +++ b/pym/calculate/lib/datavars.py @@ -31,7 +31,7 @@ import operator import traceback from contextlib import contextmanager from types import StringTypes -from calculate.lib.configparser import ConfigParser +from calculate.lib.configparser import ConfigParser, ParsingError def addStdConfig(fileLst,prefix='/'): stdPath = path.join(prefix, @@ -857,11 +857,18 @@ class SimpleDataVars(object): config = ConfigParser(strict=False) if path.isdir(iniFile): rs = RepositorySubstituting(self, system_root=system_root) - config.read(addStdConfig( - searchProfile(iniFile, 'calculate.env', repository_sub=rs), + try: + config.read(addStdConfig( + searchProfile(iniFile, 'calculate.env', + repository_sub=rs), prefix=self.systemRoot), encoding="utf-8") + except ParsingError: + raise DataVarsError(_("Error in calculate.env in profile")) else: - config.read(iniFile, encoding="utf-8") + try: + config.read(iniFile, encoding="utf-8") + except ParsingError: + raise DataVarsError(_("Error in %s") % iniFile) importVars = {} for varname, varobj in self.allVars.items(): if varobj.section not in importVars: @@ -1189,10 +1196,12 @@ class DataVars(SimpleDataVars): for iniFile in calculateIniFiles: if path.exists(iniFile): config = ConfigParser(strict=False) - config.read(iniFile, encoding="utf-8") try: + config.read(iniFile, encoding="utf-8") value = config[section][varname] retVal = value + except ParsingError: + raise DataVarsError(_("Error in %s") % iniFile) except KeyError: pass return retVal.encode('UTF-8') @@ -1244,12 +1253,20 @@ class DataVars(SimpleDataVars): config = ConfigParser(strict=False) if iniName == 'profile': repos = RepositorySubstituting(self) - config.read(addStdConfig( + try: + config.read(addStdConfig( searchProfile(iniFile,'calculate.env', repository_sub=repos)), encoding="utf-8") + except ParsingError: + raise DataVarsError( + _("Error in profile calculate.env")) else: - config.read(iniFile, encoding="utf-8") + try: + config.read(iniFile, encoding="utf-8") + except ParsingError: + raise DataVarsError( + _("Error in %s")%iniFile) iniSections = config.sections() if not iniSections: continue