Skip to content

Commit

Permalink
mavparmdiff.py: add option to not exclude some parameters from compar…
Browse files Browse the repository at this point in the history
…ison
  • Loading branch information
peterbarker committed Nov 26, 2018
1 parent 9b3bdb4 commit d5a816d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 4 additions & 4 deletions mavparm.py
Expand Up @@ -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')
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 13 additions & 2 deletions tools/mavparmdiff.py
Expand Up @@ -9,13 +9,24 @@
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
file2 = args.file2

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)

0 comments on commit d5a816d

Please sign in to comment.