⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 which_database.py

📁 用python实现的邮件过滤器
💻 PY
字号:
#!/usr/bin/env python"""which_databaseThis little script checks which database is used to save your data, andalso prints out information about which database systems are available.It will check whichever database you have setup to use in the [Storage]persistent_storage_file option.Note that you will end up with extra files after running this utilitythat may be safely deleted:  o dumbdb.dir  o dumbdb.dat  o dumbdb.bak  o bsddb3  o dbhash"""__author__ = "Remi Ricard <papaDoc@videotron.ca>"__credits__ = "Skip Montanaro, all the Spambayes folk."import osimport syssys.path.insert(-1, os.getcwd())sys.path.insert(-1, os.path.dirname(os.getcwd()))from spambayes.Options import options, get_pathname_optionimport dumbdbmimport dbhashimport whichdbtry:    import bsddbexcept ImportError:    try:        import bsddb3 as bsddb    except ImportError:        bsddb = Nonedef main():    print "Pickle is available."    db = dumbdbm.open("dumbdb", "c")    db["1"] = "1"    db.close()    dbstr = whichdb.whichdb("dumbdb")    if dbstr:        print "Dumbdbm is available."    else:        print "Dumbdbm is not available."    db = dbhash.open("dbhash", "c")    db["1"] = "1"    db.close()    dbstr = whichdb.whichdb("dbhash")    if dbstr == "dbhash":        print "Dbhash is available."    else:        print "Dbhash is not available."    if bsddb is None:        dbstr = ""    else:        db = bsddb.hashopen("bsddb3", "c")        db["1"] = "1"        db.close()        dbstr = whichdb.whichdb("bsddb3")    if dbstr == "dbhash":        print "Bsddb[3] is available."    else:        print "Bsddb[3] is not available."    print    hammie = get_pathname_option("Storage", "persistent_storage_file")    use_dbm = options["Storage", "persistent_use_database"]    if not use_dbm:        print "Your storage %s is a: pickle" % (hammie,)        return    if not os.path.exists(hammie):        print "Your storage file does not exist yet."        return    db_type = whichdb.whichdb(hammie)    if db_type == "dbhash":        # could be dbhash or bsddb3        # only bsddb3 has a __version__ attribute - old bsddb module does not        if hasattr(bsddb, '__version__'):            try:                db = bsddb.hashopen(hammie, "r")            except bsddb.error:                pass            else:                db.close()                print "Your storage", hammie, "is a: bsddb[3]"                return    elif db_type is None:        print "Your storage %s is unreadable." % (hammie,)    print "Your storage %s is a: %s" % (hammie, db_type)if __name__ == "__main__":    main()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -