def run_flaskserver(port, debug=False): from stoqlib.lib.environment import configure_locale # Force pt_BR for now. configure_locale('pt_BR') # Check drawer in a separated thread for function in WORKERS: gevent.spawn(function) try: from stoqserver.lib import stacktracer stacktracer.start_trace("/tmp/trace-stoqserver-flask.txt", interval=5, auto=True) except ImportError: pass app = bootstrap_app() app.debug = debug main.raven_client = Sentry(app, dsn=main.SENTRY_URL) @app.after_request def after_request(response): # Add all the CORS headers the POS needs to have its ajax requests # accepted by the browser origin = request.headers.get('origin') if not origin: origin = request.args.get('origin', request.form.get('origin', '*')) response.headers['Access-Control-Allow-Origin'] = origin response.headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS' response.headers['Access-Control-Allow-Headers'] = 'stoq-session, stoq-user, Content-Type' response.headers['Access-Control-Allow-Credentials'] = 'true' return response http_server = WSGIServer(('127.0.0.1', port), app, spawn=gevent.spawn_raw, log=log, error_log=log) http_server.serve_forever()
def begin(self): # The tests require that the environment is currently set to en_US, to avoid # translated strings and use the default date/number/currency formatting from stoqlib.lib.environment import configure_locale configure_locale('en_US') # FIXME python3: # This is to make our usage of contextlib.nested compatible for now @contextlib.contextmanager def _nested(*ctxs): with contextlib.ExitStack() as stack: yield tuple(stack.enter_context(ctx) for ctx in ctxs) contextlib.nested = _nested # If we import tests.base before Cover.setup() in the coverage plugin # is called the statistics will skip the modules imported by tests.base from stoqlib.database.testsuite import bootstrap_suite hostname = os.environ.get('STOQLIB_TEST_HOSTNAME') dbname = os.environ.get('STOQLIB_TEST_DBNAME') username = os.environ.get('STOQLIB_TEST_USERNAME') password = os.environ.get('STOQLIB_TEST_PASSWORD') port = int(os.environ.get('STOQLIB_TEST_PORT') or 0) quick = os.environ.get('STOQLIB_TEST_QUICK', None) is not None config = os.path.join( os.path.dirname(stoqlib.__file__), 'tests', 'config.py') if os.path.exists(config): exec(compile(open(config).read(), config, 'exec'), globals(), locals()) bootstrap_suite(address=hostname, dbname=dbname, port=port, username=username, password=password, quick=quick)
def run_flaskserver(port, debug=False, multiclient=False): from stoqlib.lib.environment import configure_locale # Force pt_BR for now. configure_locale('pt_BR') global is_multiclient is_multiclient = multiclient from .workers import WORKERS # For now we're disabling workers when stoqserver is serving multiple clients (multiclient mode) # FIXME: a proper solution would be to modify the workflow so that the clients ask the server # about devices health, the till status, etc. instead of the other way around. if not is_multiclient: for function in WORKERS: gevent.spawn(function, get_current_station(api.get_default_store())) try: from stoqserver.lib import stacktracer stacktracer.start_trace("/tmp/trace-stoqserver-flask.txt", interval=5, auto=True) except ImportError: pass app = bootstrap_app() app.debug = debug if not is_developer_mode(): sentry.raven_client = Sentry(app, dsn=SENTRY_URL, client=raven_client) @app.after_request def after_request(response): # Add all the CORS headers the POS needs to have its ajax requests # accepted by the browser origin = request.headers.get('origin') if not origin: origin = request.args.get('origin', request.form.get('origin', '*')) response.headers['Access-Control-Allow-Origin'] = origin response.headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS, DELETE' response.headers['Access-Control-Allow-Headers'] = 'Authorization, Content-Type' response.headers['Access-Control-Allow-Credentials'] = 'true' return response from stoqserver.lib.restful import has_sat, has_nfe logger.info('Starting wsgi server (has_sat=%s, has_nfe=%s)', has_sat, has_nfe) http_server = WSGIServer(('0.0.0.0', port), app, spawn=gevent.spawn_raw, log=logger, error_log=logger) if debug: gevent.spawn(_gtk_main_loop) @run_with_reloader def run_server(): http_server.serve_forever() run_server() else: http_server.serve_forever()
def interact(self, vars=None): if vars is not None: self.ns.update(vars) configure_locale() banner = self.get_console_banner() # PyCharm doesn't support colors and tabs if USE_IPYTHON: config = Config() if 'PYCHARM_HOSTED' in os.environ: config.TerminalInteractiveShell.colors = 'NoColor' embed(config=config, user_ns=self.ns, banner1=banner) else: readline.parse_and_bind("tab: complete") code.interact(local=self.ns, banner=banner)
def run_flaskserver(port, debug=False, multiclient=False): from stoqlib.lib.environment import configure_locale # Force pt_BR for now. configure_locale('pt_BR') from .workers import WORKERS # For now we're disabling workers when stoqserver is serving multiple clients (multiclient mode) # FIXME: a proper solution would be to modify the workflow so that the clients ask the server # about devices health, the till status, etc. instead of the other way around. if not multiclient: for function in WORKERS: gevent.spawn(function, get_current_station(api.get_default_store())) try: from stoqserver.lib import stacktracer stacktracer.start_trace("/tmp/trace-stoqserver-flask.txt", interval=5, auto=True) except ImportError: pass app = bootstrap_app(debug, multiclient) from stoqserver.lib.restful import has_sat, has_nfe logger.info('Starting wsgi server (has_sat=%s, has_nfe=%s)', has_sat, has_nfe) http_server = WSGIServer(('0.0.0.0', port), app, spawn=gevent.spawn_raw, log=logger, error_log=logger) if debug: gevent.spawn(_gtk_main_loop) @run_with_reloader def run_server(): http_server.serve_forever() run_server() else: http_server.serve_forever()
def interact(self, vars=None): # Keep this imports here since they only work on linux import readline import code import rlcompleter rlcompleter # pylint: disable=W0104 if vars is not None: self.ns.update(vars) configure_locale() banner = self.get_console_banner() # PyCharm doesn't support colors and tabs if USE_IPYTHON: config = Config() if 'PYCHARM_HOSTED' in os.environ: config.TerminalInteractiveShell.colors = 'NoColor' embed(config=config, user_ns=self.ns, banner1=banner) else: readline.parse_and_bind("tab: complete") code.interact(local=self.ns, banner=banner)
def _set_user_locale(self): from stoqlib.lib.environment import configure_locale from stoqlib.lib.settings import get_settings from stoqlib.lib.translation import stoqlib_gettext as _ # We only support pt_BR in Windows and we need to set LC_ALL # or we might run in some problems in case it is not set. # We are settings os.environ directly beucase locale.setlocale # doesn't work on Windows if platform.system() == 'Windows': lang = 'pt_BR.UTF_8' os.environ['LC_ALL'] = lang os.environ['LANGUAGE'] = lang return settings = get_settings() lang = settings.get('user-locale', None) try: configure_locale(lang) except locale.Error as err: msg = _("Could not set locale to %s. Make sure that you have " "the packages for this locale installed.") % lang[:-6] self._locale_error = (msg, err) log.warning(msg)
def main(args): args = args[1:] if not args: # defaults to help args.append('help') cmd = args[0] args = args[1:] from stoqlib.lib.environment import configure_locale configure_locale() # import library or else externals won't be on sys.path from stoqlib.lib.kiwilibrary import library library # pylint: disable=W0104 from stoq.lib.options import get_option_parser parser = get_option_parser() handler = StoqCommandHandler(parser.get_prog_name()) handler.add_options(parser, cmd) options, args = parser.parse_args(args) return handler.run_command(options, cmd, args)