- Added the LOAD command to TextSimulation, and the classic question made to user on replacing an unsaved simulation

- Changed the way syntactically incorrect python policies are handled, we no more exit abruptly

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@829 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-08-08 00:20:56 +00:00
parent d72ce96508
commit 0138387a7f
8 changed files with 189 additions and 14 deletions

View file

@ -32,7 +32,7 @@ using namespace std;
// WARNING : this class needs extensive and above all
// *strong* exception checking / handling!
PythonCPUPolicy::PythonCPUPolicy(const char* name)
PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyException)
: _upolicy_dict(NULL), _adapter(NULL), _name(name)
{
PyObject* pLoadmeStr = PyString_FromString(name);
@ -42,8 +42,7 @@ PythonCPUPolicy::PythonCPUPolicy(const char* name)
if( !pUserCPUPolicyModule )
{
PyErr_Print(); // Error in import
// FIXME : don't exit abruptly, but fall back gracefully
exit(-1);
throw MalformedPolicyException("this message should be the stuff printed by PyErr_Print");
}
// Dictionary with defined ``symbols'' for .pyc file

View file

@ -30,12 +30,12 @@
#include "cpu_policy.hh"
#include "user_interrupt_exception.hh"
#include "malformed_policy_exception.hh"
namespace sgpem
{
class PythonCPUPolicy;
class PythonCPUPolicyManager;
class UserInterruptException;
/** \brief A specialization of abstract class Policy
@ -45,7 +45,7 @@ namespace sgpem
class SG_DLLEXPORT PythonCPUPolicy : public CPUPolicy
{
public:
PythonCPUPolicy(const char* name);
PythonCPUPolicy(const char* name) throw(MalformedPolicyException);
virtual ~PythonCPUPolicy();
/**

View file

@ -122,23 +122,30 @@ PythonCPUPolicyManager::collect_policies()
for(Glib::DirIterator file_it = dir.begin(); file_it != dir.end(); ++file_it)
{
cout << "\tChecking if " << *file_it << " is a Python script... ";
cout << "\tChecking if " << *file_it << " is a valid Python script... ";
Glib::PatternSpec dot_py("*.py");
if(dot_py.match(*file_it))
{
cout << "yes\n";
cout << "yes" << endl;
//strip extension
std::string policy_name = (*file_it).substr(0, (*file_it).size() - 3);
PythonCPUPolicy *pypolicy = new PythonCPUPolicy(policy_name.c_str());
try
{
PythonCPUPolicy *pypolicy = new PythonCPUPolicy(policy_name.c_str());
_policies.push_back(pypolicy);
_policies.push_back(pypolicy);
}
catch(MalformedPolicyException e)
{
// TODO do something here someday
}
}
else
cout << "no\n";
cout << "no" << endl;
}
}
}