2014-12-26 11:36:43 +00:00
|
|
|
|
using System.Diagnostics;
|
2014-07-06 14:57:11 +00:00
|
|
|
|
using System.IO;
|
2014-12-26 11:36:43 +00:00
|
|
|
|
using System.Reflection;
|
2015-01-05 14:41:17 +00:00
|
|
|
|
using Wox.Core.UserSettings;
|
2014-01-29 10:33:24 +00:00
|
|
|
|
using Wox.Plugin;
|
2013-12-20 17:20:17 +00:00
|
|
|
|
|
2014-12-26 11:36:43 +00:00
|
|
|
|
namespace Wox.Core.Plugin
|
2013-12-20 17:20:17 +00:00
|
|
|
|
{
|
2014-12-26 11:36:43 +00:00
|
|
|
|
internal class PythonPlugin : JsonRPCPlugin
|
2013-12-20 17:20:17 +00:00
|
|
|
|
{
|
2014-12-26 11:36:43 +00:00
|
|
|
|
private static string woxDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
2014-07-18 12:00:55 +00:00
|
|
|
|
private ProcessStartInfo startInfo;
|
2013-12-20 17:20:17 +00:00
|
|
|
|
|
2014-07-09 15:44:57 +00:00
|
|
|
|
public override string SupportedLanguage
|
2013-12-20 17:20:17 +00:00
|
|
|
|
{
|
2014-07-09 15:44:57 +00:00
|
|
|
|
get { return AllowedLanguage.Python; }
|
2013-12-20 17:20:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-18 12:00:55 +00:00
|
|
|
|
public PythonPlugin()
|
|
|
|
|
|
{
|
|
|
|
|
|
startInfo = new ProcessStartInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
UseShellExecute = false,
|
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
|
RedirectStandardOutput = true,
|
|
|
|
|
|
RedirectStandardError = true
|
|
|
|
|
|
};
|
|
|
|
|
|
string additionalPythonPath = string.Format("{0};{1}",
|
|
|
|
|
|
Path.Combine(woxDirectory, "PythonHome\\DLLs"),
|
2014-07-18 15:12:50 +00:00
|
|
|
|
Path.Combine(woxDirectory, "PythonHome\\Lib\\site-packages"));
|
2014-07-18 12:00:55 +00:00
|
|
|
|
if (!startInfo.EnvironmentVariables.ContainsKey("PYTHONPATH"))
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
startInfo.EnvironmentVariables.Add("PYTHONPATH", additionalPythonPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
startInfo.EnvironmentVariables["PYTHONPATH"] = additionalPythonPath;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-07 15:05:06 +00:00
|
|
|
|
protected override string ExecuteQuery(Query query)
|
2014-01-10 16:19:14 +00:00
|
|
|
|
{
|
2014-07-18 12:00:55 +00:00
|
|
|
|
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
Method = "query",
|
|
|
|
|
|
Parameters = new object[] { query.GetAllRemainingParameter() },
|
|
|
|
|
|
HttpProxy = HttpProxy.Instance
|
|
|
|
|
|
};
|
|
|
|
|
|
//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
|
|
|
|
|
|
startInfo.FileName = Path.Combine(woxDirectory, "PythonHome\\pythonw.exe");
|
2014-08-14 13:07:56 +00:00
|
|
|
|
startInfo.Arguments = string.Format("-B \"{0}\" \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath, request);
|
2014-07-18 12:00:55 +00:00
|
|
|
|
|
|
|
|
|
|
return Execute(startInfo);
|
2014-02-09 12:55:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-12-26 11:36:43 +00:00
|
|
|
|
protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest)
|
2014-02-09 12:55:18 +00:00
|
|
|
|
{
|
2014-07-18 12:00:55 +00:00
|
|
|
|
startInfo.FileName = Path.Combine(woxDirectory, "PythonHome\\pythonw.exe");
|
2014-08-14 13:07:56 +00:00
|
|
|
|
startInfo.Arguments = string.Format("-B \"{0}\" \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath, rpcRequest);
|
2014-07-18 12:00:55 +00:00
|
|
|
|
return Execute(startInfo);
|
2013-12-20 17:20:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-07-07 15:05:06 +00:00
|
|
|
|
}
|