def get_version(self): path = self.get_executablePath() if not path: raise ServerException(nsError.NS_ERROR_FILE_NOT_FOUND, "Can't find executable for %s" % (getattr(self, "exenames", ["?"])[0],)) return self.getVersionForBinary(path)
def do_getHomeDirectory(self): raise ServerException(nsError.NS_ERROR_NOT_IMPLEMENTED)
def do_removeDirectory(self, name): raise ServerException(nsError.NS_ERROR_NOT_IMPLEMENTED)
def do_verifyConnected(self): raise ServerException(nsError.NS_ERROR_NOT_IMPLEMENTED)
def do_rename(self, oldName, newName): raise ServerException(nsError.NS_ERROR_NOT_IMPLEMENTED)
def lint_with_text(self, request, text): encoding_name = request.encoding.python_encoding_name cwd = request.cwd prefset = request.prefset prefName = "lint_%s_with_standard_python" % self.language_name_lc if not prefset.getBooleanPref(prefName): return try: # Get the Python interpreter (prefs or first valid one on the path). interpreter_pref_name = "%sDefaultInterpreter" % ( self.language_name_lc, ) python = prefset.getString(interpreter_pref_name) if not python: python = self._pythonInfo.executablePath if not python: return if not self._pythonInfo.isSupportedBinary(python): raise ServerException( nsError.NS_ERROR_FAILURE, "Invalid %r executable: %r" % (self.language_name, python)) # Determine the pycompile settings. if self.language_name == "Python3": compilePy = os.path.join(self._koDirSvc.supportDir, "python", "py3compile.py") if encoding_name not in self._simple_python3_string_encodings: # First, make sure the text is Unicode if type(text) == self._stringType: text = text.decode(encoding_name) # Now save it as utf-8 -- python3 knows how to read utf-8 text = text.encode("utf-8") else: compilePy = os.path.join(self._koDirSvc.supportDir, "python", "pycompile.py") if request.koDoc.displayPath.startswith("macro2://"): text = projectUtils.wrapPythonMacro(text) leadingWS = _leading_ws_re.match(text.splitlines()[1]).group(1) else: leadingWS = None # Save the current buffer to a temporary file. cwd = cwd or None # Standard Python syntax-checking files can live in a tmp directory # because the checker doesn't attempt to verify or read imported # modules. fout, tmpFileName = _localTmpFileName() fout.write(text) fout.close() results = koLintResults() try: argv = [python, '-u', compilePy, tmpFileName] #print "---- check syntax of the following with %r" % argv #sys.stdout.write(text) #print "-"*70 env = self._get_fixed_env(prefset) if sys.platform.startswith("win") and cwd is not None\ and cwd.startswith("\\\\"): # Don't try to switch to a UNC path because pycompile.py # ends up spitting out: # CMD.EXE was started with '\\netshare\apps\Komodo\stuff' as the current directory # path. UNC paths are not supported. Defaulting to Windows directory. # XXX Could perhaps try to ensure that command is not # run via "cmd.exe /c", but don't know if that would # help either. cwd = None p = process.ProcessOpen(argv, cwd=cwd, env=env, stdin=None) output, error = p.communicate() retval = p.returncode #print "-"*60, "env" #pprint(env) #print "-"*60, "output" #print output #print "-"*60, "error" #print error #print "-"*70 if retval: errmsg = "Error checking syntax: retval=%s, stderr=%s"\ % (retval, error) log.exception(errmsg) raise ServerException(nsError.NS_ERROR_UNEXPECTED, errmsg) else: # Parse syntax errors in the output. dicts = eval(output) for d in dicts: results.addResult(self._buildResult(d, leadingWS)) # Parse warnings in the error. results.addResults( self._parseWarnings(error, text, leadingWS)) finally: os.unlink(tmpFileName) except ServerException: log.exception("ServerException") raise except: # non-ServerException's are unexpected internal errors log.exception("unexpected internal error") raise return results
def do_authenticateWithAgent(self): raise ServerException(nsError.NS_ERROR_NOT_IMPLEMENTED)
def get_classID(self): if self.classID is None: raise ServerException(nsError.NS_ERROR_NOT_IMPLEMENTED, "Class '%r' has no class ID" % (self.klass,)) return self.classID
def set_data(self, val): raise ServerException(nsError.NS_ERROR_NOT_IMPLEMENTED)
def chmod(self, permissions): raise ServerException(nsError.NS_ERROR_NOT_AVAILABLE)
def setUsedWindowNum(self, val): if val in self._usedWindowNums: raise ServerException(nsError.NS_ERROR_FAILURE, "setUsedWindowNum: %d already in use" % val) self._usedWindowNums.add(val)
def write(self, text): try: self._file.write(text) except EnvironmentError, ex: self.lastErrorSvc.setLastError(ex.errno, ex.strerror) raise ServerException(nsError.NS_ERROR_FAILURE, ex.strerror)
class FileHandlerBase(object): isNetworkFile = False @LazyClassAttribute def lastErrorSvc(self): return components.classes["@activestate.com/koLastErrorService;1"].\ getService(components.interfaces.koILastErrorService) def __init__(self): self.clearstat() self._file = None self._path = None self._mode = 'rb' # lastAccessedTime is special, in that it can change # but we don't care if it does. It's only used in ko # for display purposes. If we keep this in the stat # cache for this file, it makes checking disk changes # more difficult, so instead, we store it seperately # see get_hasChanged below self.lastAccessedTime = 0 def get_stats(self): return self._stats stats = property(get_stats) def clearstat(self): self._stats = {} def __getattr__(self, name): if name in self.stats: return self.stats[name] if self._file is None or not hasattr(self._file, name): raise AttributeError, name return getattr(self._file, name) def getStatusMap(self): status = self.stats.copy() keys = map(str, status.keys()) values = map(str, status.values()) return keys, values def read(self, nBytes): try: if nBytes >= 0xFFFFFFFF: # XXX - Hack around the fact that the read nBytes is # marked as an unsigned int in the IDL, but some # parts of the code use read(-1), which makes a # really large unsigned int, causing exceptions! # http://bugs.activestate.com/show_bug.cgi?id=72912 return self._file.read(-1) else: return self._file.read(nBytes) except EnvironmentError, ex: self.lastErrorSvc.setLastError(ex.errno, ex.strerror) raise ServerException(nsError.NS_ERROR_FAILURE, ex.strerror) except COMException: # Last error should already be set in this case raise ServerException(nsError.NS_ERROR_FAILURE)
except EnvironmentError, ex: self.lastErrorSvc.setLastError(ex.errno, ex.strerror) raise ServerException(nsError.NS_ERROR_FAILURE, ex.strerror) except COMException: # Last error should already be set in this case raise ServerException(nsError.NS_ERROR_FAILURE) def write(self, text): try: self._file.write(text) except EnvironmentError, ex: self.lastErrorSvc.setLastError(ex.errno, ex.strerror) raise ServerException(nsError.NS_ERROR_FAILURE, ex.strerror) except COMException: # Last error should already be set in this case raise ServerException(nsError.NS_ERROR_FAILURE) def chmod(self, permissions): raise ServerException(nsError.NS_ERROR_NOT_AVAILABLE) class FileHandler(FileHandlerBase): isLocal = 1 isRemoteFile = 0 _networkFile = None def __init__(self, path): FileHandlerBase.__init__(self) uri = URIParser(path) if uri.scheme != 'file': raise URILibError("Invalid File Scheme: %s" % uri.scheme)
def importFileWithNewName(self, parentPath, srcPath, destPath): try: self.toolboxLoader.importFileWithNewName(parentPath, srcPath, destPath) self._notifyToolboxChanged(parentPath) except Exception, ex: raise ServerException(nsError.NS_ERROR_ILLEGAL_VALUE, ex)
class koActionScriptLinter: _com_interfaces_ = [components.interfaces.koILinter] _reg_desc_ = "Komodo ActionScript MTASC Linter" _reg_clsid_ = "{50bc6a5c-950f-4b94-8d5a-194524d41f85}" _reg_contractid_ = "@activestate.com/koLinter?language=ActionScript;1" _reg_categories_ = [ ("category-komodo-linter", 'ActionScript'), ("komodo-linter", "ActionScript MTASC Linter"), ] def __init__(self): log.debug("Created the ActionScript Linter object") # Copied and pasted from KoPerlCompileLinter self.sysUtils = components.classes["@activestate.com/koSysUtils;1"].\ getService(components.interfaces.koISysUtils) self.infoSvc = components.classes["@activestate.com/koInfoService;1"].\ getService() self._lastErrorSvc = components.classes["@activestate.com/koLastErrorService;1"].\ getService(components.interfaces.koILastErrorService) self._koVer = self.infoSvc.version def _getInterpreter(self, prefset): if prefset.hasStringPref("actionScriptDefaultInterpreter") and\ prefset.getStringPref("actionScriptDefaultInterpreter"): return prefset.getStringPref("actionScriptDefaultInterpreter") return None def lint(self, request): text = request.content.encode(request.encoding.python_encoding_name) prefset = request.koDoc.getEffectivePrefs() ascExe = self._getInterpreter(prefset) if ascExe is None: lintResults = koLintResults() lr = KoLintResult() lr.description = "Can't find an ActionScript interpreter" lr.lineStart = lr.lineEnd = 1 lr.columnStart = 1 lr.columnEnd = 1 + len(text.splitlines()[0]) lr.severity = KoLintResult.SEV_WARNING lintResults.addResult(lr) log.debug('no interpreter') return lintResults tmpFileName = None cwd = request.cwd if cwd: tmpFileName = os.path.join( cwd, "tmp_ko_aslint_ko%s.as" % (self._koVer.replace(".", "_").replace("-", "_"))) try: fout = open(tmpFileName, 'wb') fout.write(text) fout.close() except (OSError, IOError), ex: tmpFileName = None if not tmpFileName: # Fallback to using a tmp dir if cannot write in cwd. try: tmpFileName = tempfile.mktemp() cwd = os.path.dirname(tmpFileName) except OSError, ex: # Sometimes get this error but don't know why: # OSError: [Errno 13] Permission denied: 'C:\\DOCUME~1\\trentm\\LOCALS~1\\Temp\\~1324-test' errmsg = "error determining temporary filename for "\ "ActionScript content: %s" % ex self._lastErrorSvc.setLastError(3, errmsg) raise ServerException(nsError.NS_ERROR_UNEXPECTED) fout = open(tmpFileName, 'wb') fout.write(text) fout.close()
def importV5Package(self, parentPath, kpzPath): try: self.importV5Package_aux(parentPath, kpzPath) self._notifyToolboxChanged(parentPath) except Exception, ex: raise ServerException(nsError.NS_ERROR_ILLEGAL_VALUE, ex)
def filePosFromDiffPos(self, line, column): try: return self.diffex.file_pos_from_diff_pos(line, column) except difflibex.DiffLibExError, ex: self.lastErrorSvc.setLastError(0, str(ex)) raise ServerException(nsError.NS_ERROR_UNEXPECTED, str(ex))
def newChannel(self, aURI): raise ServerException(nsError.NS_ERROR_NOT_IMPLEMENTED)
def inferCwdAndStripFromPath(self, pathInDiff, actualPath): try: return difflibex.infer_cwd_and_strip_from_path(pathInDiff, actualPath) except difflibex.DiffLibExError, ex: raise ServerException(nsError.NS_ERROR_UNEXPECTED, str(ex))
def do_openSocket(self): raise ServerException(nsError.NS_ERROR_NOT_IMPLEMENTED)
def set_path(self, val): raise ServerException(nsError.NS_ERROR_ILLEGAL_VALUE, ("can't call setpath on %s %s (id %r)" % (self.get_type(), self.typeName, self.id)))
def do_getDirectoryList(self, path, dir_rfinfo): raise ServerException(nsError.NS_ERROR_NOT_IMPLEMENTED)
def save(self): raise ServerException( nsError.NS_ERROR_ILLEGAL_VALUE, ("save not yet implemented for %s" % self.get_type()))
def do_changeDirectory(self, path): raise ServerException(nsError.NS_ERROR_NOT_IMPLEMENTED)
def importDirectory(self, parentPath, pathToImport): try: self.toolboxLoader.importDirectory(parentPath, pathToImport) self._notifyToolboxChanged(parentPath) except Exception, ex: raise ServerException(nsError.NS_ERROR_ILLEGAL_VALUE, ex)
def do_getParentPath(self, path): raise ServerException(nsError.NS_ERROR_NOT_IMPLEMENTED)
def importFiles(self, parentPath, toolPaths): try: self.toolboxLoader.importFiles(parentPath, toolPaths) self._notifyToolboxChanged(parentPath) except Exception, ex: raise ServerException(nsError.NS_ERROR_ILLEGAL_VALUE, ex)
def do_createDirectory(self, name, permissions): raise ServerException(nsError.NS_ERROR_NOT_IMPLEMENTED)
def get_webHelpURL(self): raise ServerException(nsError.NS_ERROR_NOT_IMPLEMENTED)