Commit cf9e9826 authored by eric pellegrini's avatar eric pellegrini

Removed LOGGER called from the kernel

Bug fix with Preferences
parent 19e47fa0
......@@ -35,7 +35,6 @@ import collections
import ConfigParser
import os
from MDANSE import LOGGER
from MDANSE.Core.Platform import PLATFORM, PlatformError
from MDANSE.Core.Error import Error
from MDANSE.Core.Singleton import Singleton
......@@ -232,7 +231,7 @@ class InputDirectory(PreferencesItem):
try:
PLATFORM.create_directory(value)
except PlatformError:
LOGGER("Invalid value for %r preferences item. Set the default value instead." % self._name,"warning")
raise PreferencesError('Invalid value for %r preferences item. Set the default value instead.' % self._name)
self._value = self._default
else:
self._value = value
......@@ -337,7 +336,10 @@ class Preferences(collections.OrderedDict):
for s in self._parser.sections():
for k, v in self._parser.items(s):
if self.has_key(k):
self[k].set_value(v)
try:
self[k].set_value(v)
except PreferencesError:
continue
else:
self._parser.remove_option(s,k)
if not self._parser.items(s):
......
......@@ -40,7 +40,7 @@ import subprocess
import sys
import traceback
from MDANSE import LOGGER, PLATFORM, REGISTRY
from MDANSE import PLATFORM, REGISTRY
from MDANSE.Core.Error import Error
from MDANSE.Framework.Configurable import Configurable
from MDANSE.Framework.Jobs.JobStatus import JobStatus
......@@ -468,8 +468,7 @@ class IJob(Configurable):
def save_template(cls, shortname,classname):
if REGISTRY['job'].has_key(shortname):
LOGGER('A job with %r name is already stored in the registry' % shortname,'error')
return None
raise KeyError('A job with %r name is already stored in the registry' % shortname)
from MDANSE import PREFERENCES
macrosDir = PREFERENCES["macros_directory"].get_value()
......@@ -545,7 +544,6 @@ class %s(IJob):
''' % (classname,shortname,classname))
except IOError:
LOGGER('The job template could not be save to %r. Maybe a permission problem.' % templateFile,'error')
return None
else:
f.close()
......
......@@ -101,12 +101,15 @@ class JobTemplateEditor(wx.Dialog):
return
from MDANSE.Framework.Jobs.IJob import IJob
filename = IJob.save_template(shortName,className)
if filename is not None:
LOGGER('Job template successfully saved to %r.' % filename,'info',['console'])
self.EndModal(wx.ID_OK)
try:
filename = IJob.save_template(shortName,className)
except (IOError,KeyError) as e:
LOGGER(str(e),'error',['console'])
return
LOGGER('Job template successfully saved to %r.' % filename,'info',['console'])
self.EndModal(wx.ID_OK)
if __name__ == "__main__":
app = wx.App(False)
......
......@@ -37,7 +37,8 @@ import wx
import wx.aui as wxaui
import wx.lib.filebrowsebutton as wxfile
from MDANSE import PLATFORM, PREFERENCES
from MDANSE import LOGGER, PLATFORM, PREFERENCES
from MDANSE.Core.Preferences import PreferencesError
class WritableDirectoryValidator(wx.PyValidator):
......@@ -187,21 +188,27 @@ class PreferencesSettings(wx.Dialog):
return True
def on_apply(self,event):
def on_apply(self,event=None):
if not self.validate():
return
return False
valid = True
for k, widget in self._widgets.items():
PREFERENCES[k].set_value(widget.get_value())
try:
PREFERENCES[k].set_value(widget.get_value())
except PreferencesError as e:
LOGGER(str(e),'error',['console'])
valid = False
continue
return valid
def on_ok(self,event):
if not self.validate():
if not self.on_apply():
return
for k, widget in self._widgets.items():
PREFERENCES[k].set_value(widget.get_value())
PREFERENCES.save()
......
......@@ -79,7 +79,6 @@ def databasePath(filename, directory, try_direct = False):
if entries is None:
if directory == "Atoms":
LOGGER("Atom %r not found in the MMTK database. MDANSE will create a default one." % basename,"warning")
ELEMENTS.add_element(basename,save=True)
return os.path.join(PLATFORM.local_mmtk_database_directory(),"Atoms", basename)
else:
......
......@@ -8,6 +8,7 @@ import subprocess
import sys
import textwrap
from MDANSE import LOGGER
from MDANSE.Core.Error import Error
from MDANSE import ELEMENTS, PLATFORM, REGISTRY
from MDANSE.Framework.Jobs.JobStatus import JobState
......@@ -70,9 +71,7 @@ class CommandLineParser(optparse.OptionParser):
def __init__(self,*args,**kwargs):
optparse.OptionParser.__init__(self,*args,**kwargs)
from MDANSE import LOGGER
LOGGER.add_handler("terminal", REGISTRY['handler']['terminal'](), level="info", start=True)
LOGGER.start()
......@@ -337,9 +336,13 @@ class CommandLineParser(optparse.OptionParser):
raise CommandLineParserError("Invalid number of arguments for %r option" % opt_str)
shortname,classname = parser.rargs
IJob.save_template(shortname,classname)
try:
IJob.save_template(shortname,classname)
except (IOError,KeyError) as e:
LOGGER(str(e),'error',['console'])
return
if __name__ == "__main__":
from MDANSE.__pkginfo__ import __version__, __date__
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment