3
##############################################################################
5
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be)
7
# $Id: tinyerp-server.py 1308 2005-09-08 18:02:01Z pinky $
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
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.
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.
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.
30
##############################################################################
34
Tiny ERP is an ERP+CRM program for small and medium businesses.
36
The whole source code is distributed under the terms of the
39
(c) 2003-TODAY, Fabien Pinckaers - Tiny sprl
42
__author__ = 'Fabien Pinckaers, <fp@tiny.be>'
46
__builtin__.__dict__['tinyerp_version'] = __version__
47
__builtin__.__dict__['tinyerp_version_string'] = "Tiny ERP Server " + __version__
51
#----------------------------------------------------------
53
#----------------------------------------------------------
54
import os, signal, sys
56
#----------------------------------------------------------
58
#----------------------------------------------------------
63
logger = netsvc.Logger()
65
#-----------------------------------------------------------------------
66
# import the tools module so that the commandline parameters are parsed
67
#-----------------------------------------------------------------------
70
if sys.platform=='win32':
73
mx.DateTime.strptime = lambda x,y: mx.DateTime.mktime(time.strptime(x, y))
75
#os.chdir(tools.file_path_root)
77
#----------------------------------------------------------
79
#----------------------------------------------------------
80
logger.notifyChannel("objects", netsvc.LOG_INFO, 'initialising distributed objects services')
82
dispatcher = netsvc.Dispatcher()
83
dispatcher.monitor(signal.SIGINT)
85
#---------------------------------------------------------------
86
# connect to the database and initialize it with base if needed
87
#---------------------------------------------------------------
88
logger.notifyChannel("init", netsvc.LOG_INFO, 'connecting to database')
93
# try to connect to the database
97
except psycopg.OperationalError, err:
98
logger.notifyChannel("init", netsvc.LOG_ERROR, "could not connect to database '%s'!" % (tools.config["db_name"],))
100
msg = str(err).replace("FATAL:","").strip()
101
db_msg = "database \"%s\" does not exist" % (tools.config["db_name"],)
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
107
this database does not exist
109
You need to create it using the command:
111
createdb --encoding=UNICODE '%s'
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:
116
./tinyerp-server --init=all
118
Two accounts will be created by default:
119
1. login: admin password : admin
120
2. login: demo password : demo
122
""" % (tools.config["db_name"])
127
db_name = tools.config["db_name"]
129
# test whether it is needed to initialize the db (the db is empty)
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,)
136
cr.execute("SELECT relname FROM pg_class WHERE relkind='r' AND relname='perm'")
137
if len(cr.fetchall())==0:
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
148
#----------------------------------------------------------
149
# launch modules install/upgrade/removes if needed
150
#----------------------------------------------------------
151
if tools.config['upgrade']:
152
print 'Upgrading new modules...'
154
(toinit, toupdate) = tools.upgrade.upgrade()
156
tools.config['init'][m] = 1
158
tools.config['update'][m] = 1
160
#----------------------------------------------------------
161
# import basic modules
162
#----------------------------------------------------------
163
import osv, workflow, report, service
165
#----------------------------------------------------------
167
#----------------------------------------------------------
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)
174
#----------------------------------------------------------
176
#----------------------------------------------------------
177
if tools.config["translate_out"]:
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"))
186
logger.notifyChannel("init", netsvc.LOG_INFO, 'translation file written succesfully')
189
if tools.config["translate_in"]:
190
tools.trans_load(tools.config["db_name"], tools.config["translate_in"], tools.config["language"])
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"]:
199
#----------------------------------------------------------
201
#----------------------------------------------------------
203
port = int(tools.config["port"])
205
logger.notifyChannel("init", netsvc.LOG_ERROR, "invalid port '%s'!" % (tools.config["port"],))
207
interface = tools.config["interface"]
208
secure = tools.config["secure"]
210
httpd = netsvc.HttpDaemon(interface,port, secure)
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))
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))
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")
226
logger.notifyChannel("web-services", netsvc.LOG_INFO, "You are using the SSL Layer")
228
logger.notifyChannel("web-services", netsvc.LOG_INFO, 'the server is running, waiting for connections...')