dialog_bom: modify the way a command line is created (python scripts on windows only) to call python scripts

For some reason, when calling python and giving a full filename script, the last separator in the filename
must be '/', not '\'.
Otherwise the import command inside the script does not find files to import in the same folder as the script.

We cannot replace blindly '\' to '/' in command line because it does not work for file on a server (name starting by \\server_name\).
So the fix is just replacing one '\' in python script full filename.
This is not perfect, but at least it works for newly created plugin commands.
This commit is contained in:
jean-pierre charras 2018-02-23 09:50:15 +01:00
parent afd4710045
commit 9a462d9414
2 changed files with 23 additions and 7 deletions

View File

@ -1,8 +1,8 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras@wanadoo.fr
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -545,15 +545,31 @@ wxString DIALOG_BOM::choosePlugin()
wxFileName fn( fullFileName );
wxString ext = fn.GetExt();
// Python requires on Windows the path of the script ends by '/' instead of '\'
// otherwise import does not find modules in the same folder as the python script
// We cannot change all '\' to '/' in command line because it causes issues with files
// that are stored on network resources and pointed to using the Windows
// Universal Naming Convention format. (full filename starting by \\server\)
//
// I hope changing the last separator only to '/' will work.
#ifdef __WINDOWS__
if( ext == wxT("py" ) || ext == wxT("pyw" ) )
{
wxString sc_path = fn.GetPathWithSep();
sc_path.RemoveLast();
fullFileName = sc_path +'/' + fn.GetFullName();;
}
#endif
if( ext == "xsl" )
cmdLine.Printf( "xsltproc -o \"%%O\" \"%s\" \"%%I\"", GetChars( fullFileName ) );
else if( ext == "exe" || ext.IsEmpty() )
else if( ext == "exe" )
cmdLine.Printf( "\"%s\" < \"%%I\" > \"%%O\"", GetChars( fullFileName ) );
else if( ext == wxT("py" ) || ext.IsEmpty() )
else if( ext == "py" )
cmdLine.Printf( "python \"%s\" \"%%I\" \"%%O\"", GetChars( fullFileName ) );
else if( ext == "pyw" || ext.IsEmpty() )
else if( ext == "pyw" )
#ifdef __WINDOWS__
cmdLine.Printf(wxT("pythonw \"%s\" \"%%I\" \"%%O\""), GetChars( fullFileName ) );
cmdLine.Printf( "pythonw \"%s\" \"%%I\" \"%%O\"", GetChars( fullFileName ) );
#else
cmdLine.Printf( "python \"%s\" \"%%I\" \"%%O\"", GetChars( fullFileName ) );
#endif

View File

@ -61,7 +61,7 @@ wxString NETLIST_EXPORTER::MakeCommandLine( const wxString& aFormatString,
ret.Replace( "%I", in.GetFullPath(), true );
#ifdef __WINDOWS__
// A ugly hack to run xsltproc that has a serious bug on Window since along time:
// A ugly hack to run xsltproc that has a serious bug on Window since a long time:
// the filename given after -o option (output filename) cannot use '\' in filename
// so replace if by '/' if possible (I mean if the filename does not start by "\\"
// that is a filename on a Windows server)