2011-03-02 18:56:06 +00:00
#!/usr/bin/env python
2011-08-31 17:37:29 +00:00
import optparse , os , sys , tempfile
import cherrypy
import cherrypy . lib . static
2011-03-02 18:56:06 +00:00
2011-08-30 23:23:00 +00:00
path_root = os . path . dirname ( os . path . abspath ( __file__ ) )
path_addons = os . path . join ( path_root , ' addons ' )
if path_addons not in sys . path :
sys . path . insert ( 0 , path_addons )
import base
2011-03-02 18:56:06 +00:00
2011-08-31 17:37:29 +00:00
def main ( argv ) :
# change the timezone of the program to the OpenERP server's assumed timezone
os . environ [ " TZ " ] = " UTC "
2011-08-30 23:44:33 +00:00
2011-08-31 17:37:29 +00:00
DEFAULT_CONFIG = {
' server.socket_host ' : ' 0.0.0.0 ' ,
' tools.sessions.on ' : True ,
' tools.sessions.storage_type ' : ' file ' ,
' tools.sessions.timeout ' : 60
}
# Parse config
op = optparse . OptionParser ( )
op . add_option ( " -p " , " --port " , dest = " server.socket_port " , default = 8002 , help = " listening port " , type = " int " , metavar = " NUMBER " )
op . add_option ( " -s " , " --session-path " , dest = " tools.sessions.storage_path " , default = os . path . join ( tempfile . gettempdir ( ) , " cpsessions " ) , help = " directory used for session storage " , metavar = " DIR " )
op . add_option ( " --server-host " , dest = " openerp.server.host " , default = ' 127.0.0.1 ' , help = " OpenERP server hostname " , metavar = " HOST " )
op . add_option ( " --server-port " , dest = " openerp.server.port " , default = 8069 , help = " OpenERP server port " , type = " int " , metavar = " NUMBER " )
op . add_option ( " --db-filter " , dest = " openerp.dbfilter " , default = ' .* ' , help = " Filter listed database " , metavar = " REGEXP " )
( o , args ) = op . parse_args ( argv [ 1 : ] )
o = vars ( o )
for k in o . keys ( ) :
if o [ k ] is None :
del ( o [ k ] )
# Setup and run cherrypy
cherrypy . tree . mount ( base . common . Root ( ) )
2011-08-30 23:44:33 +00:00
2011-08-31 17:37:29 +00:00
cherrypy . config . update ( config = DEFAULT_CONFIG )
if os . path . exists ( os . path . join ( path_root , ' openerp-web.cfg ' ) ) :
cherrypy . config . update ( os . path . join ( path_root , ' openerp-web.cfg ' ) )
if os . path . exists ( os . path . expanduser ( ' ~/.openerp_webrc ' ) ) :
cherrypy . config . update ( os . path . expanduser ( ' ~/.openerp_webrc ' ) )
cherrypy . config . update ( o )
2011-08-30 23:44:33 +00:00
2011-08-31 17:37:29 +00:00
if not os . path . exists ( cherrypy . config [ ' tools.sessions.storage_path ' ] ) :
os . makedirs ( cherrypy . config [ ' tools.sessions.storage_path ' ] , 0700 )
cherrypy . server . subscribe ( )
cherrypy . engine . start ( )
cherrypy . engine . block ( )
if __name__ == " __main__ " :
main ( sys . argv )
2011-08-30 23:44:33 +00:00