diff --git a/acme-copy-certs/app/file_watcher.py b/acme-copy-certs/app/file_watcher.py index adf39aeffba7f9f419a9b8aa1030fec628c4d9fa..a8529f89ef0b46026ba99728e2612d426aa02a74 100644 --- a/acme-copy-certs/app/file_watcher.py +++ b/acme-copy-certs/app/file_watcher.py @@ -8,17 +8,27 @@ class FileWatcher: abs_path, file_name = os.path.split(os.path.abspath(file_path)) self.observed_path = abs_path self.observed_file = file_name + self.handler = handler - super(FileWatcher, self).__init__(patterns=[file_path], - ignore_patterns=[], ignore_directories=True) + self.event_handler = PatternMatchingEventHandler( + patterns=['*/' + file_name], + ignore_patterns=[], + ignore_directories=True) - def on_any_event(self, event): + self.event_handler.on_any_event = self._on_any_event + + self.observer.schedule(self.event_handler, + self.observed_path, + recursive=False) -if __name__ == "__main__": + def _on_any_event(self, event): + self.handler() - acme_file = sys.argv[1] if len(sys.argv) > 1 else 'acme.json' + def start(self): + print('Staring oberving file {0} in directory {1}'.format(self.observed_file, self.observed_path)) + self.observer.start() - u = acme.CertUpdater(acme_file, '.') + def stop(self): + self.observer.stop() + self.observer.join() - u.add('pica01-test.picasoft.net') - print('Updated certs: ', u.update())