| 207 | logging.error(e) |
| 208 | |
| 209 | def load_path(self, km, p): |
| 210 | if os.path.exists(p) and os.path.isfile(p): |
| 211 | with open(p, encoding="utf8") as f: |
| 212 | try: |
| 213 | txt = f.read() |
| 214 | except UnicodeDecodeError as e: |
| 215 | raise KeyBindingError(f"Encoding error - expected UTF8: {p}: {e}") |
| 216 | try: |
| 217 | vals = self.parse(txt) |
| 218 | except KeyBindingError as e: |
| 219 | raise KeyBindingError(f"Error reading {p}: {e}") from e |
| 220 | for v in vals: |
| 221 | user_ctxs = v.get("ctx", ["global"]) |
| 222 | try: |
| 223 | km._check_contexts(user_ctxs) |
| 224 | km.remove(v["key"], user_ctxs) |
| 225 | km.add( |
| 226 | key=v["key"], |
| 227 | command=v["cmd"], |
| 228 | contexts=user_ctxs, |
| 229 | help=v.get("help", None), |
| 230 | ) |
| 231 | except ValueError as e: |
| 232 | raise KeyBindingError(f"Error reading {p}: {e}") from e |
| 233 | |
| 234 | def parse(self, text): |
| 235 | try: |