def __init__(self, waitables, paths, translationPaths = None): self.on_file_reloaded = signals.Signal() self.on_file_reload_failed = signals.Signal() self.runningCheckAt = 0 self.startedAt = int(time.time()) self.processed = {} self.waitables = waitables self.translationPaths = translationPaths or [] if isinstance(paths, basestring): paths = [paths] self.handles = {} paths = map(os.path.abspath, paths) commonprefix = os.path.commonprefix(paths) if commonprefix: paths = [commonprefix] for path in paths: if not os.path.exists(path): log.warn("SpyFolder: Can't spy on non-existing folder %s" % path) continue handle = win32api.FindFirstChangeNotification(path, True, win32api.FILE_NOTIFY_CHANGE_LAST_WRITE) if handle == win32api.INVALID_HANDLE_VALUE: log.warn('SpyFolder: got invalid handle for %s' % path) continue waitables.InsertHandle(handle, self) self.handles[handle] = path log.info('AutoCompiler: Now spying on %s using handle %s.', path, handle)
def RefreshEvent(self): self.hwnd = self.doc.GetFirstView().GetSafeHwnd() if self.watchEvent is not None: win32api.FindCloseChangeNotification(self.watchEvent) self.watchEvent = None path = self.doc.GetPathName() if path: path = os.path.dirname(path) if path: filter = win32con.FILE_NOTIFY_CHANGE_FILE_NAME | \ win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES | \ win32con.FILE_NOTIFY_CHANGE_LAST_WRITE try: self.watchEvent = win32api.FindFirstChangeNotification(path, 0, filter) except win32api.error, exc: print "Can not watch file", path, "for changes -", exc.strerror
def wfc(self, *args, **kwargs): #wait for change subpath = self._get_subpath(args) if settings.debug: print "wfc:", subpath f = os.path.abspath(os.path.join(get_base_dir(), subpath)) parent = os.path.dirname(f) timeout = kwargs.has_key("timeout") and int(kwargs["timeout"]) or 60000 try: print "watching", f handle = win32api.FindFirstChangeNotification(parent, 0, 0x010) ret = win32event.WaitForSingleObject(handle, int(timeout)) if ret is win32event.WAIT_TIMEOUT: raise cherrypy.HTTPError(304) time.sleep(0.2) return self.default_dispatcher(None, args, **kwargs) except pywintypes.error as e: #@UndefinedVariable print e[2] raise cherrypy.HTTPError(500) finally: if handle: win32api.FindCloseChangeNotification(handle)