[I18N] Update the translations
[odoo/odoo.git] / bin / openerp-server.py
1 #!/usr/bin/env python
2 # -*- encoding: utf-8 -*-
3 ##############################################################################
4 #
5 #    OpenERP, Open Source Management Solution   
6 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
7 #    $Id$
8 #
9 #    This program is free software: you can redistribute it and/or modify
10 #    it under the terms of the GNU General Public License as published by
11 #    the Free Software Foundation, either version 3 of the License, or
12 #    (at your option) any later version.
13 #
14 #    This program is distributed in the hope that it will be useful,
15 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 #    GNU General Public License for more details.
18 #
19 #    You should have received a copy of the GNU General Public License
20 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 #
22 ##############################################################################
23
24 """
25 OpenERP - Server
26 OpenERP is an ERP+CRM program for small and medium businesses.
27
28 The whole source code is distributed under the terms of the
29 GNU Public Licence.
30
31 (c) 2003-TODAY, Fabien Pinckaers - Tiny sprl
32 """
33
34 #----------------------------------------------------------
35 # python imports
36 #----------------------------------------------------------
37 import sys
38 import os
39 import signal
40
41 import release
42 __author__ = release.author
43 __version__ = release.version
44
45 #----------------------------------------------------------
46 # get logger
47 #----------------------------------------------------------
48 import netsvc
49 logger = netsvc.Logger()
50
51 #-----------------------------------------------------------------------
52 # import the tools module so that the commandline parameters are parsed
53 #-----------------------------------------------------------------------
54 import tools
55
56 logger.notifyChannel("server", netsvc.LOG_INFO, "version - %s" % release.version )
57 for name, value in [('addons_path', tools.config['addons_path']),
58                     ('database hostname', tools.config['db_host'] or 'localhost'),
59                     ('database port', tools.config['db_port'] or '5432'),
60                     ('database user', tools.config['db_user'])]:
61     logger.notifyChannel("server", netsvc.LOG_INFO, "%s - %s" % ( name, value ))
62
63 import time
64
65 if sys.platform == 'win32':
66     import mx.DateTime
67     mx.DateTime.strptime = lambda x, y: mx.DateTime.mktime(time.strptime(x, y))
68
69 #----------------------------------------------------------
70 # init net service
71 #----------------------------------------------------------
72 logger.notifyChannel("objects", netsvc.LOG_INFO, 'initialising distributed objects services')
73
74 #---------------------------------------------------------------
75 # connect to the database and initialize it with base if needed
76 #---------------------------------------------------------------
77 import pooler
78
79 #----------------------------------------------------------
80 # import basic modules
81 #----------------------------------------------------------
82 import osv
83 import workflow
84 import report
85 import service
86
87 #----------------------------------------------------------
88 # import addons
89 #----------------------------------------------------------
90
91 import addons
92
93 #----------------------------------------------------------
94 # Load and update databases if requested
95 #----------------------------------------------------------
96
97 if tools.config['db_name']:
98     for db in tools.config['db_name'].split(','):
99         pooler.get_db_and_pool(db, update_module=tools.config['init'] or tools.config['update'])
100
101 #----------------------------------------------------------
102 # translation stuff
103 #----------------------------------------------------------
104 if tools.config["translate_out"]:
105     import csv
106
107     if tools.config["language"]:
108         msg = "language %s" % (tools.config["language"],)
109     else:
110         msg = "new language"
111     logger.notifyChannel("init", netsvc.LOG_INFO, 
112                          'writing translation file for %s to %s' % (msg, 
113                                                                     tools.config["translate_out"]))
114
115     fileformat = os.path.splitext(tools.config["translate_out"])[-1][1:].lower()
116     buf = file(tools.config["translate_out"], "w")
117     tools.trans_export(tools.config["language"], tools.config["translate_modules"], buf, fileformat)
118     buf.close()
119
120     logger.notifyChannel("init", netsvc.LOG_INFO, 'translation file written successfully')
121     sys.exit(0)
122
123 if tools.config["translate_in"]:
124     tools.trans_load(tools.config["db_name"], 
125                      tools.config["translate_in"], 
126                      tools.config["language"])
127     sys.exit(0)
128
129 #----------------------------------------------------------------------------------
130 # if we don't want the server to continue to run after initialization, we quit here
131 #----------------------------------------------------------------------------------
132 if tools.config["stop_after_init"]:
133     sys.exit(0)
134
135
136 #----------------------------------------------------------
137 # Launch Server
138 #----------------------------------------------------------
139
140 if tools.config['xmlrpc']:
141     port = int(tools.config['port'])
142     interface = tools.config["interface"]
143     secure = tools.config["secure"]
144
145     httpd = netsvc.HttpDaemon(interface, port, secure)
146
147     xml_gw = netsvc.xmlrpc.RpcGateway('web-services')
148     httpd.attach("/xmlrpc", xml_gw)
149     logger.notifyChannel("web-services", netsvc.LOG_INFO, 
150                          "starting XML-RPC%s services, port %s" % 
151                          ((tools.config['secure'] and ' Secure' or ''), port))
152
153 #
154 #if tools.config["soap"]:
155 #   soap_gw = netsvc.xmlrpc.RpcGateway('web-services')
156 #   httpd.attach("/soap", soap_gw )
157 #   logger.notifyChannel("web-services", netsvc.LOG_INFO, 'starting SOAP services, port '+str(port))
158 #
159
160 if tools.config['netrpc']:
161     netport = int(tools.config['netport'])
162     netinterface = tools.config["netinterface"]
163     tinySocket = netsvc.TinySocketServerThread(netinterface, netport, False)
164     logger.notifyChannel("web-services", netsvc.LOG_INFO, 
165                          "starting NET-RPC service, port %d" % (netport,))
166
167 LST_SIGNALS = ['SIGINT', 'SIGTERM']
168 if os.name == 'posix':
169     LST_SIGNALS.extend(['SIGUSR1','SIGQUIT'])
170
171
172 SIGNALS = dict(
173     [(getattr(signal, sign), sign) for sign in LST_SIGNALS]
174 )
175
176 def handler(signum, _):
177     """
178     :param signum: the signal number
179     :param _: 
180     """
181     if tools.config['netrpc']:
182         tinySocket.stop()
183     if tools.config['xmlrpc']:
184         httpd.stop()
185     netsvc.Agent.quit()
186     if tools.config['pidfile']:
187         os.unlink(tools.config['pidfile'])
188     logger.notifyChannel('shutdown', netsvc.LOG_INFO, 
189                          "Shutdown Server! - %s" % ( SIGNALS[signum], ))
190     logger.shutdown()
191     sys.exit(0)
192
193 for signum in SIGNALS:
194     signal.signal(signum, handler)
195
196 if tools.config['pidfile']:
197     fd = open(tools.config['pidfile'], 'w')
198     pidtext = "%d" % (os.getpid())
199     fd.write(pidtext)
200     fd.close()
201
202 logger.notifyChannel("web-services", netsvc.LOG_INFO, 
203                      'the server is running, waiting for connections...')
204
205 if tools.config['netrpc']:
206     tinySocket.start()
207 if tools.config['xmlrpc']:
208     httpd.start()
209
210 while True:
211     time.sleep(1)
212
213 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
214