kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #00266
PATCH: python execute in place
-
To:
kicad-devel@xxxxxxxxxxxxxxx
-
From:
DELIZY Florian <florian.delizy@...>
-
Date:
Sun, 06 May 2007 21:33:55 +0200
-
User-agent:
Icedove 1.5.0.10 (X11/20070328)
This patch execute the python scripts in their owning directory,
(changing temporary directories).
This is quite useful for loading resources for instance.
---
common/pyhandler.cpp | 38 +++++++++++++++++++++++---------------
1 file changed, 23 insertions(+), 15 deletions(-)
--------------030405060702040808010604 Content-Type: text/x-patch;
name="kicad-py-exec-in-place.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="kicad-py-exec-in-place.patch"
Subject: PATCH: @patch@
This patch execute the python scripts in their owning directory, (changing temporary directories).
This is quite useful for loading resources for instance.
---
common/pyhandler.cpp | 38 +++++++++++++++++++++++---------------
1 file changed, 23 insertions(+), 15 deletions(-)
Index: kicad-dev/common/pyhandler.cpp
===================================================================
--- kicad-dev.orig/common/pyhandler.cpp 2007-05-06 21:22:15.000000000 +0200
+++ kicad-dev/common/pyhandler.cpp 2007-05-06 21:31:32.000000000 +0200
@@ -242,6 +242,7 @@
object module( handle<>(borrowed(PyImport_AddModule("__main__"))));
object ns = module.attr( "__dict__" );
+ bool ret = true;
FILE * file = fopen( name.fn_str(), "r" );
@@ -251,25 +252,32 @@
{
// do something
std::cout << "Unable to Load " << name.fn_str() << "\n";
- return false;
+ ret = false;
}
+ else
+ {
+ wxString currDir = wxGetCwd();
- try
- {
- ns["currentScript"] = Convert( name );
- handle<> ignored( PyRun_File( file, name.fn_str(), Py_file_input, ns.ptr(), ns.ptr() ) );
- }
- catch ( error_already_set )
- {
- PyErr_Print(); // should be printed into an error message ...
- fclose( file );
- wxPyEndBlockThreads(blocked);
- return false;
- }
+ wxFileName fname( name );
+ wxString pyDir = fname.GetPath();
+
+ wxSetWorkingDirectory( pyDir );
+ try
+ {
+ ns["currentScript"] = Convert( name );
+ handle<> ignored( PyRun_File( file, name.fn_str(), Py_file_input, ns.ptr(), ns.ptr() ) );
+ }
+ catch ( error_already_set )
+ {
+ PyErr_Print(); // should be printed into an error message ...
+ ret = false;
+ }
+ wxSetWorkingDirectory( currDir );
+ }
- wxPyEndBlockThreads(blocked);
fclose( file );
- return true;
+ wxPyEndBlockThreads(blocked);
+ return ret;
}
bool PyHandler::RunSimpleString( const wxString & code )
--------------030405060702040808010604--