From cbcb54ccaafd688b86c9cd1f771c74930117a782 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 5 Oct 2012 14:56:13 +0200 Subject: [PATCH] better error message in case of config file errors --- auto_debuild.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/auto_debuild.py b/auto_debuild.py index b921d7c..f9f0672 100755 --- a/auto_debuild.py +++ b/auto_debuild.py @@ -32,24 +32,29 @@ def safeCall(*args): def loadConfigFile(file): import shlex # read config file + linenr = 0 with open(file) as file: result = AdvancedDict() curKey = None for line in file: + linenr += 1 isCont = len(line) and line[0].isspace() # remember if we were a continuation line if isCont and curKey is None: - raise Exception("Invalid config: Starting with continuation line") + raise Exception("Invalid config, line %d: Starting with continuation line" % linenr) line = line.strip() if not len(line) or line.startswith("#"): continue # skip empty and comment lines - if isCont: - # continuation line - result[curKey].append(shlex.split(line)) - else: - # option line - pos = line.index("=") # will raise exception when substring is not found - curKey = line[:pos].strip() - value = line[pos+1:] - result[curKey] = shlex.split(value) + try: + if isCont: + # continuation line + result[curKey] += shlex.split(line) + else: + # option line + pos = line.index("=") # will raise exception when substring is not found + curKey = line[:pos].strip() + value = line[pos+1:] + result[curKey] = shlex.split(value) + except Exception: + raise Exception("Invalid config, line %d: Error parsing line (quoting issue?)" % linenr) # add some convencience get functions return result @@ -82,7 +87,7 @@ class RulesFile: print >>f, "" print >>f, ".PHONY: build" # there may be a directory called "build" print >>f, "" - print >>f, "build %:" # need to mention "build" here again explicitly + print >>f, "build %:" # need to mention "build" here again explicitly so PHONY takes effect # write proper dh call dh = self.dh if self.dhWith: -- 2.30.2