19.1.1. camcops_server.camcops¶
Copyright (C) 2012-2018 Rudolf Cardinal (rudolf@pobox.com).
This file is part of CamCOPS.
CamCOPS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
CamCOPS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with CamCOPS. If not, see <http://www.gnu.org/licenses/>.
-
camcops_server.camcops.
add_sub
(sp: _SubParsersAction, cmd: str, config_mandatory: Union[bool, NoneType] = False, description: str = None, help: str = None) → argparse.ArgumentParser[source]¶ - help:
- Used for the main help summary, i.e. “camcops –help”.
- description:
- Used for the description in the detailed help, e.g. “camcops docs –help”. Defaults to “help”.
- config_mandatory:
- None = don’t ask for config False = ask for it, but not mandatory True = mandatory
-
camcops_server.camcops.
camcops_main
() → None[source]¶ Command-line entry point.
Note that we can’t easily use delayed imports to speed up the help output, because the help system has function calls embedded into it.
-
camcops_server.camcops.
enable_user_cli
(username: str = None) → bool[source]¶ Re-enable a locked user account from the command line.
-
camcops_server.camcops.
make_superuser
(username: str = None) → bool[source]¶ Make a superuser from the command line.
-
camcops_server.camcops.
make_wsgi_app
(debug_toolbar: bool = False, reverse_proxied_config: cardinal_pythonlib.wsgi.reverse_proxied_mw.ReverseProxiedConfig = None, debug_reverse_proxy: bool = False) → pyramid.router.Router[source]¶ Makes and returns a WSGI application, attaching all our special methods.
QUESTION: how do we access the WSGI environment (passed to the WSGI app) from within a Pyramid request? ANSWER:
Configurator.make_wsgi_app() calls Router.__init__() and returns: app = Router(...) The WSGI framework uses: response = app(environ, start_response) which therefore calls: Router.__call__(environ, start_response) which does: response = self.execution_policy(environ, self) return response(environ, start_response) So something LIKE this will be called: Router.default_execution_policy(environ, router) with router.request_context(environ) as request: # ... So the environ is handled by Router.request_context(environ) which will call BaseRequest.__init__() which does: d = self.__dict__ d['environ'] = environ so we should be able to use request.environ # type: Dict[str, str]
-
camcops_server.camcops.
reset_password
(username: str = None) → bool[source]¶ Reset a password from the command line.
-
camcops_server.camcops.
serve_cherrypy
(application: pyramid.router.Router, host: str, port: int, unix_domain_socket_filename: str, threads_start: int, threads_max: int, server_name: str, log_screen: bool, ssl_certificate: Union[str, NoneType], ssl_private_key: Union[str, NoneType], root_path: str) → None[source]¶ Start CherryPy server - Multithreading. - Any platform.
-
camcops_server.camcops.
serve_gunicorn
(application: pyramid.router.Router, host: str, port: int, unix_domain_socket_filename: str, num_workers: int, ssl_certificate: Union[str, NoneType], ssl_private_key: Union[str, NoneType], reload: bool = False, timeout_s: int = 30, debug_show_gunicorn_options: bool = False) → None[source]¶ Start Gunicorn server
- Multiprocessing; this is a Good Thing particularly in Python; see e.g. https://eli.thegreenplace.net/2012/01/16/python-parallelizing-cpu-bound-tasks-with-multiprocessing/ # noqa http://www.dabeaz.com/python/UnderstandingGIL.pdf
- UNIX only.
- The Pyramid debug toolbar detects a multiprocessing web server and says “shan’t, because I use global state”.