~openerp-groupes/openobject-server/6.0-fix-setup-windows

« back to all changes in this revision

Viewing changes to bin/tinyerp-server.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-3f10ee12cea3c4c75cef44ab04ad33ef47432907
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
##############################################################################
 
4
#
 
5
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be)
 
6
#
 
7
# $Id: tinyerp-server.py 1308 2005-09-08 18:02:01Z pinky $
 
8
#
 
9
# WARNING: This program as such is intended to be used by professional
 
10
# programmers who take the whole responsability of assessing all potential
 
11
# consequences resulting from its eventual inadequacies and bugs
 
12
# End users who are looking for a ready-to-use solution with commercial
 
13
# garantees and support are strongly adviced to contact a Free Software
 
14
# Service Company
 
15
#
 
16
# This program is Free Software; you can redistribute it and/or
 
17
# modify it under the terms of the GNU General Public License
 
18
# as published by the Free Software Foundation; either version 2
 
19
# of the License, or (at your option) any later version.
 
20
#
 
21
# This program is distributed in the hope that it will be useful,
 
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
24
# GNU General Public License for more details.
 
25
#
 
26
# You should have received a copy of the GNU General Public License
 
27
# along with this program; if not, write to the Free Software
 
28
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
29
#
 
30
##############################################################################
 
31
 
 
32
"""
 
33
Tiny ERP - Server
 
34
Tiny ERP is an ERP+CRM program for small and medium businesses.
 
35
 
 
36
The whole source code is distributed under the terms of the
 
37
GNU Public Licence.
 
38
 
 
39
(c) 2003-TODAY, Fabien Pinckaers - Tiny sprl
 
40
"""
 
41
 
 
42
__author__ = 'Fabien Pinckaers, <fp@tiny.be>'
 
43
__version__ = '4.0.0'
 
44
 
 
45
import __builtin__
 
46
__builtin__.__dict__['tinyerp_version'] = __version__
 
47
__builtin__.__dict__['tinyerp_version_string'] = "Tiny ERP Server " + __version__
 
48
 
 
49
 
 
50
 
 
51
#----------------------------------------------------------
 
52
# python imports
 
53
#----------------------------------------------------------
 
54
import os, signal, sys
 
55
 
 
56
#----------------------------------------------------------
 
57
# get logger
 
58
#----------------------------------------------------------
 
59
import netsvc
 
60
 
 
61
netsvc.init_logger()
 
62
 
 
63
logger = netsvc.Logger()
 
64
 
 
65
#-----------------------------------------------------------------------
 
66
# import the tools module so that the commandline parameters are parsed
 
67
#-----------------------------------------------------------------------
 
68
import tools
 
69
 
 
70
if sys.platform=='win32':
 
71
        import mx.DateTime
 
72
        import time
 
73
        mx.DateTime.strptime = lambda x,y: mx.DateTime.mktime(time.strptime(x, y))
 
74
 
 
75
#os.chdir(tools.file_path_root)
 
76
 
 
77
#----------------------------------------------------------
 
78
# init net service
 
79
#----------------------------------------------------------
 
80
logger.notifyChannel("objects", netsvc.LOG_INFO, 'initialising distributed objects services')
 
81
 
 
82
dispatcher = netsvc.Dispatcher()
 
83
dispatcher.monitor(signal.SIGINT)
 
84
 
 
85
#---------------------------------------------------------------
 
86
# connect to the database and initialize it with base if needed
 
87
#---------------------------------------------------------------
 
88
logger.notifyChannel("init", netsvc.LOG_INFO, 'connecting to database')
 
89
 
 
90
import psycopg
 
91
import pooler
 
92
 
 
93
# try to connect to the database
 
94
try:
 
95
#       pooler.init()
 
96
        pass
 
97
except psycopg.OperationalError, err:
 
98
        logger.notifyChannel("init", netsvc.LOG_ERROR, "could not connect to database '%s'!" % (tools.config["db_name"],))
 
99
 
 
100
        msg = str(err).replace("FATAL:","").strip()
 
101
        db_msg = "database \"%s\" does not exist" % (tools.config["db_name"],)
 
102
        
 
103
        # Note: this is ugly but since psycopg only uses one exception for all errors
 
104
        # I don't think it's possible to do differently
 
105
        if msg == db_msg:
 
106
                print """
 
107
    this database does not exist
 
108
 
 
109
You need to create it using the command:
 
110
 
 
111
    createdb --encoding=UNICODE '%s'
 
112
 
 
113
When you run tinyerp-server for the first time it will initialise the
 
114
database. You may force this behaviour at a later time by using the command:
 
115
 
 
116
    ./tinyerp-server --init=all
 
117
 
 
118
Two accounts will be created by default:
 
119
    1. login: admin      password : admin
 
120
    2. login: demo       password : demo
 
121
 
 
122
""" % (tools.config["db_name"])
 
123
        else:
 
124
                print "\n    "+msg+"\n"
 
125
        sys.exit(1)
 
126
 
 
127
db_name = tools.config["db_name"]
 
128
 
 
129
# test whether it is needed to initialize the db (the db is empty)
 
130
try:
 
131
        cr = pooler.get_db_only(db_name).cursor()
 
132
except psycopg.OperationalError:
 
133
        logger.notifyChannel("init", netsvc.LOG_INFO, "could not connect to database '%s'!" % db_name,)
 
134
        cr = None
 
135
if cr:
 
136
        cr.execute("SELECT relname FROM pg_class WHERE relkind='r' AND relname='perm'")
 
137
        if len(cr.fetchall())==0:
 
138
#if False:
 
139
                print "init db"
 
140
                tools.init_db(cr)
 
141
                # in that case, force --init=all
 
142
                tools.config["init"]["all"] = 1
 
143
                tools.config['update']['all'] = 1
 
144
                if not tools.config['without_demo']:
 
145
                        tools.config["demo"]['all'] = 1
 
146
        cr.close()
 
147
 
 
148
#----------------------------------------------------------
 
149
# launch modules install/upgrade/removes if needed
 
150
#----------------------------------------------------------
 
151
if tools.config['upgrade']:
 
152
        print 'Upgrading new modules...'
 
153
        import tools.upgrade
 
154
        (toinit, toupdate) = tools.upgrade.upgrade()
 
155
        for m in toinit:
 
156
                tools.config['init'][m] = 1
 
157
        for m in toupdate:
 
158
                tools.config['update'][m] = 1
 
159
 
 
160
#----------------------------------------------------------
 
161
# import basic modules 
 
162
#----------------------------------------------------------
 
163
import osv, workflow, report, service
 
164
 
 
165
#----------------------------------------------------------
 
166
# import addons
 
167
#----------------------------------------------------------
 
168
import addons
 
169
 
 
170
addons.register_classes()
 
171
if tools.config['init'] or tools.config['update']:
 
172
        pooler.get_db_and_pool(tools.config['db_name'], update_module=True)
 
173
 
 
174
#----------------------------------------------------------
 
175
# translation stuff
 
176
#----------------------------------------------------------
 
177
if tools.config["translate_out"]:
 
178
        import csv
 
179
 
 
180
        logger.notifyChannel("init", netsvc.LOG_INFO, 'writing translation file for language %s to %s' % (tools.config["language"], tools.config["translate_out"]))
 
181
        trans=tools.trans_generate(tools.config["language"], tools.config["translate_modules"])
 
182
        writer=csv.writer(file(tools.config["translate_out"], "w"))
 
183
        for row in trans:
 
184
                writer.writerow(row)
 
185
        del trans
 
186
        logger.notifyChannel("init", netsvc.LOG_INFO, 'translation file written succesfully')
 
187
        sys.exit(0)
 
188
 
 
189
if tools.config["translate_in"]:
 
190
        tools.trans_load(tools.config["db_name"], tools.config["translate_in"], tools.config["language"])
 
191
        sys.exit(0)
 
192
 
 
193
#----------------------------------------------------------------------------------
 
194
# if we don't want the server to continue to run after initialization, we quit here
 
195
#----------------------------------------------------------------------------------
 
196
if tools.config["stop_after_init"]:
 
197
    sys.exit(0)
 
198
 
 
199
#----------------------------------------------------------
 
200
# Launch Server
 
201
#----------------------------------------------------------
 
202
try:
 
203
        port = int(tools.config["port"])
 
204
except Exception:
 
205
        logger.notifyChannel("init", netsvc.LOG_ERROR, "invalid port '%s'!" % (tools.config["port"],))
 
206
        sys.exit(1)
 
207
interface = tools.config["interface"]
 
208
secure = tools.config["secure"]
 
209
 
 
210
httpd = netsvc.HttpDaemon(interface,port, secure)
 
211
 
 
212
if tools.config["xmlrpc"]:
 
213
        xml_gw = netsvc.xmlrpc.RpcGateway('web-services')
 
214
        httpd.attach("/xmlrpc", xml_gw )
 
215
        logger.notifyChannel("web-services", netsvc.LOG_INFO, "starting XML-RPC services, port "+str(port))
 
216
 
 
217
#
 
218
#if tools.config["soap"]:
 
219
#       soap_gw = netsvc.xmlrpc.RpcGateway('web-services')
 
220
#       httpd.attach("/soap", soap_gw )
 
221
#       logger.notifyChannel("web-services", netsvc.LOG_INFO, 'starting SOAP services, port '+str(port))
 
222
#
 
223
if not (netsvc.HAS_SSL and tools.config['secure']):
 
224
        logger.notifyChannel("web-services", netsvc.LOG_INFO, "You are not using the SSL layer")
 
225
else:
 
226
        logger.notifyChannel("web-services", netsvc.LOG_INFO, "You are using the SSL Layer")
 
227
 
 
228
logger.notifyChannel("web-services", netsvc.LOG_INFO, 'the server is running, waiting for connections...')
 
229
 
 
230
 
 
231
httpd.start()
 
232
dispatcher.run()