private string GenerateDbFile(IPythonInterpreterFactory interpreter, string moduleName, string extensionModuleFilename, List <string> existingModules, string dbFile, FileStream fs) { // we need to generate the DB file dbFile = Path.Combine(ReferencesDatabasePath, moduleName + ".$project.idb"); int retryCount = 0; while (File.Exists(dbFile)) { dbFile = Path.Combine(ReferencesDatabasePath, moduleName + "." + ++retryCount + ".$project.idb"); } using (var output = interpreter.Run( NodejsToolsInstallPath.GetFile("ExtensionScraper.py"), "scrape", "-", // do not use __import__ extensionModuleFilename, // extension module path Path.ChangeExtension(dbFile, null) // output file path (minus .idb) )) { if (_cancel.CanBeCanceled) { if (WaitHandle.WaitAny(new[] { _cancel.WaitHandle, output.WaitHandle }) != 1) { // we were cancelled return(null); } } else { output.Wait(); } if (output.ExitCode == 0) { // [FileName]|interpGuid|interpVersion|DateTimeStamp|[db_file.idb] // save the new entry in the DB file existingModules.Add( String.Format("{0}|{1}|{2}|{3}|{4}", extensionModuleFilename, interpreter.Id, interpreter.Configuration.Version, new FileInfo(extensionModuleFilename).LastWriteTime.ToString("O"), dbFile ) ); fs.Seek(0, SeekOrigin.Begin); fs.SetLength(0); using (var sw = new StreamWriter(fs)) { sw.Write(String.Join(Environment.NewLine, existingModules)); sw.Flush(); } } else { throw new CannotAnalyzeExtensionException(string.Join(Environment.NewLine, output.StandardErrorLines)); } } return(dbFile); }
public static string GetTemplateFile(string fileType) { string templateFileName = null; switch (fileType) { case NodejsConstants.JavaScript: templateFileName = "EmptyJs.js"; break; case NodejsConstants.TypeScript: templateFileName = "EmptyTs.ts"; break; case NodejsConstants.HTML: templateFileName = "EmptyHTML.html"; break; case NodejsConstants.CSS: templateFileName = "EmptyCSS.css"; break; } if (templateFileName == null) { Debug.Fail(String.Format("Invalid file type: {0}", fileType)); } return(NodejsToolsInstallPath.GetFile("FileTemplates\\NewItem\\" + templateFileName)); }
public static async Task <int> GenerateAsync(PythonTypeDatabaseCreationRequest request) { var fact = request.Factory; var evt = request.OnExit; if (fact == null || !Directory.Exists(fact.Configuration.LibraryPath)) { if (evt != null) { evt(NotSupportedExitCode); } return(NotSupportedExitCode); } var outPath = request.OutputPath; var analyzerPath = NodejsToolsInstallPath.GetFile("Microsoft.NodejsTools.Analyzer.exe"); Directory.CreateDirectory(CompletionDatabasePath); var baseDb = BaselineDatabasePath; if (request.ExtraInputDatabases.Any()) { baseDb = baseDb + ";" + string.Join(";", request.ExtraInputDatabases); } var logPath = Path.Combine(outPath, "AnalysisLog.txt"); var glogPath = Path.Combine(CompletionDatabasePath, "AnalysisLog.txt"); using (var output = ProcessOutput.RunHiddenAndCapture( analyzerPath, "/id", fact.Id.ToString("B"), "/version", fact.Configuration.Version.ToString(), "/python", fact.Configuration.InterpreterPath, "/library", fact.Configuration.LibraryPath, "/outdir", outPath, "/basedb", baseDb, (request.SkipUnchanged ? null : "/all"), // null will be filtered out; empty strings are quoted "/log", logPath, "/glog", glogPath, "/wait", (request.WaitFor != null ? AnalyzerStatusUpdater.GetIdentifier(request.WaitFor) : "") )) { output.PriorityClass = ProcessPriorityClass.BelowNormal; int exitCode = await output; if (exitCode > -10 && exitCode < 0) { try { File.AppendAllLines( glogPath, new[] { string.Format("FAIL_STDLIB: ({0}) {1}", exitCode, output.Arguments) } .Concat(output.StandardErrorLines) ); } catch (IOException) { } catch (ArgumentException) { } catch (SecurityException) { } catch (UnauthorizedAccessException) { } } if (evt != null) { evt(exitCode); } return(exitCode); } }