Skip to content

Commit

Permalink
UBUNTU: [Packaging] update annotations scripts
Browse files Browse the repository at this point in the history
BugLink: https://bugs.launchpad.net/bugs/1786013
Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
  • Loading branch information
Luke Nowakowski-Krijger committed Jul 11, 2023
1 parent 613945c commit eda1e44
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion debian/scripts/misc/annotations
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- mode: python -*-
# Manage Ubuntu kernel .config and annotations
# Copyright © 2022 Canonical Ltd.
Expand Down
23 changes: 14 additions & 9 deletions debian/scripts/misc/kconfig/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ def _parse_body(self, data: str, parent=True):
entry['note'] = "'" + m.group(1).replace("'", '') + "'"

if not match:
raise Exception('syntax error')
raise SyntaxError('syntax error')
self.config[conf] = entry
except Exception as e:
raise Exception(str(e) + f', line = {line}') from e
raise SyntaxError(str(e) + f', line = {line}') from e
continue

# Invalid line
raise Exception(f'invalid line: {line}')
raise SyntaxError(f'invalid line: {line}')

def _parse(self, data: str):
"""
Expand Down Expand Up @@ -162,9 +162,9 @@ def _parse(self, data: str):
# Sanity check: Verify that all FLAVOUR_DEP flavors are valid
for src, tgt in self.flavour_dep.items():
if src not in self.flavour:
raise Exception(f'Invalid source flavour in FLAVOUR_DEP: {src}')
raise SyntaxError(f'Invalid source flavour in FLAVOUR_DEP: {src}')
if tgt not in self.include_flavour:
raise Exception(f'Invalid target flavour in FLAVOUR_DEP: {tgt}')
raise SyntaxError(f'Invalid target flavour in FLAVOUR_DEP: {tgt}')

def _remove_entry(self, config: str):
if self.config[config]:
Expand Down Expand Up @@ -338,15 +338,20 @@ def save(self, fname: str):
if 'policy' not in new_val:
continue

# If new_val is a subset of old_val, skip it
# If new_val is a subset of old_val, skip it unless there are
# new notes that are different than the old ones.
old_val = tmp_a.config.get(conf)
if old_val and 'policy' in old_val:
try:
if old_val['policy'] == old_val['policy'] | new_val['policy']:
continue
can_skip = old_val['policy'] == old_val['policy'] | new_val['policy']
except TypeError:
if old_val['policy'] == {**old_val['policy'], **new_val['policy']}:
can_skip = old_val['policy'] == {**old_val['policy'], **new_val['policy']}
if can_skip:
if 'note' not in new_val:
continue
if 'note' in old_val and 'note' in new_val:
if old_val['note'] == new_val['note']:
continue

# Write out the policy (and note) line(s)
val = dict(sorted(new_val['policy'].items()))
Expand Down

0 comments on commit eda1e44

Please sign in to comment.