def main ( database=':memory:', host='127.0.0.2', port=3999, precision=1.0, inactive=3.0, local=512, private=1, public=1, log_buffer_size=4096, anetlog_host='', anetlog_port=3998 ): import time started = time.time () from allegra import netstring, loginfo, tcp_server, ansqlite if anetlog_host: from allegra import anetlog anetlog.stdoe ((anetlog_host, anetlog_port)) loginfo.log ( 'ansqlite - Copyright 2007 Laurent Szyster | Copyleft GPL 2.0', 'info' ) conn, Dispatcher = ansqlite.open (database) ansql = Dispatcher.ansql loads = ansqlite.loads for data in netstring.netpipe (( lambda r=sys.stdin.read: r (log_buffer_size) )): ansql (*loads(data)).close () del ansql, loads listen = tcp_server.decorate (tcp_server.Listen ( Dispatcher, (host, port), precision, max=5 ), inactive, local, private, public) async_loop.catch (listen.server_shutdown) def finalize (listen): anetlog.disconnect () conn.close () listen.finalization = finalize del listen loginfo.log ('loaded in %f seconds' % (time.time () - started), 'info')
def main ( root='.', precision=1.0, inactive=3.0, local=512, private=1, public=1, anetlog_host='', anetlog_port=3998, ac_in=16384, ac_out=16384 ): import time started = time.time () from allegra import loginfo, ip_peer, tcp_server, http_server, presto http_server.Dispatcher.ac_in_buffer_size = ac_in http_server.Dispatcher.ac_out_buffer_size = ac_out if anetlog_host: from allegra import anetlog anetlog.stdoe ((anetlog_host, anetlog_port)) def finalize (joined): anetlog.disconnect () loginfo.log ('final', 'info') else: def finalize (joined): loginfo.log ('final', 'info') loginfo.log ( 'Allegra PRESTo' ' - Coyright 2005-2007 Laurent A.V. Szyster' ' | Copyleft GPL 2.0', 'info' ) import glob, os, stat joined = finalization.Finalization () for listen in [ tcp_server.decorate (presto.Listen ( path, addr, precision ), inactive, local, private, public) for path, addr in [ ( p.replace ('\\', '/'), ip_peer.addr (os.path.basename (p), 80) ) for p in glob.glob ('%s/*' % root) if stat.S_ISDIR (os.stat (p)[0]) ] ]: for filename in listen.presto_dir (): listen.presto_load (filename) async_loop.catch (listen.server_shutdown) listen.finalization = joined joined.finalization = finalize loginfo.log ('loaded in %f seconds' % (time.time () - started), 'info')
def main(database=':memory:', host='127.0.0.2', port=3999, precision=1.0, inactive=3.0, local=512, private=1, public=1, log_buffer_size=4096, anetlog_host='', anetlog_port=3998): import time started = time.time() from allegra import netstring, loginfo, tcp_server, ansqlite if anetlog_host: from allegra import anetlog anetlog.stdoe((anetlog_host, anetlog_port)) loginfo.log('ansqlite - Copyright 2007 Laurent Szyster | Copyleft GPL 2.0', 'info') conn, Dispatcher = ansqlite.open(database) ansql = Dispatcher.ansql loads = ansqlite.loads for data in netstring.netpipe( (lambda r=sys.stdin.read: r(log_buffer_size))): ansql(*loads(data)).close() del ansql, loads listen = tcp_server.decorate( tcp_server.Listen(Dispatcher, (host, port), precision, max=5), inactive, local, private, public) async_loop.catch(listen.server_shutdown) def finalize(listen): anetlog.disconnect() conn.close() listen.finalization = finalize del listen loginfo.log('loaded in %f seconds' % (time.time() - started), 'info')