def __init__(self, observer, path, watch_type, flags, log): # XXX - WeakRef this observer (xpcom) #self.observer = observer try: self.__observer_weakref = WeakReference(observer) except COMException: # Not a supported xpcom object self.__observer_weakref = observer self.path = path self.uri = pathToUri(path) self.watch_type = watch_type self.flags = flags self.__recursive = (watch_type == WATCH_DIR_RECURSIVE) #log.debug("self.__recursive: %r", self.__recursive) self.log = log # Initialized: # 0 - Just been created # 1 - Cache has been initialized through initCache() # 2 - Now ready for first check against it's own cache # 3 - Own cache cleared. Ready for checking against a global cache # 4 - Observed path was deleted self.__initalized = 0 self.__statCache = {} self.__dirCache = {} self.__shutdown = False ##< Whether we have shut down and should suppress
def createUntitledDocument(self, language): leafName = self._untitledNameFromLanguage(language) # Just return the existing document for this name if there is one. doc = self.findDocumentByDisplayPath(leafName) if doc: return doc # Create a new document. encoding = self._getEncodingFromFilename(leafName) doc = components.classes["@activestate.com/koDocumentBase;1"]\ .createInstance(components.interfaces.koIDocument) doc.initUntitled(leafName, encoding) eolPref = self._globalPrefs.getStringPref("endOfLine") try: eol = eollib.eolPref2eol[eolPref] except KeyError: # Be paranoid: stay with system default if pref value is bogus. log.exception("unexpected 'endOfLine' pref value: %r", eolPref) eol = eollib.EOL_PLATFORM doc.new_line_endings = eol self._cDoc.acquire() try: self._documents[doc.displayPath] = WeakReference(doc) finally: self._cDoc.release() return doc
class koFileService(object): _com_interfaces_ = [ components.interfaces.koIFileService, components.interfaces.nsIObserver ] _reg_desc_ = "Komodo File Service Component" _reg_contractid_ = "@activestate.com/koFileService;1" _reg_clsid_ = "{32129770-2756-4496-A1DF-5218B1CE115F}" def __init__(self): self._files = {} self._tmpfiles = {} self._tmpdirs = {} self._uriParser = URIParser() self.obsSvc = components.classes[ "@mozilla.org/observer-service;1"].getService( components.interfaces.nsIObserverService) self.obsSvc.addObserver( WrapObject(self, components.interfaces.nsIObserver), "xpcom-shutdown", 0) @LazyClassAttribute def fileStatusSvc(self): return components.classes["@activestate.com/koFileStatusService;1"].\ getService(components.interfaces.koIFileStatusService) #koIFileEx getFileFromURI(in wstring URI); def getFileFromURI(self, uri): return self._getFileFromURI(uri) def _getFileFromURI(self, uri, doNotification=True): # first cleanup the uri by passing it through the parser try: self._uriParser.URI = uri uri = self._uriParser.URI kofile = self.findFileByURI(uri) if kofile: return kofile kofile = \ components.classes["@activestate.com/koFileEx;1"] \ .createInstance(components.interfaces.koIFileEx) kofile.URI = uri except Exception, e: log.error("Invalid URL parsed: %r", uri) raise ServerException(nsError.NS_ERROR_FAILURE, str(e)) self._files[uri] = WeakReference(kofile) if doNotification: forceRefresh = False self.fileStatusSvc.updateStatusForFiles([kofile], forceRefresh, None) return kofile
def createDocumentFromTemplateURI(self, uri, name, ext): log.info("creating document with URI: %s", uri) name = name or "Untitled" ext = ext or "" doc = components.classes["@activestate.com/koDocumentBase;1"]\ .createInstance(components.interfaces.koIDocument) title = "%s-%d%s" % (name, self._docCounterFromPrefix(name), ext) doc.initUntitled(title, self._getEncodingFromFilename(title)) doc.loadFromURI(uri) self._fixupEOL(doc) self._cDoc.acquire() try: self._documents[doc.displayPath] = WeakReference(doc) finally: self._cDoc.release() return doc
def createNewDocumentFromURI(self, uri): log.info("creating document with URI: %s", uri) file = self._fileSvc.getFileFromURI(uri) # We need to know the latest information about this file, so refresh # the file information. Don't do this for non-local files - bug 68285. if file.isLocal and not file.isNetworkFile: file.updateStats() doc = components.classes["@activestate.com/koDocumentBase;1"]\ .createInstance(components.interfaces.koIDocument) doc.initWithFile(file,0) self._cDoc.acquire() try: self._documents[doc.displayPath] = WeakReference(doc) finally: self._cDoc.release() return doc
def _addObserver(self, anObserver, aTopic, ownsWeak): wr_observers = self._topics.get(aTopic) if wr_observers is None: wr_observers = [] self._topics[aTopic] = wr_observers # Ignoring the ownsWeak argument, always try to create a # weakreference, see comments in bug 80145. try: try: # We prefer a Python weak reference, as sometimes our Python # code will only hold a Python (non XPCOM) reference to the # observer, and then the XPCOM weakreference will report the # observer as dead, even though it's still alive in the Python # world - bug 88013. anObserver = ref(UnwrapObject(anObserver)) except ValueError: # Not a Python object, use an XPCOM weakreference then. anObserver = WeakReference(anObserver) except COMException: pass wr_observers.append(anObserver)
def createNewDocumentFromURI(self, uri): log.info("creating document with URI: %s", uri) file = self._fileSvc.getFileFromURI(uri) # We need to know the latest information about this file, so refresh # the file information now. We use the hasChanged property, as this # has the side-effect of re-stat'ing. Psychotically, this is the only # way to initiate a re-stat. Don't do this for non-local files. # Fixes bug: # http://bugs.activestate.com/show_bug.cgi?id=68285 if file.isLocal and not file.isNetworkFile: file.hasChanged doc = components.classes["@activestate.com/koDocumentBase;1"]\ .createInstance(components.interfaces.koIDocument) doc.initWithFile(file, 0) self._cDoc.acquire() try: self._documents[doc.displayPath] = WeakReference(doc) finally: self._cDoc.release() return doc
def __init__(self, scimoz, silvercity_lexer): self.scimoz = WeakReference(scimoz) self.silvercity_lexer = silvercity_lexer
def __init__(self, doc, silvercity_lexer): self.doc = WeakReference(doc) self.silvercity_lexer = silvercity_lexer
def registerView(self, view): self._all_views_wr.add(WeakReference(view))
def registerView(self, view): self._all_views_wr_list.append(WeakReference(view))