Ejemplo n.º 1
0
__author__ = "Tony Meyer <*****@*****.**>"
__credits__ = "Tim Stone; all the SpamBayes folk"

import os
import sys
import getopt

from spambayes import storage

if __name__ == '__main__':
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'ht:T:n:N:')
    except getopt.error, msg:
        print >> sys.stderr, str(msg) + '\n\n' + __doc__
        sys.exit()

    old_name = old_type = new_name = new_type = None
    for opt, arg in opts:
        if opt == '-h':
            print >> sys.stderr, __doc__
            sys.exit()
        elif opt == '-t':
            old_type = arg
        elif opt == '-T':
            new_type = arg
        elif opt == '-n':
            old_name = os.path.expanduser(arg)
        elif opt == '-N':
            new_name = os.path.expanduser(arg)
    storage.convert(old_name, old_type, new_name, new_type)
Ejemplo n.º 2
0
the script with no options should work.  To convert the database from
dbm to ZODB on linux or OS X, the following should work:
    python convert_db.py -n ~/.hammie.db
"""
__author__ = "Tony Meyer <*****@*****.**>"
__credits__ = "Tim Stone; all the SpamBayes folk"
import os
import sys
import getopt
from spambayes import storage
if __name__ == '__main__':
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'ht:T:n:N:')
    except getopt.error, msg:
        print >>sys.stderr, str(msg) + '\n\n' + __doc__
        sys.exit()
    old_name = old_type = new_name = new_type = None
    for opt, arg in opts:
        if opt == '-h':
            print >>sys.stderr, __doc__
            sys.exit()
        elif opt == '-t':
            old_type = arg
        elif opt == '-T':
            new_type = arg
        elif opt == '-n':
            old_name = os.path.expanduser(arg)
        elif opt == '-N':
            new_name = os.path.expanduser(arg)
    storage.convert(old_name, old_type, new_name, new_type)
Ejemplo n.º 3
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)