36 m_file = wxFileName( aFile );
38 if( !wxFile::Exists(
m_file.GetFullPath() ) )
41 if( !wxFile::Exists(
m_file.GetFullPath() ) )
43 m_info.Printf(
_(
"Script file:\n%s\nnot found. Script not available."), aFile );
50 wxString extension =
m_file.GetExt().Lower();
57 if( extension == wxS(
"xsl" ) )
60 m_cmd = wxString::Format( wxS(
"xsltproc -o \"%%O%s\" \"%s\" \"%%I\"" ),
64 else if( extension == wxS(
"py" ) )
68 m_cmd = wxString::Format(
"python \"%s/%s\" \"%%I\" \"%%O%s\"",
73 wxString interpreter = wxString::FromUTF8Unchecked( PYTHON_EXECUTABLE );
75 if( interpreter.IsEmpty() )
76 interpreter = wxT(
"python" );
78 m_cmd = wxString::Format(
"%s \"%s\" \"%%I\" \"%%O%s\"",
85 else if( extension == wxS(
"pyw" ) )
88 m_cmd = wxString::Format( wxS(
"pythonw \"%s/%s\" \"%%I\" \"%%O%s\"" ),
105 wxFileName fn( aFile );
106 wxString ext = fn.GetExt().Lower();
108 for(
const auto& pluginExt : { wxS(
"xsl" ), wxS(
"py" ), wxS(
"pyw" ) } )
110 if( pluginExt == ext )
120 if( aEndSection.IsEmpty() )
121 return wxEmptyString;
123 wxFFile fdata(
m_file.GetFullPath(), wxS(
"rb" ) );
126 if( !fdata.ReadAll( &data ) )
127 return wxEmptyString;
129 const wxString
header( wxS(
"@package" ) );
132 size_t strstart = data.find(
header );
134 if( strstart == wxString::npos )
135 return wxEmptyString;
137 strstart +=
header.Length();
138 size_t strend = data.find( aEndSection, strstart );
140 if( strend == wxString::npos )
141 return wxEmptyString;
144 while( data[strstart] <
' ' )
147 return data.SubString( strstart, strend - 1 );
155 const wxString outputarg( wxS(
"\"%O" ) );
157 size_t strstart = aHeader.find( outputarg );
159 if( strstart == wxString::npos )
160 return wxEmptyString;
162 strstart += outputarg.Length();
163 size_t strend = aHeader.find( wxS(
"\"" ), strstart );
165 if( strend == wxString::npos )
166 return wxEmptyString;
168 return aHeader.SubString( strstart, strend - 1 );
174 if(
m_file.IsAbsolute() &&
m_file.Exists( wxFILE_EXISTS_REGULAR ) )
176 wxLogTrace(
BOM_TRACE, wxS(
"%s found directly" ),
m_file.GetFullPath() );
182 if(
test.Exists( wxFILE_EXISTS_REGULAR ) )
184 wxLogTrace(
BOM_TRACE, wxS(
"%s found in user plugins path %s" ),
m_file.GetFullName(),
191 if(
test.Exists( wxFILE_EXISTS_REGULAR ) )
193 wxLogTrace(
BOM_TRACE, wxS(
"%s found in stock plugins path %s" ),
m_file.GetFullName(),
198 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)
const wxString m_storedPath
User customisable name.
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.
std::vector< std::string > header