From: Ralf Jung Date: Fri, 5 Oct 2012 12:56:13 +0000 (+0200) Subject: better error message in case of config file errors X-Git-Url: https://git.ralfj.de/auto-debuild.git/commitdiff_plain/cbcb54ccaafd688b86c9cd1f771c74930117a782?hp=b36b79c329864a4681e9339d8b92f950800b4b79 better error message in case of config file errors --- 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: