From 2807a37fc0f63763e1483746120601e5f4530cfd Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Fri, 22 Jan 2021 23:27:39 -0500 Subject: [PATCH] Create a stock scripting path helper --- common/paths.cpp | 26 ++++++++++++++++++++++++++ include/paths.h | 1 + pcbnew/swig/python_scripting.cpp | 17 +---------------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/common/paths.cpp b/common/paths.cpp index 050978dc18..120ea9384d 100644 --- a/common/paths.cpp +++ b/common/paths.cpp @@ -3,6 +3,7 @@ #include #include +#include #include wxString PATHS::GetUserScriptingPath() @@ -41,4 +42,29 @@ wxString PATHS::GetDefaultUserProjectsPath() tmp.AppendDir( "projects" ); return tmp.GetFullPath(); +} + + +wxString PATHS::GetStockScriptingPath() +{ + wxString path; + + if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) ) + { + // Allow debugging from build dir by placing a "scripting" folder in the build root + path = Pgm().GetExecutablePath() + wxT( "../scripting" ); + } + else + { + //TODO(snh) break out the directory functions into KIPLATFORM +#if defined( __WXMAC__ ) + path = GetOSXKicadDataDir() + wxT( "/scripting" ); +#elif defined( __WXMSW__ ) + path = Pgm().GetExecutablePath() + wxT( "../share/kicad/scripting" ); +#else + path = wxString( KICAD_DATA ) + wxS( "/scripting" ); +#endif + } + + return path; } \ No newline at end of file diff --git a/include/paths.h b/include/paths.h index 35d8b453ed..dfdc2d3ce7 100644 --- a/include/paths.h +++ b/include/paths.h @@ -8,6 +8,7 @@ public: static wxString GetUserScriptingPath(); static wxString GetUserTemplatesPath(); static wxString GetDefaultUserProjectsPath(); + static wxString GetStockScriptingPath(); }; #endif \ No newline at end of file diff --git a/pcbnew/swig/python_scripting.cpp b/pcbnew/swig/python_scripting.cpp index a20cbff409..06556f969f 100644 --- a/pcbnew/swig/python_scripting.cpp +++ b/pcbnew/swig/python_scripting.cpp @@ -676,22 +676,7 @@ wxString PyScriptingPath( bool aUserPath ) } else { - if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) ) - { - // Allow debugging from build dir by placing a "scripting" folder in the build root - path = Pgm().GetExecutablePath() + wxT( "../scripting" ); - } - else - { - //TODO(snh) break out the directory functions into KIPLATFORM -#if defined( __WXMAC__ ) - path = GetOSXKicadDataDir() + wxT( "/scripting" ); -#elif defined( __WXMSW__ ) - path = Pgm().GetExecutablePath() + wxT( "../share/kicad/scripting" ); -#else - path = wxString( KICAD_DATA ) + wxS( "/scripting" ); -#endif - } + path = PATHS::GetStockScriptingPath(); } wxFileName scriptPath( path );