From 053458b81ab166198e61b70790a5b5347ac3166e Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Thu, 1 Oct 2015 20:15:01 -0400 Subject: [PATCH] Minor scripting improvements and code cleaning. * Coding policy fixes in the scripting initialization code missed in my previous commit. * Remove redundant checks for valid Python library paths in kicadplugins.i. --- pcbnew/pcbnew.cpp | 12 ++++++------ scripting/kicadplugins.i | 11 +++++------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index cf3ab0f836..ebdbe066be 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -207,7 +207,7 @@ static bool scriptingSetup() #if defined( __MINGW32__ ) // force python environment under Windows: - const wxString python_us( "python27_us" ); + const wxString python_us( wxT( "python27_us" ) ); // Build our python path inside kicad wxString kipython = FindKicadFile( python_us + wxT( "/python.exe" ) ); @@ -281,21 +281,21 @@ static bool scriptingSetup() wxSetEnv( "PYTHONPATH", pypath ); #else - /* Linux-specific setup */ + // Linux-specific setup wxString pypath; pypath = Pgm().GetExecutablePath() + wxT( "../lib/python2.7/dist-packages" ); - if( !wxIsEmpty( wxGetenv("PYTHONPATH") ) ) - pypath = wxString( wxGetenv("PYTHONPATH") ) + wxT( ":" ) + pypath; + if( !wxIsEmpty( wxGetenv( wxT( "PYTHONPATH" ) ) ) + pypath = wxString( wxGetenv( wxT( "PYTHONPATH" ) ) ) + wxT( ":" ) + pypath; - wxSetEnv( "PYTHONPATH", pypath ); + wxSetEnv( wxT( "PYTHONPATH" ), pypath ); // Add this default search path: path_frag = Pgm().GetExecutablePath() + wxT( "../share/kicad/scripting/plugins" ); #endif - if( ! pcbnewInitPythonScripting( TO_UTF8( path_frag ) ) ) + if( !pcbnewInitPythonScripting( TO_UTF8( path_frag ) ) ) { wxLogError( wxT( "pcbnewInitPythonScripting() failed." ) ); return false; diff --git a/scripting/kicadplugins.i b/scripting/kicadplugins.i index 45118ab3e2..6f8aff4676 100644 --- a/scripting/kicadplugins.i +++ b/scripting/kicadplugins.i @@ -78,17 +78,17 @@ def ReloadPlugins(): ReloadPlugin(k) -def LoadPlugins( plugpath ): +def LoadPlugins(plugpath): import os import sys kicad_path = os.environ.get('KICAD_PATH') plugin_directories=[] - if plugpath and os.path.isdir( plugpath ): - plugin_directories.append( plugpath ) + if plugpath: + plugin_directories.append(plugpath) - if kicad_path and os.path.isdir(kicad_path): + if kicad_path: plugin_directories.append(os.path.join(kicad_path, 'scripting', 'plugins')) if sys.platform.startswith('linux'): @@ -97,8 +97,7 @@ def LoadPlugins( plugpath ): if sys.platform.startswith('darwin'): for singlepath in sys.path: - if os.path.isdir( os.path.join( singlepath, 'scripting', 'plugins') ): - plugin_directories.append( os.path.join( singlepath, 'scripting', 'plugins') ) + plugin_directories.append(os.path.join( singlepath, 'scripting', 'plugins')) for plugins_dir in plugin_directories: if not os.path.isdir(plugins_dir):