[IMP] Refactoring, resulting from pylint
[IMP] Improve the signal management bzr revid: stephane@tinyerp.com-20081223233842-xkn2tc0g6kk7pryy
This commit is contained in:
parent
12cd0b5e7d
commit
ad6871c77c
|
@ -125,7 +125,9 @@ if tools.config["translate_out"]:
|
|||
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"]))
|
||||
logger.notifyChannel("init", netsvc.LOG_INFO,
|
||||
'writing translation file for %s to %s' % (msg,
|
||||
tools.config["translate_out"]))
|
||||
|
||||
fileformat = os.path.splitext(tools.config["translate_out"])[-1][1:].lower()
|
||||
buf = file(tools.config["translate_out"], "w")
|
||||
|
@ -136,7 +138,9 @@ if tools.config["translate_out"]:
|
|||
sys.exit(0)
|
||||
|
||||
if tools.config["translate_in"]:
|
||||
tools.trans_load(tools.config["db_name"], tools.config["translate_in"], tools.config["language"])
|
||||
tools.trans_load(tools.config["db_name"],
|
||||
tools.config["translate_in"],
|
||||
tools.config["language"])
|
||||
sys.exit(0)
|
||||
|
||||
#----------------------------------------------------------------------------------
|
||||
|
@ -153,8 +157,9 @@ if tools.config["stop_after_init"]:
|
|||
if tools.config['xmlrpc']:
|
||||
try:
|
||||
port = int(tools.config["port"])
|
||||
except Exception:
|
||||
logger.notifyChannel("init", netsvc.LOG_CRITICAL, "invalid port: %r" % (tools.config["port"],))
|
||||
except:
|
||||
logger.notifyChannel("init", netsvc.LOG_CRITICAL,
|
||||
"invalid port: %r" % (tools.config["port"],))
|
||||
sys.exit(1)
|
||||
interface = tools.config["interface"]
|
||||
secure = tools.config["secure"]
|
||||
|
@ -163,7 +168,9 @@ if tools.config['xmlrpc']:
|
|||
|
||||
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))
|
||||
logger.notifyChannel("web-services", netsvc.LOG_INFO,
|
||||
"starting XML-RPC%s services, port %s" % (
|
||||
(tools.config['secure'] and ' Secure' or ''), port))
|
||||
|
||||
#
|
||||
#if tools.config["soap"]:
|
||||
|
@ -175,17 +182,25 @@ if tools.config['xmlrpc']:
|
|||
if tools.config['netrpc']:
|
||||
try:
|
||||
netport = int(tools.config["netport"])
|
||||
except Exception:
|
||||
logger.notifyChannel("init", netsvc.LOG_ERROR, "invalid port '%s'!" % (tools.config["netport"],))
|
||||
except:
|
||||
logger.notifyChannel("init", netsvc.LOG_ERROR,
|
||||
"invalid port '%s'!" % (tools.config["netport"],))
|
||||
sys.exit(1)
|
||||
netinterface = tools.config["netinterface"]
|
||||
|
||||
tinySocket = netsvc.TinySocketServerThread(netinterface, netport, False)
|
||||
logger.notifyChannel("web-services", netsvc.LOG_INFO, "starting NET-RPC service, port "+str(netport))
|
||||
logger.notifyChannel("web-services", netsvc.LOG_INFO,
|
||||
"starting NET-RPC service, port %d" % (netport,))
|
||||
|
||||
SIGNALS = dict(
|
||||
[(getattr(signal, sign), sign) for sign in ('SIGINT', 'SIGTERM', 'SIGUSR1', 'SIGQUIT')]
|
||||
)
|
||||
|
||||
def handler(signum, frame):
|
||||
from tools import config
|
||||
def handler(signum, _):
|
||||
"""
|
||||
:param signum: the signal number
|
||||
:param _:
|
||||
"""
|
||||
if tools.config['netrpc']:
|
||||
tinySocket.stop()
|
||||
if tools.config['xmlrpc']:
|
||||
|
@ -193,9 +208,13 @@ def handler(signum, frame):
|
|||
netsvc.Agent.quit()
|
||||
if config['pidfile']:
|
||||
os.unlink(config['pidfile'])
|
||||
logger.notifyChannel('shutdown', netsvc.LOG_INFO, "Shutdown Server!")
|
||||
logger.notifyChannel('shutdown', netsvc.LOG_INFO,
|
||||
"Shutdown Server! - %s" % ( SIGNALS[signum], ))
|
||||
sys.exit(0)
|
||||
|
||||
for signum in SIGNALS:
|
||||
signal.signal(signum, handler)
|
||||
|
||||
from tools import config
|
||||
if config['pidfile']:
|
||||
fd = open(config['pidfile'], 'w')
|
||||
|
@ -203,10 +222,9 @@ if config['pidfile']:
|
|||
fd.write(pidtext)
|
||||
fd.close()
|
||||
|
||||
for sign in ('SIGINT', 'SIGTERM', 'SIGUSR1', 'SIGQUIT'):
|
||||
signal.signal(getattr(signal, sign), handler)
|
||||
logger.notifyChannel("web-services", netsvc.LOG_INFO,
|
||||
'the server is running, waiting for connections...')
|
||||
|
||||
logger.notifyChannel("web-services", netsvc.LOG_INFO, 'the server is running, waiting for connections...')
|
||||
if tools.config['netrpc']:
|
||||
tinySocket.start()
|
||||
if tools.config['xmlrpc']:
|
||||
|
|
Loading…
Reference in New Issue