#!/usr/bin/env python # TODO: Convert to use with mktap (see ./doc/howto/listings/TwistedQuotes/quotetap.py) # TODO: Use Twisted's logging # TODO: Think about using PyObjC to wrap all of this in an OS X app # TODO: Consider embedding WebKit in a Cocoa window as all-in-one browser/aggregator (see: http://cocoadevcentral.com/articles/000077.php) # $Header: /cvsroot/dbagg/bin/dbagg.py,v 1.6 2003/09/29 16:05:22 deusx Exp $ __version__ = "$Revision: 1.6 $" import ConfigParser, os, string, sys, StringIO, time, threading # Set up a module path that covers the global lib and all plugins BASE_PATH = os.path.normpath(os.path.join(\ os.path.abspath(sys.argv[0]), os.pardir, os.pardir)) sys.path.insert(0, os.path.join(BASE_PATH, 'lib')) import logging, logging.config from twisted.internet import reactor, app from twisted.manhole import telnet from twisted.python import log from twisted.python.util import spewer from twisted.python import threadable threadable.init() import dbagg import dbagg.web import dbagg.scan from spambayes import hammie #if __name__ == '__main__': # Configure logging logging.config.fileConfig(os.path.join(BASE_PATH, 'conf', 'global.conf')) main_log = logging.getLogger("") main_log.info("Starting up.") def emitLog(eventDict): edm = eventDict['message'] if not edm: if eventDict['isError'] and eventDict.has_key('failure'): text = eventDict['failure'].getTraceback() elif eventDict.has_key('format'): text = eventDict['format'] % eventDict else: # we don't know how to log this return else: text = ' '.join(map(str, edm)) main_log.debug("twisted[%s]: %s" % (eventDict['system'], text.replace("\n","\n\t"))) #log.addObserver(emitLog) # Create the global app main_app = app.Application("dbagg") # Configure data sources import sqlite, dbagg.storage.sqlite conn = sqlite.connect("data/agg", autocommit=1) sources = dbagg.storage.sqlite.SourceCollection(main_app, conn) main_app.addService(sources) items = dbagg.storage.sqlite.ItemCollection(main_app, conn) main_app.addService(items) #import MySQLdb, dbagg.storage.mysql #conn = MySQLdb.connect(host="localhost", user="dbagg", \ # passwd="dbagg", db="dbagg") #sources = dbagg.storage.mysql.SourceCollection(conn) #items = dbagg.storage.mysql.ItemCollection(conn) #main_app.addService(sources) #main_app.addService(items) # Configure the classifier bayes_db = 'data/bayes-interesting.db' usedb = True classifier = hammie.open(bayes_db, usedb, 'c') # Set up source scanning machinery source_scan_scheduler = dbagg.scan.AvgSourceScanScheduler(main_app) #source_scan_scheduler = dbagg.scan.RampingSourceScanScheduler(main_app) main_app.addService(source_scan_scheduler) item_queue = dbagg.scan.ItemQueue(main_app) main_app.addService(item_queue) source_scanner = dbagg.scan.SourceScanner(main_app) main_app.addService(source_scanner) # Create & install the webserver service http_port = 8088 #global_conf.getint('global', 'http_port') http_service = dbagg.web.WebService(main_app, http_port) main_app.addService(http_service) # Install telnet admin console telnet_port = 4040 ts = telnet.ShellFactory() main_app.listenTCP(telnet_port, ts) #sys.settrace(spewer) #sys.settrace(None) # Start everything up main_app.run(save=0)