2016-05-05 08:57:03 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
2016-06-22 07:42:24 +08:00
|
|
|
|
using System.IO;
|
|
|
|
|
using Wox.Infrastructure;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
using Wox.Plugin;
|
2013-12-21 01:20:17 +08:00
|
|
|
|
|
2014-12-26 19:36:43 +08:00
|
|
|
|
namespace Wox.Core.Plugin
|
2013-12-21 01:20:17 +08:00
|
|
|
|
{
|
2014-12-26 19:36:43 +08:00
|
|
|
|
internal class PythonPlugin : JsonRPCPlugin
|
2013-12-21 01:20:17 +08:00
|
|
|
|
{
|
2016-01-08 09:55:24 +08:00
|
|
|
|
private readonly ProcessStartInfo _startInfo;
|
2016-05-05 08:57:03 +08:00
|
|
|
|
public override string SupportedLanguage { get; set; } = AllowedLanguage.Python;
|
2013-12-21 01:20:17 +08:00
|
|
|
|
|
2016-05-05 08:57:03 +08:00
|
|
|
|
public PythonPlugin(string filename)
|
2014-07-18 20:00:55 +08:00
|
|
|
|
{
|
2016-01-08 09:55:24 +08:00
|
|
|
|
_startInfo = new ProcessStartInfo
|
|
|
|
|
{
|
2016-05-05 19:30:23 +08:00
|
|
|
|
FileName = filename,
|
2016-01-08 09:55:24 +08:00
|
|
|
|
UseShellExecute = false,
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
RedirectStandardOutput = true,
|
2016-06-22 07:42:24 +08:00
|
|
|
|
RedirectStandardError = true,
|
2016-01-08 09:55:24 +08:00
|
|
|
|
};
|
2016-06-22 07:42:24 +08:00
|
|
|
|
|
|
|
|
|
// temp fix for issue #667
|
|
|
|
|
var path = Path.Combine(Constant.ProgramDirectory, JsonRPC);
|
|
|
|
|
_startInfo.EnvironmentVariables["PYTHONPATH"] = path;
|
|
|
|
|
|
2014-07-18 20:00:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 23:05:06 +08:00
|
|
|
|
protected override string ExecuteQuery(Query query)
|
2014-01-11 00:19:14 +08:00
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
|
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel
|
|
|
|
|
{
|
2016-01-08 09:55:24 +08:00
|
|
|
|
Method = "query",
|
2016-05-05 08:57:03 +08:00
|
|
|
|
Parameters = new object[] { query.Search },
|
2016-01-08 09:55:24 +08:00
|
|
|
|
};
|
2014-07-18 20:00:55 +08:00
|
|
|
|
//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
|
2016-01-08 09:55:24 +08:00
|
|
|
|
_startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{request}\"";
|
2016-06-22 07:42:24 +08:00
|
|
|
|
// todo happlebao why context can't be used in constructor
|
|
|
|
|
_startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory;
|
2014-07-18 20:00:55 +08:00
|
|
|
|
|
2016-01-08 09:55:24 +08:00
|
|
|
|
return Execute(_startInfo);
|
2014-02-09 20:55:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-26 19:36:43 +08:00
|
|
|
|
protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest)
|
2014-02-09 20:55:18 +08:00
|
|
|
|
{
|
2016-01-08 09:55:24 +08:00
|
|
|
|
_startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{rpcRequest}\"";
|
2016-06-22 07:42:24 +08:00
|
|
|
|
_startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory;
|
2016-01-08 09:55:24 +08:00
|
|
|
|
return Execute(_startInfo);
|
2013-12-21 01:20:17 +08:00
|
|
|
|
}
|
2017-04-11 21:34:04 +08:00
|
|
|
|
|
|
|
|
|
protected override string ExecuteContextMenu(Result selectedResult) {
|
|
|
|
|
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel {
|
|
|
|
|
Method = "context_menu",
|
|
|
|
|
Parameters = new object[] { selectedResult.ContextData },
|
|
|
|
|
};
|
|
|
|
|
_startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{request}\"";
|
|
|
|
|
_startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory;
|
|
|
|
|
|
|
|
|
|
return Execute(_startInfo);
|
|
|
|
|
}
|
2013-12-21 01:20:17 +08:00
|
|
|
|
}
|
2014-07-07 23:05:06 +08:00
|
|
|
|
}
|