- self.wm.add_watch(path, mask, rec=True)
-
- def process_data(self, files):
- xml_files = [i for i in files if i.endswith('.xml')]
- for i in xml_files:
- for path in openerp.modules.module.ad_paths:
- if i.startswith(path):
- # find out wich addons path the file belongs to
- # and extract it's module name
- right = i[len(path) + 1:].split('/')
- if len(right) < 2:
- continue
- module = right[0]
- self.modules[module] = 1
- if self.modules:
- _logger.info('autoreload: xml change detected, autoreload activated')
- restart()
-
- def process_python(self, files):
- # process python changes
- py_files = [i for i in files if i.endswith('.py')]
- py_errors = []
- # TODO keep python errors until they are ok
- if py_files:
- for i in py_files:
- try:
- source = open(i, 'rb').read() + '\n'
- compile(source, i, 'exec')
- except SyntaxError:
- py_errors.append(i)
- if py_errors:
- _logger.info('autoreload: python code change detected, errors found')
- for i in py_errors:
- _logger.info('autoreload: SyntaxError %s', i)
- else:
- _logger.info('autoreload: python code updated, autoreload activated')
- restart()
-
- def check_thread(self):
- # Check if some files have been touched in the addons path.
- # If true, check if the touched file belongs to an installed module
- # in any of the database used in the registry manager.
- while 1:
- while self.notifier.check_events(1000):
- self.notifier.read_events()
- self.notifier.process_events()
- l = self.files.keys()
- self.files.clear()
- self.process_data(l)
- self.process_python(l)
+ self.observer.schedule(self, path, recursive=True)
+
+ def dispatch(self, event):
+ if isinstance(event, (FileCreatedEvent, FileModifiedEvent)):
+ if not event.is_directory:
+ path = event.src_path
+ if path.endswith('.py'):
+ try:
+ source = open(path, 'rb').read() + '\n'
+ compile(source, path, 'exec')
+ except SyntaxError:
+ _logger.error('autoreload: python code change detected, SyntaxError in %s', path)
+ else:
+ _logger.info('autoreload: python code updated, autoreload activated')
+ restart()