From d5a816df86230999abb9952ecce87d359a665a12 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Mon, 26 Nov 2018 12:22:33 +1100 Subject: [PATCH] mavparmdiff.py: add option to not exclude some parameters from comparison --- mavparm.py | 8 ++++---- tools/mavparmdiff.py | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/mavparm.py b/mavparm.py index d879e5ef3..92004bba4 100644 --- a/mavparm.py +++ b/mavparm.py @@ -53,7 +53,7 @@ def save(self, filename, wildcard='*', verbose=False): print("Saved %u parameters to %s" % (count, filename)) - def load(self, filename, wildcard='*', mav=None, check=True): + def load(self, filename, wildcard='*', mav=None, check=True, use_excludes=True): '''load parameters from a file''' try: f = open(filename, mode='r') @@ -72,7 +72,7 @@ def load(self, filename, wildcard='*', mav=None, check=True): print("Invalid line: %s" % line) continue # some parameters should not be loaded from files - if a[0] in self.exclude_load: + if use_excludes and a[0] in self.exclude_load: continue if not fnmatch.fnmatch(a[0].upper(), wildcard.upper()): continue @@ -111,10 +111,10 @@ def show(self, wildcard='*'): if fnmatch.fnmatch(str(p).upper(), wildcard.upper()): self.show_param_value(str(p), "%f" % self.get(p)) - def diff(self, filename, wildcard='*'): + def diff(self, filename, wildcard='*', use_excludes=True): '''show differences with another parameter file''' other = MAVParmDict() - if not other.load(filename): + if not other.load(filename, use_excludes=use_excludes): return keys = sorted(list(set(self.keys()).union(set(other.keys())))) for k in keys: diff --git a/tools/mavparmdiff.py b/tools/mavparmdiff.py index 75d805655..9c14638a3 100755 --- a/tools/mavparmdiff.py +++ b/tools/mavparmdiff.py @@ -9,6 +9,16 @@ parser = ArgumentParser(description=__doc__) parser.add_argument("file1", metavar="FILE1") parser.add_argument("file2", metavar="FILE2") +parser.add_argument("--use-excludes", + help="exclude volatile and similar parameters", + default=True, + action='store_true', + dest='use_excludes') +parser.add_argument("--no-excludes", + help="include volatile and similar parameters", + default=True, + action='store_false', + dest='use_excludes') args = parser.parse_args() file1 = args.file1 @@ -16,6 +26,7 @@ p1 = mavparm.MAVParmDict() p2 = mavparm.MAVParmDict() -p1.load(file2) -p1.diff(file1) +print("use_excludes=%s" % str(args.use_excludes)) +p1.load(file2, use_excludes=args.use_excludes) +p1.diff(file1, use_excludes=args.use_excludes)