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 == wxS(
"xsl" ) )
63 m_cmd = wxString::Format( wxS(
"xsltproc -o \"%%O%s\" \"%s\" \"%%I\"" ),
67 else if( extension == wxS(
"py" ) )
71 m_cmd = wxString::Format(
"python \"%s/%s\" \"%%I\" \"%%O%s\"",
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" );
103 m_cmd = wxString::Format(
"%s \"%s\" \"%%I\" \"%%O%s\"",
110 else if( extension == wxS(
"pyw" ) )
113 m_cmd = wxString::Format( wxS(
"pythonw \"%s/%s\" \"%%I\" \"%%O%s\"" ),
130 wxFileName fn( aFile );
131 wxString ext = fn.GetExt().Lower();
133 for(
const auto& pluginExt : { wxS(
"xsl" ), wxS(
"py" ), wxS(
"pyw" ) } )
135 if( pluginExt == ext )
145 if( aEndSection.IsEmpty() )
146 return wxEmptyString;
148 wxFFile fdata(
m_file.GetFullPath(), wxS(
"rb" ) );
151 if( !fdata.ReadAll( &data ) )
152 return wxEmptyString;
154 const wxString header( wxS(
"@package" ) );
157 size_t strstart = data.find( header );
159 if( strstart == wxString::npos )
160 return wxEmptyString;
162 strstart += header.Length();
163 size_t strend = data.find( aEndSection, strstart );
165 if( strend == wxString::npos )
166 return wxEmptyString;
169 while( data[strstart] <
' ' )
172 return data.SubString( strstart, strend - 1 );
180 const wxString outputarg( wxS(
"\"%O" ) );
182 size_t strstart = aHeader.find( outputarg );
184 if( strstart == wxString::npos )
185 return wxEmptyString;
187 strstart += outputarg.Length();
188 size_t strend = aHeader.find( wxS(
"\"" ), strstart );
190 if( strend == wxString::npos )
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, wxS(
"%s found directly" ),
m_file.GetFullPath() );
207 if(
test.Exists( wxFILE_EXISTS_REGULAR ) )
209 wxLogTrace(
BOM_TRACE, wxS(
"%s found in user plugins path %s" ),
m_file.GetFullName(),
216 if(
test.Exists( wxFILE_EXISTS_REGULAR ) )
218 wxLogTrace(
BOM_TRACE, wxS(
"%s found in stock plugins path %s" ),
m_file.GetFullName(),
223 wxLogTrace(
BOM_TRACE, wxS(
"Could not find %s (checked %s, %s)" ),
m_file.GetFullName(),
wxString m_name
Command to execute the plugin.
static bool IsValidGenerator(const wxString &aFile)
Return true if a file name matches a recognized plugin format.
wxString readHeader(const wxString &aEndSection)
Read the plugin file header.
bool m_isOk
Path to the plugin.
BOM_GENERATOR_HANDLER(const wxString &aFile)
wxString m_info
Plugin specific options.
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)
wxFileName FindFilePath() const
Returns the calculated path to the plugin: if the path is already absolute and exists,...
static wxString getOutputExtension(const wxString &aHeader)
Extracts the output BOM file's extension, including the '.
static wxString GetUserPluginsPath()
Gets the user path for plugins.
static wxString GetStockPluginsPath()
Gets the stock (install) plugins path.