Temp fix for #667 by add wox.py to PYTHONPATH

This commit is contained in:
bao-qian
2016-06-22 00:42:24 +01:00
parent 4b31f40026
commit a8869c46b8
7 changed files with 35 additions and 115 deletions

View File

@@ -1,107 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import json
import sys
import inspect
class Wox(object):
"""
Wox python plugin base
"""
def __init__(self):
rpc_request = json.loads(sys.argv[1])
self.proxy = rpc_request.get("proxy",{})
request_method_name = rpc_request.get("method")
request_parameters = rpc_request.get("parameters")
methods = inspect.getmembers(self, predicate=inspect.ismethod)
request_method = dict(methods)[request_method_name]
results = request_method(*request_parameters)
if request_method_name == "query":
print(json.dumps({"result": results}))
def query(self,query):
"""
sub class need to override this method
"""
return []
def debug(self,msg):
"""
alert msg
"""
print("DEBUG:{}".format(msg))
sys.exit()
class WoxAPI(object):
@classmethod
def change_query(cls,query,requery = False):
"""
change wox query
"""
print(json.dumps({"method": "Wox.ChangeQuery","parameters":[query,requery]}))
@classmethod
def shell_run(cls,cmd):
"""
run shell commands
"""
print(json.dumps({"method": "Wox.ShellRun","parameters":[cmd]}))
@classmethod
def close_app(cls):
"""
close wox
"""
print(json.dumps({"method": "Wox.CloseApp","parameters":[]}))
@classmethod
def hide_app(cls):
"""
hide wox
"""
print(json.dumps({"method": "Wox.HideApp","parameters":[]}))
@classmethod
def show_app(cls):
"""
show wox
"""
print(json.dumps({"method": "Wox.ShowApp","parameters":[]}))
@classmethod
def show_msg(cls,title,sub_title,ico_path=""):
"""
show messagebox
"""
print(json.dumps({"method": "Wox.ShowMsg","parameters":[title,sub_title,ico_path]}))
@classmethod
def open_setting_dialog(cls):
"""
open setting dialog
"""
print(json.dumps({"method": "Wox.OpenSettingDialog","parameters":[]}))
@classmethod
def start_loadingbar(cls):
"""
start loading animation in wox
"""
print(json.dumps({"method": "Wox.StartLoadingBar","parameters":[]}))
@classmethod
def stop_loadingbar(cls):
"""
stop loading animation in wox
"""
print(json.dumps({"method": "Wox.StopLoadingBar","parameters":[]}))
@classmethod
def reload_plugins(cls):
"""
reload all wox plugins
"""
print(json.dumps({"method": "Wox.ReloadPlugins","parameters":[]}))

View File

@@ -20,6 +20,7 @@ namespace Wox.Core.Plugin
internal abstract class JsonRPCPlugin : IPlugin internal abstract class JsonRPCPlugin : IPlugin
{ {
protected PluginInitContext context; protected PluginInitContext context;
public const string JsonRPC = "JsonRPC";
/// <summary> /// <summary>
/// The language this JsonRPCPlugin support /// The language this JsonRPCPlugin support

View File

@@ -34,7 +34,7 @@ namespace Wox.Core.Plugin
return; return;
} }
string pluginFolerPath = Infrastructure.Constant.UserDirectory; string pluginFolerPath = Infrastructure.Constant.PluginsDirectory;
string newPluginName = plugin.Name string newPluginName = plugin.Name
.Replace("/", "_") .Replace("/", "_")

View File

@@ -33,13 +33,27 @@ namespace Wox.Core.Plugin
// todo happlebao, this should not be public, the indicator function should be embeded // todo happlebao, this should not be public, the indicator function should be embeded
public static PluginsSettings Settings; public static PluginsSettings Settings;
private static List<PluginMetadata> _metadatas; private static List<PluginMetadata> _metadatas;
private static readonly string[] Directories = { Constant.PreinstalledDirectory, Constant.UserDirectory }; private static readonly string[] Directories = { Constant.PreinstalledDirectory, Constant.PluginsDirectory };
private static void ValidateUserDirectory() private static void ValidateUserDirectory()
{ {
if (!Directory.Exists(Constant.UserDirectory)) if (!Directory.Exists(Constant.PluginsDirectory))
{ {
Directory.CreateDirectory(Constant.UserDirectory); Directory.CreateDirectory(Constant.PluginsDirectory);
}
}
private static void DeletePythonBinding()
{
const string binding = "wox.py";
var directory = Constant.PluginsDirectory;
foreach (var subDirectory in Directory.GetDirectories(directory))
{
var path = Path.Combine(subDirectory, binding);
if (File.Exists(path))
{
File.Delete(path);
}
} }
} }
@@ -55,7 +69,8 @@ namespace Wox.Core.Plugin
static PluginManager() static PluginManager()
{ {
ValidateUserDirectory(); ValidateUserDirectory();
// force old plugins use new python binding
DeletePythonBinding();
} }
/// <summary> /// <summary>

View File

@@ -1,5 +1,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using Wox.Infrastructure;
using Wox.Plugin; using Wox.Plugin;
namespace Wox.Core.Plugin namespace Wox.Core.Plugin
@@ -17,8 +19,13 @@ namespace Wox.Core.Plugin
UseShellExecute = false, UseShellExecute = false,
CreateNoWindow = true, CreateNoWindow = true,
RedirectStandardOutput = true, RedirectStandardOutput = true,
RedirectStandardError = true RedirectStandardError = true,
}; };
// temp fix for issue #667
var path = Path.Combine(Constant.ProgramDirectory, JsonRPC);
_startInfo.EnvironmentVariables["PYTHONPATH"] = path;
} }
protected override string ExecuteQuery(Query query) protected override string ExecuteQuery(Query query)
@@ -30,6 +37,8 @@ namespace Wox.Core.Plugin
}; };
//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable //Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
_startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{request}\""; _startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{request}\"";
// todo happlebao why context can't be used in constructor
_startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory;
return Execute(_startInfo); return Execute(_startInfo);
} }
@@ -37,6 +46,7 @@ namespace Wox.Core.Plugin
protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest) protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest)
{ {
_startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{rpcRequest}\""; _startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{rpcRequest}\"";
_startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory;
return Execute(_startInfo); return Execute(_startInfo);
} }
} }

View File

@@ -15,7 +15,7 @@ namespace Wox.Infrastructure
public static readonly string ProgramDirectory = Directory.GetParent(Assembly.Location).ToString(); public static readonly string ProgramDirectory = Directory.GetParent(Assembly.Location).ToString();
public static readonly string ExecutablePath = Path.Combine(ProgramDirectory, Wox + ".exe"); public static readonly string ExecutablePath = Path.Combine(ProgramDirectory, Wox + ".exe");
public static readonly string DataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Wox); public static readonly string DataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Wox);
public static readonly string UserDirectory = Path.Combine(DataDirectory, Plugins); public static readonly string PluginsDirectory = Path.Combine(DataDirectory, Plugins);
public static readonly string PreinstalledDirectory = Path.Combine(ProgramDirectory, Plugins); public static readonly string PreinstalledDirectory = Path.Combine(ProgramDirectory, Plugins);
public static readonly string SettingsPath = Path.Combine(DataDirectory, Settings); public static readonly string SettingsPath = Path.Combine(DataDirectory, Settings);
public const string Github = "https://github.com/Wox-launcher/Wox"; public const string Github = "https://github.com/Wox-launcher/Wox";

View File

@@ -422,9 +422,10 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent> <PostBuildEvent>
xcopy /Y $(ProjectDir)Themes\* $(TargetDir)Themes\ xcopy /Y /E $(ProjectDir)Themes\* $(TargetDir)Themes\
xcopy /Y /E $(ProjectDir)Images\* $(TargetDir)Images\ xcopy /Y /E $(ProjectDir)Images\* $(TargetDir)Images\
xcopy /Y /D /E $(SolutionDir)Plugins\HelloWorldPython\* $(TargetDir)Plugins\HelloWorldPython\* xcopy /Y /D /E $(SolutionDir)Plugins\HelloWorldPython\* $(TargetDir)Plugins\HelloWorldPython\*
xcopy /Y /E $(SolutionDir)JsonRPC\* $(TargetDir)JsonRPC\
cd $(SolutionDir)packages\squirrel*\tools cd $(SolutionDir)packages\squirrel*\tools
copy /Y Squirrel.exe $(TargetDir)..\Update.exe copy /Y Squirrel.exe $(TargetDir)..\Update.exe