From 21277aff15db8db5130d46ae9605e3c10c740eb6 Mon Sep 17 00:00:00 2001 From: Jamie Hardt Date: Sun, 7 Jul 2024 13:42:24 -0700 Subject: [PATCH] Improved reset/key unset logic Patterns and incrs are now unset as well --- mfbatch/commands.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mfbatch/commands.py b/mfbatch/commands.py index 353b857..144a7da 100644 --- a/mfbatch/commands.py +++ b/mfbatch/commands.py @@ -63,6 +63,23 @@ class CommandEnv: self.incr.pop(k, None) self.patterns.pop(k, None) + + # delete all patterns that refer to the key + refs = [] + for pattern_key, (frm, _, _) in self.patterns: + if frm == k: + refs.append(pattern_key) + + for ref in refs: + del self.patterns[ref] + + + def reset_keys(self): + all_keys = list(self.metadatums.keys()) + + for key in all_keys: + self.unset_key(key) + def set_pattern(self, to: str, frm: str, pattern: str, repl: str): """