Esempio n. 1
0
 def restoreConfigDefaults(self, parm_map):
     d = OptionsClass()
     d.load_defaults(defaults)
     for section, option in parm_map:
         if option is not None:
             if not options.no_restore(section, option):
                 options.set(section, option, d.get(section, option))
     options.update_file(optionsPathname)
Esempio n. 2
0
    def onCvresults(self, *args, **kwargs):
        del kwargs["how"]
        self._writePreamble("CV Test Results")
        text = "Display the results of a cross-validation test with the " \
               "current settings against the defaults."
        nsets = options["TestToolsUI", "n"]

        # With defaults first.
        self.write("<p>Testing with defaults...</p>")
        saved = {}
        for opt in options.options(True):
            # Ignore those that have do_not_restore as True
            # (These are predominately storage options, and at least
            # the cache directory ones may be needed later on).
            sect, opt = opt[1:].split(']', 1)
            saved[(sect, opt)] = options[(sect, opt)]
            if not options.no_restore(sect, opt):
                options.set(sect, opt, options.default(sect, opt))
        options["TestToolsUI", "source"] = kwargs["TestToolsUI_source"]
        # XXX Cache this somewhere?  If the testing data isn't changing,
        # XXX and the user is running multiple tests, then it doesn't
        # XXX make much sense to rerun the 'default's test over and over
        # XXX again.
        cv_out, errors = self.timCV(nsets)
##        print errors.read()
        defaults = self.rates(cv_out)

        # Now with specified settings.
        self.write("<p>Testing with selected settings...</p>")
        for opt in options.options(True):
            sect, opt = opt[1:].split(']', 1)
            try:
                value = kwargs["%s_%s" % (sect, opt)]
            except KeyError:
                # Leave as the default.
                pass
            else:
                options.set(sect, opt, value)
        cv_out, errors = self.timCV(nsets)
##        print errors.read()
        current = self.rates(cv_out)

        # Restore the settings.
        for opt in options.options(True):
            sect, opt = opt[1:].split(']', 1)
            options.set(sect, opt, saved[(sect, opt)])

        # Do the comparison.
        comp, errors = self.compare(defaults, current)
##        print errors.read()

        # Output the results
        # XXX This is just what you'd get from running cmp.py
        # XXX at the moment - it could be prettied up a bit.
        comp = comp.read()
        box = self._buildBox('Cross-validation test', None,
                             cgi.escape(comp).replace("\n", "<br />"))
        self.write(box)
        self._writePostamble()
Esempio n. 3
0
    def onCvresults(self, *args, **kwargs):
        del kwargs["how"]
        self._writePreamble("CV Test Results")
        text = "Display the results of a cross-validation test with the " \
               "current settings against the defaults."
        nsets = options["TestToolsUI", "n"]

        # With defaults first.
        self.write("<p>Testing with defaults...</p>")
        saved = {}
        for opt in options.options(True):
            # Ignore those that have do_not_restore as True
            # (These are predominately storage options, and at least
            # the cache directory ones may be needed later on).
            sect, opt = opt[1:].split(']', 1)
            saved[(sect, opt)] = options[(sect, opt)]
            if not options.no_restore(sect, opt):
                options.set(sect, opt, options.default(sect, opt))
        options["TestToolsUI", "source"] = kwargs["TestToolsUI_source"]
        # XXX Cache this somewhere?  If the testing data isn't changing,
        # XXX and the user is running multiple tests, then it doesn't
        # XXX make much sense to rerun the 'default's test over and over
        # XXX again.
        cv_out, errors = self.timCV(nsets)
        ##        print errors.read()
        defaults = self.rates(cv_out)

        # Now with specified settings.
        self.write("<p>Testing with selected settings...</p>")
        for opt in options.options(True):
            sect, opt = opt[1:].split(']', 1)
            try:
                value = kwargs["%s_%s" % (sect, opt)]
            except KeyError:
                # Leave as the default.
                pass
            else:
                options.set(sect, opt, value)
        cv_out, errors = self.timCV(nsets)
        ##        print errors.read()
        current = self.rates(cv_out)

        # Restore the settings.
        for opt in options.options(True):
            sect, opt = opt[1:].split(']', 1)
            options.set(sect, opt, saved[(sect, opt)])

        # Do the comparison.
        comp, errors = self.compare(defaults, current)
        ##        print errors.read()

        # Output the results
        # XXX This is just what you'd get from running cmp.py
        # XXX at the moment - it could be prettied up a bit.
        comp = comp.read()
        box = self._buildBox('Cross-validation test', None,
                             cgi.escape(comp).replace("\n", "<br />"))
        self.write(box)
        self._writePostamble()
Esempio n. 4
0
 def onCvresults(self, *args, **kwargs):
     del kwargs["how"]
     self._writePreamble("CV Test Results")
     text = "Display the results of a cross-validation test with the " \
            "current settings against the defaults."
     nsets = options["TestToolsUI", "n"]
     self.write("<p>Testing with defaults...</p>")
     saved = {}
     for opt in options.options(True):
         sect, opt = opt[1:].split(']', 1)
         saved[(sect, opt)] = options[(sect, opt)]
         if not options.no_restore(sect, opt):
             options.set(sect, opt, options.default(sect, opt))
     options["TestToolsUI", "source"] = kwargs["TestToolsUI_source"]
     cv_out, errors = self.timCV(nsets)
     defaults = self.rates(cv_out)
     self.write("<p>Testing with selected settings...</p>")
     for opt in options.options(True):
         sect, opt = opt[1:].split(']', 1)
         try:
             value = kwargs["%s_%s" % (sect, opt)]
         except KeyError:
             pass
         else:
             options.set(sect, opt, value)
     cv_out, errors = self.timCV(nsets)
     current = self.rates(cv_out)
     for opt in options.options(True):
         sect, opt = opt[1:].split(']', 1)
         options.set(sect, opt, saved[(sect, opt)])
     comp, errors = self.compare(defaults, current)
     comp = comp.read()
     box = self._buildBox('Cross-validation test', None,
                          cgi.escape(comp).replace("\n", "<br />"))
     self.write(box)
     self._writePostamble()
Esempio n. 5
0
 def onChangeopts(self, **parms):
     pmap = self.parm_ini_map
     if parms.has_key("how"):
         if parms["how"] == _("Save advanced options"):
             pmap = self.advanced_options_map
         elif parms["how"] == _("Save experimental options"):
             pmap = experimental_ini_map
         elif parms["how"] == _("Save plugin options"):
             pmap = self.plugin_ini_map
         del parms["how"]
     html = self._getHTMLClone()
     html.shutdownTableCell = "&nbsp;"
     html.mainContent = self.html.headedBox.clone()
     errmsg = self.verifyInput(parms, pmap)
     if errmsg != "":
         html.mainContent.heading = _("Errors Detected")
         html.mainContent.boxContent = errmsg
         html.title = _("Home &gt; Error")
         html.pagename = _("&gt; Error")
         self.writeOKHeaders("text/html")
         self.write(html)
         return
     old_database_type = options["Storage", "persistent_use_database"]
     old_name = options["Storage", "persistent_storage_file"]
     for name, value in parms.items():
         sect, opt = name.split("_", 1)
         if (sect, opt) in pmap:
             options.set(sect, opt, value)
         else:
             sect2, opt = opt.split("_", 1)
             sect += "_" + sect2
             options.set(sect, opt, value)
     options.update_file(optionsPathname)
     if options["Storage", "persistent_use_database"] != old_database_type and os.path.exists(old_name):
         new_name = options["Storage", "persistent_storage_file"]
         new_type = options["Storage", "persistent_use_database"]
         self.close_database()
         try:
             os.remove(new_name + ".tmp")
         except OSError:
             pass
         storage.convert(old_name, old_database_type, new_name + ".tmp", new_type)
         if os.path.exists(new_name):
             try:
                 os.remove(new_name + ".old")
             except OSError:
                 pass
             os.rename(new_name, new_name + ".old")
         os.rename(new_name + ".tmp", new_name)
         if os.path.exists(options["Storage", "messageinfo_storage_file"]):
             try:
                 os.remove(options["Storage", "messageinfo_storage_file"] + ".old")
             except OSError:
                 pass
             os.rename(
                 options["Storage", "messageinfo_storage_file"],
                 options["Storage", "messageinfo_storage_file"] + ".old",
             )
     self.reReadOptions()
     html.mainContent.heading = _("Options Changed")
     html.mainContent.boxContent = _("Options changed.  Return " "<a href='home'>Home</a>.")
     html.title = _("Home &gt; Options Changed")
     html.pagename = _("&gt; Options Changed")
     self.writeOKHeaders("text/html")
     self.write(html)