diff --git a/frontends/src/tools/misc.py b/frontends/src/tools/misc.py index 775867b1..406bf5d2 100644 --- a/frontends/src/tools/misc.py +++ b/frontends/src/tools/misc.py @@ -60,3 +60,31 @@ class InputHistory(object): if callback is not None: callback(self.input_history_tmp[index_tmp]) self.input_history_index = index_tmp + + +class FlagsHandler(object): + """Small class to handle easily option flags + + the instance is initialized with an iterable + then attribute return True if flag is set, False else. + WARNING: If a flag is checked, it is removed (i.e. unset) + this is done to use bool(flags_handler) to check if all flags + have been used + """ + + def __init__(self, flags): + self.flags = set(flags or []) + + def __getattr__(self, flag): + try: + self.flags.remove(flag) + except KeyError: + return False + else: + return True + + def __len__(self): + return len(self.flags) + + def __iter__(self): + return self.flags.__iter__()