]> git.mxchange.org Git - flightgear.git/commitdiff
lsprop: also consider includes from <PropertyList>; help improvements
authormfranz <mfranz>
Tue, 19 Aug 2008 06:36:48 +0000 (06:36 +0000)
committermfranz <mfranz>
Tue, 19 Aug 2008 06:36:48 +0000 (06:36 +0000)
scripts/tools/lsprop

index 9e97db488995e1085fc13e7e4cded99902b8a27b..91ebca95c7c42dbdf6a902fd1c83eee82fd197a0 100755 (executable)
@@ -6,15 +6,15 @@ __doc__ = """\
 List properties of FlightGear's <PropertyList> XML files.
 
 Usage:
-       lsprop -h
        lsprop [-v] [-i|-I] [-f <format>] [<list-of-xml-files>]
+       lsprop -h
 
 Options:
-       -h, --help         this help screen
-       -v, --verbose      increase verbosity (can be used multiple times)
+       -h, --help         print this help screen
+       -v, --verbose      increase verbosity
        -i, --all-indices  also show null indices in properties
        -I, --no-indices   don't show any indices in properties
-       -p, --raw-paths    don't replace FG_ROOT/FG_HOME prefix by environment variables
+       -p, --raw-paths    don't replace path prefix by symbols "$FG_ROOT" and "$FG_HOME"
        -f, --format       set output format  (default: --format="%f +%l: %p = '%v'")
 
 Format:
@@ -34,9 +34,12 @@ Environment:
        FG_HOME
        LSPROP_FORMAT      overrides default format
 
-If no file arguments are specified, then the following files are assumed:
+Arguments:
+       If no file arguments are specified, then the following files are assumed:
        $FG_ROOT/preferences.xml
        $FG_ROOT/Aircraft/*/*-set.xml
+
+Current settings:\
 """
 
 
@@ -57,7 +60,7 @@ def errmsg(msg, color = "31;1"):
 
 
 def cook_path(path, force = 0):
-       path = os.path.normpath(path)
+       path = os.path.normpath(os.path.abspath(path))
        if config.raw_paths and not force:
                return path
        if path.startswith(config.root):
@@ -111,33 +114,31 @@ class parse_xml_file(xml.sax.handler.ContentHandler):
                if self.level == 1:
                        if name != "PropertyList":
                                raise XMLError(self.locator, "XML file isn't a <PropertyList>")
-                       return
-
-               if attrs.has_key("n"):
-                       index = int(attrs["n"])
-               elif name in self.stack[-1][2]:
-                       index = self.stack[-1][2][name] + 1
                else:
                        index = 0
-               self.stack[-1][2][name] = index
+                       if attrs.has_key("n"):
+                               index = int(attrs["n"])
+                       elif name in self.stack[-1][2]:
+                               index = self.stack[-1][2][name] + 1
+                       self.stack[-1][2][name] = index
+
+                       self.type = "unspecified"
+                       if attrs.has_key("type"):
+                               self.type = attrs["type"]
 
                if attrs.has_key("include"):
                        path = os.path.dirname(self.path) + "/" + attrs["include"]
-                       if attrs.has_key("omit-node") and attrs["omit-node"] == "y":
+                       if attrs.has_key("omit-node") and attrs["omit-node"] == "y" or self.level == 1:
                                self.stack.append([None, None, self.stack[-1][2], []])
                        else:
                                self.stack.append([name, index, {}, []])
                        parse_xml_file(path, self.nesting + 1, self.stack)
-               else:
+               elif self.level > 1:
                        self.stack.append([name, index, {}, []])
 
-               self.type = "unspecified"
-               if attrs.has_key("type"):
-                       self.type = attrs["type"]
-
        def endElement(self, name):
                value = string.join(self.stack[-1][3], '')
-               if not len(self.stack[-1][2]):
+               if not len(self.stack[-1][2]) and self.level > 1:
                        path = self.pathname()
                        if path:
                                cooked_value = self.escape(value.encode("iso-8859-15", "backslashreplace"))
@@ -217,13 +218,12 @@ def main():
                                "hviIpf:", \
                                ["help", "verbose", "all-indices", "no-indices", "raw-paths", "format="])
        except getopt.GetoptError, msg:
-               print >>sys.stderr, str(msg)
-               return 0
+               errmsg("Error: %s" % msg)
+               return -1
 
        for o, a in opts:
                if o in ("-h", "--help"):
                        print __doc__
-                       print "Current settings:"
                        print '\t--format="%s"' % config.format.replace('"', '\\"')
                        return 0
                if o in ("-v", "--verbose"):