<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _build(self, name, **params):
 """ Rebuild operations by removing open modules that no longer need to be watched, and adding new modules if they are not currently being watched. This is done by comparing self.modules to watch_files.paths_open """

        log = self._getparam('log', self._discard, **params)

        #  Find all the modules that no longer need watching
        #
        rebuild = False
        wparams = params.copy()
        wparams['commit'] = False
        for path in list(self._watch.paths_open):
            if path in self.modules:
                continue
            try:
                self._watch.remove(path, **wparams)
                rebuild = True
            except Exception as e:
                log.warning("Remove of watched module %r failed -- %s", path, e)
            log.debug("Removed watch for path %r", path)

        #  Find all the modules that are new and should be watched
        #
        for path in list(self.modules):
            if path not in self._watch.paths_open:
                try:
                    self._watch.add(path, **wparams)
                    rebuild = True
                except Exception as e:
                    log.error("watch failed on module %r -- %s", path, e)
                    continue
        if rebuild:
            self._watch.commit(**params)