Merge lp:~jr.allen/unifield-web/us-2080 into lp:unifield-web

Proposed by Jeff Allen
Status: Merged
Merged at revision: 4835
Proposed branch: lp:~jr.allen/unifield-web/us-2080
Merge into: lp:unifield-web
Diff against target: 313 lines (+134/-34)
7 files modified
doc/openerp-web-oc.cfg (+6/-0)
openerp-web.py (+1/-1)
openobject/commands.py (+92/-2)
openobject/i18n/_gettext.py (+10/-10)
setup.nsi (+1/-0)
setup.py (+16/-15)
win32/OpenERPWebService.py (+8/-6)
To merge this branch: bzr merge lp:~jr.allen/unifield-web/us-2080
Reviewer Review Type Date Requested Status
jftempo Pending
Review via email: mp+317322@code.launchpad.net
To post a comment you must log in.
lp:~jr.allen/unifield-web/us-2080 updated
4840. By Jeff Allen

merge

4841. By Jeff Allen

pyflakes fixes. To avoid a race, move the signal where it should have been all along. Update revprox to handle LetsEncrypt automatically.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'doc/openerp-web-oc.cfg'
--- doc/openerp-web-oc.cfg 2016-06-08 10:23:06 +0000
+++ doc/openerp-web-oc.cfg 2017-02-16 14:13:31 +0000
@@ -8,3 +8,9 @@
8#server.environment = "red"8#server.environment = "red"
9#server.environment = "blue"9#server.environment = "blue"
1010
11# HTTPS server
12# To enable the HTTPS wrapper server (revprox.exe) set this to the
13# fully qualified domain name of the server, and arrange for this to
14# resolve in local DNS to the Unifield server machine's IP address.
15
16# server.https_name = "THIS-INSTANCE.prod.unifield.org"
1117
=== modified file 'openerp-web.py'
--- openerp-web.py 2010-09-15 17:46:36 +0000
+++ openerp-web.py 2017-02-16 14:13:31 +0000
@@ -1,5 +1,5 @@
1#!/usr/bin/env python1#!/usr/bin/env python
2# -*- coding: UTF-8 -*-2# -*- coding: utf-8 -*-
3"""Start script for the openerp-web project.3"""Start script for the openerp-web project.
44
5This script is only needed during development for running from the project5This script is only needed during development for running from the project
66
=== modified file 'openobject/commands.py'
--- openobject/commands.py 2016-01-18 08:45:32 +0000
+++ openobject/commands.py 2017-02-16 14:13:31 +0000
@@ -1,9 +1,10 @@
1import os1import os
2import sys2import sys
3import time
4import subprocess
5import threading
3from optparse import OptionParser6from optparse import OptionParser
47
5import babel.localedata
6
7import cherrypy8import cherrypy
8try:9try:
9 from cherrypy.lib.reprconf import as_dict10 from cherrypy.lib.reprconf import as_dict
@@ -81,6 +82,15 @@
81 if options.static:82 if options.static:
82 openobject.enable_static_paths()83 openobject.enable_static_paths()
8384
85 # Try to start revprox now so that we know what default to set for
86 # port number (revprox ok? port = 18061)
87 if options.port is None:
88 options.port = cherrypy.config.get('server.socket_port', 8061)
89 if revprox(options.port):
90 options.port = 18061
91 options.address = '127.0.0.1'
92 cherrypy.config['tools.proxy.on'] = True
93
84 if options.address:94 if options.address:
85 cherrypy.config['server.socket_host'] = options.address95 cherrypy.config['server.socket_host'] = options.address
86 if options.port:96 if options.port:
@@ -89,6 +99,7 @@
89 except:99 except:
90 pass100 pass
91 port = cherrypy.config.get('server.socket_port')101 port = cherrypy.config.get('server.socket_port')
102
92 if not isinstance(port, (int, long)) or port < 1 or port > 65535:103 if not isinstance(port, (int, long)) or port < 1 or port > 65535:
93 cherrypy.log('Wrong configuration socket_port: %s' % (port,), "ERROR")104 cherrypy.log('Wrong configuration socket_port: %s' % (port,), "ERROR")
94 raise ConfigurationError(_("Wrong configuration socket_port: %s") %105 raise ConfigurationError(_("Wrong configuration socket_port: %s") %
@@ -122,3 +133,82 @@
122133
123def stop():134def stop():
124 cherrypy.engine.exit()135 cherrypy.engine.exit()
136
137# Try to start the reverse proxy. If anything goes wrong, return
138# False. Launch a thread which monitors it's output, copying it to
139# cherrypy.log, and kills the server if revproxy dies.
140def revprox(redir_port):
141 ctx = "REVPROX"
142
143 https_name = cherrypy.config.get('server.https_name')
144 if not https_name:
145 cherrypy.log("server.https_name is not set, not running the reverse proxy", ctx)
146 return False
147
148 rbin = 'revprox'
149 if sys.platform == 'win32':
150 rbin += '.exe'
151 rbin = os.path.abspath(openobject.paths.root('revprox', rbin))
152 if not os.path.exists(rbin):
153 cherrypy.log("%s does not exist, not running the reverse proxy." % rbin, ctx)
154 return False
155
156 cmd = [ rbin, '-server', https_name, '-redir', str(redir_port) ]
157 if cherrypy.config.get('server.use_letsencrypt', False):
158 cmd.append('-usele')
159 proc = subprocess.Popen(cmd,
160 stderr=subprocess.STDOUT, # Merge stdout and stderr
161 stdout=subprocess.PIPE)
162 ok = False
163 while not ok:
164 line = proc.stdout.readline()
165 if line != '':
166 line = line.strip().split(" ", 2)
167 cherrypy.log(line[-1], ctx)
168 if line[-1] == 'Startup OK.':
169 ok = True
170 else:
171 # Process exited
172 break
173
174 if not ok:
175 cherrypy.log("reverse proxy exited without starting up", ctx)
176 return False
177
178 # It started correctly. So arrange that it's logs are copied
179 # and that it is killed on shutdown.
180
181 def logRead(proc):
182 while True:
183 line = proc.stdout.readline()
184 if line != '':
185 line = line.split(" ", 2)
186 cherrypy.log(line[-1].strip(), ctx)
187 else:
188 break
189 rc = proc.wait()
190 cherrypy.log("reverse proxy exited (rc=%d)." % rc, ctx)
191 if rc != 0:
192 # revprox exited with an error, so tell cherrypy to exit too.
193 # We will be restarted by the system (see setup.nsi: "sc failure...")
194 cherrypy.engine.stop()
195 # However, if it gets stuck on "Bus STOPPED", use exit to be sure
196 time.sleep(5)
197 os._exit(1)
198 return
199
200 thread = threading.Thread(target=logRead, args=[proc])
201 thread.start()
202
203 # A callback to register on stop, for killing revprox.
204 def _cb(p):
205 cherrypy.log("stopping", ctx)
206 try:
207 p.terminate()
208 except OSError:
209 # Probably "no such process", which is ok.
210 pass
211
212 cherrypy.engine.subscribe('stop', lambda p=proc: _cb(p))
213 return True
214
125215
=== modified file 'openobject/i18n/_gettext.py'
--- openobject/i18n/_gettext.py 2011-05-10 13:22:29 +0000
+++ openobject/i18n/_gettext.py 2017-02-16 14:13:31 +0000
@@ -62,9 +62,9 @@
62 with open(popath, 'rb') as pofile:62 with open(popath, 'rb') as pofile:
63 with open(mopath, 'wb') as mofile:63 with open(mopath, 'wb') as mofile:
64 babel.messages.mofile.write_mo(64 babel.messages.mofile.write_mo(
65 mofile,65 mofile,
66 babel.messages.pofile.read_po(66 babel.messages.pofile.read_po(
67 pofile, locale, domain))67 pofile, locale, domain))
68 except Exception:68 except Exception:
69 # If the parsing of the PO file broke, don't leave an empty MO69 # If the parsing of the PO file broke, don't leave an empty MO
70 # file hanging around70 # file hanging around
@@ -75,7 +75,7 @@
75 raise75 raise
7676
77 return babel.support.Translations.load(77 return babel.support.Translations.load(
78 locale_path, [locale], domain)78 locale_path, [locale], domain)
7979
80def _load_translations(path, locales, domain):80def _load_translations(path, locales, domain):
81 if not locales:81 if not locales:
@@ -94,11 +94,11 @@
94 except SyntaxError:94 except SyntaxError:
95 # http://babel.edgewall.org/ticket/21395 # http://babel.edgewall.org/ticket/213
96 cherrypy.log.error(96 cherrypy.log.error(
97 'Could not load translation domain "%s" for'97 'Could not load translation domain "%s" for'
98 ' locale "%s" in addon %s' % (98 ' locale "%s" in addon %s' % (
99 domain, locale, basename(path)),99 domain, locale, basename(path)),
100 context="i18n",100 context="i18n",
101 severity=logging.WARNING)101 severity=logging.WARNING)
102 cherrypy.log.error(context='i18n', severity=logging.DEBUG,102 cherrypy.log.error(context='i18n', severity=logging.DEBUG,
103 traceback=True)103 traceback=True)
104 if isinstance(translation, babel.support.Translations):104 if isinstance(translation, babel.support.Translations):
@@ -184,7 +184,7 @@
184_lazy_gettext = lazify(_gettext)184_lazy_gettext = lazify(_gettext)
185185
186def gettext(key, locale=None, domain=None):186def gettext(key, locale=None, domain=None):
187 if cherrypy.request.loading_addons:187 if hasattr(cherrypy.request, "loading_addons") and cherrypy.request.loading_addons:
188 return _lazy_gettext(key, locale, domain)188 return _lazy_gettext(key, locale, domain)
189 return _gettext(key, locale, domain)189 return _gettext(key, locale, domain)
190190
191191
=== added directory 'revprox'
=== added file 'revprox/revprox.exe'
192Binary files revprox/revprox.exe 1970-01-01 00:00:00 +0000 and revprox/revprox.exe 2017-02-16 14:13:31 +0000 differ192Binary files revprox/revprox.exe 1970-01-01 00:00:00 +0000 and revprox/revprox.exe 2017-02-16 14:13:31 +0000 differ
=== modified file 'setup.nsi'
--- setup.nsi 2016-10-27 09:40:52 +0000
+++ setup.nsi 2017-02-16 14:13:31 +0000
@@ -170,6 +170,7 @@
170Section -RestartService170Section -RestartService
171 nsExec::Exec '"$INSTDIR\service\OpenERPWebService.exe" -auto -install'171 nsExec::Exec '"$INSTDIR\service\OpenERPWebService.exe" -auto -install'
172 sleep 2172 sleep 2
173 nsExec::Exec 'sc failure openerp-web-6.0 reset= 0 actions= restart/0/restart/0/restart/0'
173 nsExec::Exec "sc config openerp-web-6.0 depend= openerp-server-6.0"174 nsExec::Exec "sc config openerp-web-6.0 depend= openerp-server-6.0"
174 nsExec::Exec "net start openerp-web-6.0"175 nsExec::Exec "net start openerp-web-6.0"
175 sleep 2176 sleep 2
176177
=== modified file 'setup.py'
--- setup.py 2013-02-04 09:09:45 +0000
+++ setup.py 2017-02-16 14:13:31 +0000
@@ -24,12 +24,12 @@
24 'win32serviceutil',24 'win32serviceutil',
25 ])25 ])
26 opts['options']['py2exe'].update(26 opts['options']['py2exe'].update(
27 skip_archive=1,27 skip_archive=1,
28 compressed=0,28 compressed=0,
29 bundle_files=3,29 bundle_files=3,
30 optimize=0,30 optimize=0,
31 collected_libs_dir='libs',31 collected_libs_dir='libs',
32 collected_libs_data_relocate='babel,pytz',32 collected_libs_data_relocate='babel,pytz',
33 )33 )
34 opts.setdefault('data_files', []).extend(fixup_data_pytz_zoneinfo())34 opts.setdefault('data_files', []).extend(fixup_data_pytz_zoneinfo())
35 opts.update(cmdclass={'py2exe': custom_py2exe},)35 opts.update(cmdclass={'py2exe': custom_py2exe},)
@@ -99,16 +99,17 @@
99 'Programming Language :: Python',99 'Programming Language :: Python',
100 'Environment :: Web Environment',100 'Environment :: Web Environment',
101 'Topic :: Office/Business :: Financial',101 'Topic :: Office/Business :: Financial',
102 ],102 ],
103 scripts=['scripts/openerp-web'],103 scripts=['scripts/openerp-web'],
104 data_files=(find_data_files('addons/openerp')104 data_files=(find_data_files('addons/openerp')
105 + find_data_files('addons/view_calendar')105 + find_data_files('addons/view_calendar')
106 + find_data_files('addons/view_diagram')106 + find_data_files('addons/view_diagram')
107 + find_data_files('addons/view_graph')107 + find_data_files('addons/view_graph')
108 + find_data_files('addons/widget_ckeditor')108 + find_data_files('addons/widget_ckeditor')
109 + find_data_files('doc', patterns='')109 + find_data_files('doc', patterns='')
110 + find_data_files('openobject', patterns=r'.+\.(cfg|css|js|mako|gif|png|jpg|ico)')110 + find_data_files('openobject', patterns=r'.+\.(cfg|css|js|mako|gif|png|jpg|ico)')
111 + opts.pop('data_files', [])111 + find_data_files('revprox', patterns='')
112 ),112 + opts.pop('data_files', [])
113 ),
113 **opts114 **opts
114)115)
115116
=== modified file 'win32/OpenERPWebService.py'
--- win32/OpenERPWebService.py 2013-02-04 09:06:57 +0000
+++ win32/OpenERPWebService.py 2017-02-16 14:13:31 +0000
@@ -20,7 +20,6 @@
20##############################################################################20##############################################################################
2121
22# Win32 python extensions modules22# Win32 python extensions modules
23import win32con
24import win32serviceutil23import win32serviceutil
25import win32service24import win32service
26import win32event25import win32event
@@ -54,11 +53,13 @@
54 def SvcStop(self):53 def SvcStop(self):
55 # Before we do anything, tell the SCM we are starting the stop process.54 # Before we do anything, tell the SCM we are starting the stop process.
56 self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)55 self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
57 # stop the running OpenERP Web: say it's a normal exit
58 win32api.TerminateProcess(int(self.openerp_process._handle), 0)
59 servicemanager.LogInfoMsg("OpenERP Web stopped correctly")
60 # And set my event.56 # And set my event.
61 win32event.SetEvent(self.hWaitStop)57 win32event.SetEvent(self.hWaitStop)
58 # stop the running OpenERP Web and any children (i.e. revprox.exe)
59 pid = str(self.openerp_process.pid)
60 subprocess.call(['taskkill', '/F', '/T', '/PID', pid])
61 self.openerp_process = None
62 servicemanager.LogInfoMsg("OpenERP Web stopped correctly")
62 self.ReportServiceStatus(win32service.SERVICE_STOPPED)63 self.ReportServiceStatus(win32service.SERVICE_STOPPED)
6364
64 def StartOpenERP(self):65 def StartOpenERP(self):
@@ -69,7 +70,7 @@
69 service_dir = os.path.dirname(sys.argv[0])70 service_dir = os.path.dirname(sys.argv[0])
70 server_dir = os.path.split(service_dir)[0]71 server_dir = os.path.split(service_dir)[0]
71 server_path = os.path.join(server_dir, 'openerp-web.exe')72 server_path = os.path.join(server_dir, 'openerp-web.exe')
72 result = win32api.SetConsoleCtrlHandler(self.handle, 1)73 win32api.SetConsoleCtrlHandler(self.handle, 1)
7374
74 self.openerp_process = subprocess.Popen([server_path], cwd=server_dir, creationflags=win32process.CREATE_NO_WINDOW)75 self.openerp_process = subprocess.Popen([server_path], cwd=server_dir, creationflags=win32process.CREATE_NO_WINDOW)
7576
@@ -92,7 +93,8 @@
92 # verification if the server is really running, else quit with an error93 # verification if the server is really running, else quit with an error
93 self.openerp_process.wait()94 self.openerp_process.wait()
94 if not self.stopping:95 if not self.stopping:
95 sys.exit("OpenERP Web check: server not running, check the logfile for more info")96 servicemanager.LogInfoMsg("openerp-web child process died unexpectedly, exiting now")
97 os._exit(1)
9698
97if __name__=='__main__':99if __name__=='__main__':
98 # Do with the service whatever option is passed in the command line100 # Do with the service whatever option is passed in the command line

Subscribers

People subscribed via source and target branches

to all changes: