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( PythonToolsInstallPath.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); }
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( PythonToolsInstallPath.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; }