Watch a directory with a specific glob. If the directory doesn't yet exist, attempt to watch the parent directory and amend the patterns to include this. It's important this method isn't called more than one per directory when updating all subscriptions. Subsequent c
(self, directory, patterns)
| 528 | self._subscribe(directory, "%s:%s" % (prefix, directory), expression) |
| 529 | |
| 530 | def _watch_glob(self, directory, patterns): |
| 531 | """ |
| 532 | Watch a directory with a specific glob. If the directory doesn't yet |
| 533 | exist, attempt to watch the parent directory and amend the patterns to |
| 534 | include this. It's important this method isn't called more than one per |
| 535 | directory when updating all subscriptions. Subsequent calls will |
| 536 | overwrite the named subscription, so it must include all possible glob |
| 537 | expressions. |
| 538 | """ |
| 539 | prefix = "glob" |
| 540 | if not directory.exists(): |
| 541 | if not directory.parent.exists(): |
| 542 | logger.warning( |
| 543 | "Unable to watch directory %s as neither it or its parent exist.", |
| 544 | directory, |
| 545 | ) |
| 546 | return |
| 547 | prefix = "glob-parent-%s" % directory.name |
| 548 | patterns = ["%s/%s" % (directory.name, pattern) for pattern in patterns] |
| 549 | directory = directory.parent |
| 550 | |
| 551 | expression = ["anyof"] |
| 552 | for pattern in patterns: |
| 553 | expression.append(["match", pattern, "wholename"]) |
| 554 | self._subscribe(directory, "%s:%s" % (prefix, directory), expression) |
| 555 | |
| 556 | def watched_roots(self, watched_files): |
| 557 | extra_directories = self.directory_globs.keys() |