lsprop: also consider includes from <PropertyList>; help improvements
This commit is contained in:
parent
3da291dde6
commit
9c2b9af40d
1 changed files with 23 additions and 23 deletions
|
@ -6,15 +6,15 @@ __doc__ = """\
|
||||||
List properties of FlightGear's <PropertyList> XML files.
|
List properties of FlightGear's <PropertyList> XML files.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
lsprop -h
|
|
||||||
lsprop [-v] [-i|-I] [-f <format>] [<list-of-xml-files>]
|
lsprop [-v] [-i|-I] [-f <format>] [<list-of-xml-files>]
|
||||||
|
lsprop -h
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h, --help this help screen
|
-h, --help print this help screen
|
||||||
-v, --verbose increase verbosity (can be used multiple times)
|
-v, --verbose increase verbosity
|
||||||
-i, --all-indices also show null indices in properties
|
-i, --all-indices also show null indices in properties
|
||||||
-I, --no-indices don't show any 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'")
|
-f, --format set output format (default: --format="%f +%l: %p = '%v'")
|
||||||
|
|
||||||
Format:
|
Format:
|
||||||
|
@ -34,9 +34,12 @@ Environment:
|
||||||
FG_HOME
|
FG_HOME
|
||||||
LSPROP_FORMAT overrides default format
|
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/preferences.xml
|
||||||
$FG_ROOT/Aircraft/*/*-set.xml
|
$FG_ROOT/Aircraft/*/*-set.xml
|
||||||
|
|
||||||
|
Current settings:\
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,7 +60,7 @@ def errmsg(msg, color = "31;1"):
|
||||||
|
|
||||||
|
|
||||||
def cook_path(path, force = 0):
|
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:
|
if config.raw_paths and not force:
|
||||||
return path
|
return path
|
||||||
if path.startswith(config.root):
|
if path.startswith(config.root):
|
||||||
|
@ -111,33 +114,31 @@ class parse_xml_file(xml.sax.handler.ContentHandler):
|
||||||
if self.level == 1:
|
if self.level == 1:
|
||||||
if name != "PropertyList":
|
if name != "PropertyList":
|
||||||
raise XMLError(self.locator, "XML file isn't a <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:
|
else:
|
||||||
index = 0
|
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"):
|
if attrs.has_key("include"):
|
||||||
path = os.path.dirname(self.path) + "/" + attrs["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], []])
|
self.stack.append([None, None, self.stack[-1][2], []])
|
||||||
else:
|
else:
|
||||||
self.stack.append([name, index, {}, []])
|
self.stack.append([name, index, {}, []])
|
||||||
parse_xml_file(path, self.nesting + 1, self.stack)
|
parse_xml_file(path, self.nesting + 1, self.stack)
|
||||||
else:
|
elif self.level > 1:
|
||||||
self.stack.append([name, index, {}, []])
|
self.stack.append([name, index, {}, []])
|
||||||
|
|
||||||
self.type = "unspecified"
|
|
||||||
if attrs.has_key("type"):
|
|
||||||
self.type = attrs["type"]
|
|
||||||
|
|
||||||
def endElement(self, name):
|
def endElement(self, name):
|
||||||
value = string.join(self.stack[-1][3], '')
|
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()
|
path = self.pathname()
|
||||||
if path:
|
if path:
|
||||||
cooked_value = self.escape(value.encode("iso-8859-15", "backslashreplace"))
|
cooked_value = self.escape(value.encode("iso-8859-15", "backslashreplace"))
|
||||||
|
@ -217,13 +218,12 @@ def main():
|
||||||
"hviIpf:", \
|
"hviIpf:", \
|
||||||
["help", "verbose", "all-indices", "no-indices", "raw-paths", "format="])
|
["help", "verbose", "all-indices", "no-indices", "raw-paths", "format="])
|
||||||
except getopt.GetoptError, msg:
|
except getopt.GetoptError, msg:
|
||||||
print >>sys.stderr, str(msg)
|
errmsg("Error: %s" % msg)
|
||||||
return 0
|
return -1
|
||||||
|
|
||||||
for o, a in opts:
|
for o, a in opts:
|
||||||
if o in ("-h", "--help"):
|
if o in ("-h", "--help"):
|
||||||
print __doc__
|
print __doc__
|
||||||
print "Current settings:"
|
|
||||||
print '\t--format="%s"' % config.format.replace('"', '\\"')
|
print '\t--format="%s"' % config.format.replace('"', '\\"')
|
||||||
return 0
|
return 0
|
||||||
if o in ("-v", "--verbose"):
|
if o in ("-v", "--verbose"):
|
||||||
|
|
Loading…
Reference in a new issue