Commit cf9e9826 authored by eric pellegrini's avatar eric pellegrini
Browse files

Removed LOGGER called from the kernel

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