36 : m_storedPath( aFile )
39 m_file = wxFileName( aFile );
41 if( !wxFile::Exists(
m_file.GetFullPath() ) )
44 if( !wxFile::Exists(
m_file.GetFullPath() ) )
46 m_info.Printf(
_(
"Script file:\n%s\nnot found. Script not available."), aFile );
53 wxString extension =
m_file.GetExt().Lower();
60 if( extension == wxT(
"xsl" ) )
67 else if( extension == wxT(
"py" ) )
87 wxFileName python( PATHS::GetOSXKicadDataDir(), wxEmptyString );
88 python.RemoveLastDir();
89 python.AppendDir( wxT(
"Frameworks" ) );
90 python.AppendDir( wxT(
"Python.framework" ) );
91 python.AppendDir( wxT(
"Versions" ) );
92 python.AppendDir( wxT(
"Current" ) );
93 python.AppendDir( wxT(
"bin" ) );
94 python.SetFullName(wxT(
"python3" ) );
96 wxString interpreter = python.GetFullPath();
98 wxString interpreter = wxString::FromUTF8Unchecked( PYTHON_EXECUTABLE );
100 if( interpreter.IsEmpty() )
101 interpreter = wxT(
"python" );
110 else if( extension == wxT(
"pyw" ) )
130 wxFileName fn( aFile );
131 wxString ext = fn.GetExt().Lower();
133 for(
const auto& pluginExt : { wxT(
"xsl" ), wxT(
"py" ), wxT(
"pyw" ) } )
135 if( pluginExt == ext )
145 if( aEndSection.IsEmpty() )
146 return wxEmptyString;
148 wxFFile fdata(
m_file.GetFullPath(), wxT(
"rb" ) );
151 if( !fdata.ReadAll( &data ) )
152 return wxEmptyString;
154 const wxString header( wxT(
"@package" ) );
157 int strstart = data.Find( header );
159 if( strstart == wxNOT_FOUND )
160 return wxEmptyString;
162 strstart += header.Length();
163 int strend = data.find( aEndSection, strstart );
165 if( strend == wxNOT_FOUND )
166 return wxEmptyString;
169 while( data[strstart] <
' ' )
172 return data.SubString( strstart, strend - 1 );
180 const wxString outputarg(
"\"%O" );
182 int strstart = aHeader.Find( outputarg );
184 if( strstart == wxNOT_FOUND )
185 return wxEmptyString;
187 strstart += outputarg.Length();
188 int strend = aHeader.find(
"\"", strstart );
190 if( strend == wxNOT_FOUND )
191 return wxEmptyString;
193 return aHeader.SubString( strstart, strend - 1 );
199 if(
m_file.IsAbsolute() &&
m_file.Exists( wxFILE_EXISTS_REGULAR ) )
201 wxLogTrace(
BOM_TRACE, wxT(
"%s found directly" ),
m_file.GetFullPath() );
207 if(
test.Exists( wxFILE_EXISTS_REGULAR ) )
209 wxLogTrace(
BOM_TRACE, wxT(
"%s found in user plugins path %s" ),
m_file.GetFullName(),
216 if(
test.Exists( wxFILE_EXISTS_REGULAR ) )
218 wxLogTrace(
BOM_TRACE, wxT(
"%s found in stock plugins path %s" ),
m_file.GetFullName(),
223 wxLogTrace(
BOM_TRACE, wxT(
"Could not find %s (checked %s, %s)" ),
m_file.GetFullName(),
wxString readHeader(const wxString &aEndSection)
Read the plugin file header.
wxFileName m_file
Path to the plugin stored in config (can be absolute or just a filename)
wxString m_cmd
Description of the plugin (normally from the plugin header)
static wxString GetUserPluginsPath()
Gets the user path for plugins.
wxFileName FindFilePath() const
Returns the calculated path to the plugin: if the path is already absolute and exists,...
static bool IsValidGenerator(const wxString &aFile)
Return true if a file name matches a recognized plugin format.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
BOM_GENERATOR_HANDLER(const wxString &aFile)
static wxString getOutputExtension(const wxString &aHeader)
Extracts the output BOM file's extension, including the '.
wxString m_name
Command to execute the plugin.
wxString m_info
Plugin specific options.
bool m_isOk
Path to the plugin.
static wxString GetStockPluginsPath()
Gets the stock (install) plugins path.