better error message in case of config file errors
[auto-debuild.git] / auto_debuild.py
index b921d7cded6d5634a24ece1eb8081de4601a1a15..f9f0672244dde929712cb789ba8da3f8a33f6ea8 100755 (executable)
@@ -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: