2006-12-07 13:41:40 +00:00
|
|
|
#!/usr/bin/python
|
2008-07-23 15:01:27 +00:00
|
|
|
# -*- encoding: utf-8 -*-
|
2006-12-07 13:41:40 +00:00
|
|
|
##############################################################################
|
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
|
|
|
|
# $Id$
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
##############################################################################
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
"""
|
2008-09-10 08:46:40 +00:00
|
|
|
OpenERP - Server
|
|
|
|
OpenERP is an ERP+CRM program for small and medium businesses.
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
The whole source code is distributed under the terms of the
|
|
|
|
GNU Public Licence.
|
|
|
|
|
|
|
|
(c) 2003-TODAY, Fabien Pinckaers - Tiny sprl
|
|
|
|
"""
|
|
|
|
|
|
|
|
#----------------------------------------------------------
|
|
|
|
# python imports
|
|
|
|
#----------------------------------------------------------
|
2008-08-12 14:44:56 +00:00
|
|
|
import sys, os, signal
|
2008-05-15 05:23:30 +00:00
|
|
|
#----------------------------------------------------------
|
|
|
|
# ubuntu 8.04 has obsoleted `pyxml` package and installs here.
|
|
|
|
# the path needs to be updated before any `import xml`
|
2008-06-16 12:27:47 +00:00
|
|
|
# TODO: remove PyXML dependencies, use lxml instead.
|
2008-05-15 05:23:30 +00:00
|
|
|
#----------------------------------------------------------
|
|
|
|
_oldxml = '/usr/lib/python%s/site-packages/oldxml' % sys.version[:3]
|
|
|
|
if os.path.exists(_oldxml):
|
|
|
|
sys.path.append(_oldxml)
|
|
|
|
|
2008-09-12 22:31:12 +00:00
|
|
|
|
|
|
|
import release
|
|
|
|
__author__ = release.author
|
|
|
|
__version__ = release.version
|
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
#----------------------------------------------------------
|
|
|
|
# get logger
|
|
|
|
#----------------------------------------------------------
|
|
|
|
import netsvc
|
|
|
|
logger = netsvc.Logger()
|
|
|
|
|
2008-12-22 23:04:18 +00:00
|
|
|
def atexit_callback():
|
|
|
|
logger.notifyChannel('shutdown', netsvc.LOG_INFO, "Shutdown Server!")
|
|
|
|
#logger.notifyChannel('pan! pan!', netsvc.LOG_INFO, "Killed Server ;-)")
|
|
|
|
|
|
|
|
import atexit
|
|
|
|
|
|
|
|
atexit.register(atexit_callback)
|
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
# import the tools module so that the commandline parameters are parsed
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
import tools
|
2008-12-11 21:20:56 +00:00
|
|
|
|
|
|
|
logger.notifyChannel("server", netsvc.LOG_INFO, "version - %s" % release.version )
|
|
|
|
for name, value in [('addons_path', tools.config['addons_path']),
|
|
|
|
('database hostname', tools.config['db_host'] or 'localhost')]:
|
|
|
|
logger.notifyChannel("server", netsvc.LOG_INFO, "%s - %s" % ( name, value ))
|
|
|
|
|
2007-02-03 22:58:57 +00:00
|
|
|
import time
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-08-12 14:44:56 +00:00
|
|
|
if sys.platform == 'win32':
|
2008-07-22 14:24:36 +00:00
|
|
|
import mx.DateTime
|
2008-08-12 14:44:56 +00:00
|
|
|
mx.DateTime.strptime = lambda x, y: mx.DateTime.mktime(time.strptime(x, y))
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
#----------------------------------------------------------
|
|
|
|
# init net service
|
|
|
|
#----------------------------------------------------------
|
|
|
|
logger.notifyChannel("objects", netsvc.LOG_INFO, 'initialising distributed objects services')
|
|
|
|
|
|
|
|
#---------------------------------------------------------------
|
|
|
|
# connect to the database and initialize it with base if needed
|
|
|
|
#---------------------------------------------------------------
|
|
|
|
import pooler
|
|
|
|
|
|
|
|
#----------------------------------------------------------
|
|
|
|
# launch modules install/upgrade/removes if needed
|
|
|
|
#----------------------------------------------------------
|
|
|
|
if tools.config['upgrade']:
|
2008-12-08 14:03:42 +00:00
|
|
|
logger.notifyChannel('init', netsvc.LOG_INFO, 'Upgrading new modules...')
|
2008-07-22 14:24:36 +00:00
|
|
|
import tools.upgrade
|
|
|
|
(toinit, toupdate) = tools.upgrade.upgrade()
|
|
|
|
for m in toinit:
|
|
|
|
tools.config['init'][m] = 1
|
|
|
|
for m in toupdate:
|
|
|
|
tools.config['update'][m] = 1
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
#----------------------------------------------------------
|
2008-08-12 14:44:56 +00:00
|
|
|
# import basic modules
|
2006-12-07 13:41:40 +00:00
|
|
|
#----------------------------------------------------------
|
2008-12-11 21:20:56 +00:00
|
|
|
import osv
|
|
|
|
import workflow
|
|
|
|
import report
|
|
|
|
import service
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
#----------------------------------------------------------
|
|
|
|
# import addons
|
|
|
|
#----------------------------------------------------------
|
2008-12-14 16:46:47 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
import addons
|
|
|
|
|
2008-12-14 16:46:47 +00:00
|
|
|
#----------------------------------------------------------
|
|
|
|
# Load and update databases if requested
|
|
|
|
#----------------------------------------------------------
|
|
|
|
|
|
|
|
if tools.config['db_name']:
|
|
|
|
for db in tools.config['db_name'].split(','):
|
|
|
|
pooler.get_db_and_pool(db, update_module=tools.config['init'] or tools.config['update'])
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
#----------------------------------------------------------
|
|
|
|
# translation stuff
|
|
|
|
#----------------------------------------------------------
|
|
|
|
if tools.config["translate_out"]:
|
2008-07-22 14:24:36 +00:00
|
|
|
import csv
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-08-19 13:10:16 +00:00
|
|
|
if tools.config["language"]:
|
|
|
|
msg = "language %s" % (tools.config["language"],)
|
|
|
|
else:
|
|
|
|
msg = "new language"
|
|
|
|
logger.notifyChannel("init", netsvc.LOG_INFO, 'writing translation file for %s to %s' % (msg, tools.config["translate_out"]))
|
2008-07-22 07:38:43 +00:00
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
fileformat = os.path.splitext(tools.config["translate_out"])[-1][1:].lower()
|
|
|
|
buf = file(tools.config["translate_out"], "w")
|
|
|
|
tools.trans_export(tools.config["language"], tools.config["translate_modules"], buf, fileformat)
|
|
|
|
buf.close()
|
2008-08-12 14:44:56 +00:00
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
logger.notifyChannel("init", netsvc.LOG_INFO, 'translation file written succesfully')
|
|
|
|
sys.exit(0)
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
if tools.config["translate_in"]:
|
2008-07-22 14:24:36 +00:00
|
|
|
tools.trans_load(tools.config["db_name"], tools.config["translate_in"], tools.config["language"])
|
|
|
|
sys.exit(0)
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------------------
|
|
|
|
# if we don't want the server to continue to run after initialization, we quit here
|
|
|
|
#----------------------------------------------------------------------------------
|
|
|
|
if tools.config["stop_after_init"]:
|
|
|
|
sys.exit(0)
|
|
|
|
|
2007-01-25 12:30:41 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
#----------------------------------------------------------
|
|
|
|
# Launch Server
|
|
|
|
#----------------------------------------------------------
|
|
|
|
|
2007-02-03 22:58:57 +00:00
|
|
|
if tools.config['xmlrpc']:
|
2008-07-22 14:24:36 +00:00
|
|
|
try:
|
|
|
|
port = int(tools.config["port"])
|
|
|
|
except Exception:
|
2008-12-19 10:55:28 +00:00
|
|
|
logger.notifyChannel("init", netsvc.LOG_CRITICAL, "invalid port: %r" % (tools.config["port"],))
|
2008-07-22 14:24:36 +00:00
|
|
|
sys.exit(1)
|
|
|
|
interface = tools.config["interface"]
|
|
|
|
secure = tools.config["secure"]
|
2008-08-12 14:44:56 +00:00
|
|
|
|
2008-12-19 10:55:28 +00:00
|
|
|
httpd = netsvc.HttpDaemon(interface, port, secure)
|
2008-12-18 21:36:30 +00:00
|
|
|
|
2008-12-19 10:55:28 +00:00
|
|
|
xml_gw = netsvc.xmlrpc.RpcGateway('web-services')
|
|
|
|
httpd.attach("/xmlrpc", xml_gw)
|
|
|
|
logger.notifyChannel("web-services", netsvc.LOG_INFO, "starting XML-RPC%s services, port %s" % ((tools.config['secure'] and ' Secure' or ''), port))
|
2008-12-11 21:20:56 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
#if tools.config["soap"]:
|
|
|
|
# soap_gw = netsvc.xmlrpc.RpcGateway('web-services')
|
|
|
|
# httpd.attach("/soap", soap_gw )
|
|
|
|
# logger.notifyChannel("web-services", netsvc.LOG_INFO, 'starting SOAP services, port '+str(port))
|
|
|
|
#
|
2007-02-03 22:58:57 +00:00
|
|
|
|
|
|
|
if tools.config['netrpc']:
|
2008-07-22 14:24:36 +00:00
|
|
|
try:
|
|
|
|
netport = int(tools.config["netport"])
|
|
|
|
except Exception:
|
|
|
|
logger.notifyChannel("init", netsvc.LOG_ERROR, "invalid port '%s'!" % (tools.config["netport"],))
|
|
|
|
sys.exit(1)
|
|
|
|
netinterface = tools.config["netinterface"]
|
2008-08-12 14:44:56 +00:00
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
tinySocket = netsvc.TinySocketServerThread(netinterface, netport, False)
|
2008-11-22 15:52:07 +00:00
|
|
|
logger.notifyChannel("web-services", netsvc.LOG_INFO, "starting NET-RPC service, port "+str(netport))
|
2007-01-25 12:30:41 +00:00
|
|
|
|
2008-08-12 14:44:56 +00:00
|
|
|
|
2007-01-25 12:30:41 +00:00
|
|
|
def handler(signum, frame):
|
2008-07-22 14:24:36 +00:00
|
|
|
from tools import config
|
|
|
|
if tools.config['netrpc']:
|
|
|
|
tinySocket.stop()
|
|
|
|
if tools.config['xmlrpc']:
|
|
|
|
httpd.stop()
|
|
|
|
netsvc.Agent.quit()
|
|
|
|
if config['pidfile']:
|
|
|
|
os.unlink(config['pidfile'])
|
|
|
|
sys.exit(0)
|
2007-01-25 12:30:41 +00:00
|
|
|
|
|
|
|
from tools import config
|
|
|
|
if config['pidfile']:
|
2008-08-12 14:44:56 +00:00
|
|
|
fd = open(config['pidfile'], 'w')
|
|
|
|
pidtext = "%d" % (os.getpid())
|
2008-07-22 14:24:36 +00:00
|
|
|
fd.write(pidtext)
|
|
|
|
fd.close()
|
2007-02-03 22:58:57 +00:00
|
|
|
|
2007-01-25 12:30:41 +00:00
|
|
|
signal.signal(signal.SIGINT, handler)
|
|
|
|
signal.signal(signal.SIGTERM, handler)
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2007-01-25 12:30:41 +00:00
|
|
|
logger.notifyChannel("web-services", netsvc.LOG_INFO, 'the server is running, waiting for connections...')
|
2007-02-03 22:58:57 +00:00
|
|
|
if tools.config['netrpc']:
|
2008-07-22 14:24:36 +00:00
|
|
|
tinySocket.start()
|
2007-02-03 22:58:57 +00:00
|
|
|
if tools.config['xmlrpc']:
|
2008-07-22 14:24:36 +00:00
|
|
|
httpd.start()
|
2007-02-03 22:58:57 +00:00
|
|
|
|
|
|
|
while True:
|
2008-07-22 14:24:36 +00:00
|
|
|
time.sleep(1)
|
2008-07-23 15:01:27 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|