def _read_config(self, options, create=False, register_station=True, check_schema=True, load_plugins=True): from stoqlib.lib.configparser import StoqConfig from stoq.lib.startup import setup config = StoqConfig() if options.load_config and options.filename: config.load(options.filename) else: config.load_default() if create: config.create() # FIXME: This should be removed and we should just import # the global settings after fixing StoqConfig to # only update the global settings. self._db_settings = config.get_settings() setup(config, options, register_station=register_station, check_schema=check_schema, load_plugins=load_plugins) return config
def main(args): handler = StoqServerCmdHandler() if not args: handler.cmd_help() return 1 cmd = args[0] args = args[1:] parser = get_option_parser() handler.add_options(cmd, parser) options, args = parser.parse_args(args) config = StoqConfig() filename = (options.filename if options.load_config and options.filename else APP_CONF_FILE) config.load(filename) # FIXME: This is called only when register_station=True. Without # this, db_settings would not be updated. We should fix it on Stoq config.get_settings() register_config(config) # FIXME: Maybe we should check_schema and load plugins here? setup(config=config, options=options, register_station=False, check_schema=False, load_plugins=True) handler.run_cmd(cmd, options, *args)
def _try_connect(self): from stoqlib.lib.message import error try: store_dsn = self._config.get_settings().get_store_dsn() except: type, value, trace = sys.exc_info() error( _("Could not open the database config file"), _("Invalid config file settings, got error '%s', " "of type '%s'") % (value, type)) from stoqlib.database.exceptions import PostgreSQLError from stoq.lib.startup import setup # XXX: progress dialog for connecting (if it takes more than # 2 seconds) or creating the database log.debug('calling setup()') try: setup(self._config, self._options, register_station=False, check_schema=False, load_plugins=False) except (StoqlibError, PostgreSQLError) as e: error(_('Could not connect to the database'), 'error=%s uri=%s' % (str(e), store_dsn))
def _setup_stoq(self): info = AppInfo() info.set('name', "stoqserver") info.set('version', stoqserver.version_str) info.set('ver', stoqserver.version_str) provide_utility(IAppInfo, info, replace=True) # FIXME: Maybe we should check_schema and load plugins here? setup(config=get_config(), options=None, register_station=False, check_schema=False, load_plugins=True)
def setup_stoq(): info = AppInfo() info.set('name', "stoqserver") info.set('version', stoqserver.version_str) info.set('ver', stoqserver.version_str) provide_utility(IAppInfo, info, replace=True) # FIXME: Maybe we should check_schema and load plugins here? setup(config=get_config(), options=None, register_station=False, check_schema=False, load_plugins=True)
def _try_connect(self): from stoqlib.lib.message import error try: store_uri = self._config.get_settings().get_store_uri() except: type, value, trace = sys.exc_info() error( _("Could not open the database config file"), _("Invalid config file settings, got error '%s', " "of type '%s'") % (value, type)) from stoqlib.database.exceptions import PostgreSQLError from stoqlib.database.runtime import get_default_store from stoqlib.exceptions import DatabaseError from stoqlib.lib.pgpass import write_pg_pass from stoq.lib.startup import setup # XXX: progress dialog for connecting (if it takes more than # 2 seconds) or creating the database log.debug('calling setup()') try: setup(self._config, self._options, register_station=False, check_schema=False, load_plugins=False) # the setup call above is not really trying to connect (since # register_station, check_schema and load_plugins are all False). # Try to really connect here. get_default_store() except (StoqlibError, PostgreSQLError) as e: log.debug('Connection failed.') error(_('Could not connect to the database'), 'error=%s uri=%s' % (str(e), store_uri)) except DatabaseError: log.debug('Connection failed. Tring to setup .pgpass') # This is probably a missing password configuration. Setup the # pgpass file and try again. try: password = self._get_password() if not password: # There is no password stored in data file. Abort raise from stoqlib.database.settings import db_settings write_pg_pass(db_settings.dbname, db_settings.address, db_settings.port, db_settings.username, password) # Now that there is a pg_pass file, try to connect again get_default_store() except DatabaseError as e: log.debug('Connection failed again.') error(_('Could not connect to the database'), 'error=%s uri=%s' % (str(e), store_uri))
def load_config_and_call_setup(self): dbargs = self.settings.get_command_line_arguments() parser = get_option_parser() db_options, unused_args = parser.parse_args(dbargs) self.config.set_from_options(db_options) try: setup(self.config, options=self.options, check_schema=True, register_station=False, load_plugins=False) except DatabaseInconsistency as err: error(_('The database version differs from your installed ' 'version.'), str(err))
def main(args): parser = get_option_parser() group = optparse.OptionGroup(parser, 'Daemon') group.add_option('', '--daemon-id', action="store", dest="daemon_id", help='Daemon Identifier') parser.add_option_group(group) options, args = parser.parse_args(args) if not options.daemon_id: raise SystemExit("Need a daemon id") from stoqlib.lib.message import error from stoqlib.lib.configparser import StoqConfig log.debug('reading configuration') config = StoqConfig() if options.filename: config.load(options.filename) else: config.load_default() settings = config.get_settings() try: store_dsn = settings.get_store_dsn() except: type, value, trace = sys.exc_info() error( _("Could not open the database config file"), _("Invalid config file settings, got error '%s', " "of type '%s'") % (value, type)) from stoqlib.exceptions import StoqlibError from stoqlib.database.exceptions import PostgreSQLError from stoq.lib.startup import setup log.debug('calling setup()') # XXX: progress dialog for connecting (if it takes more than # 2 seconds) or creating the database try: setup(config, options, register_station=True, check_schema=False) except (StoqlibError, PostgreSQLError) as e: error(_('Could not connect to the database'), 'error=%s dsn=%s' % (str(e), store_dsn)) raise SystemExit("Error: bad connection settings provided") daemon = Daemon(options.daemon_id) daemon.run()
def _try_connect(self): from stoqlib.lib.message import error try: store_dsn = self._config.get_settings().get_store_dsn() except: type, value, trace = sys.exc_info() error(_("Could not open the database config file"), _("Invalid config file settings, got error '%s', " "of type '%s'") % (value, type)) from stoqlib.database.exceptions import PostgreSQLError from stoqlib.database.runtime import get_default_store from stoqlib.exceptions import DatabaseError from stoqlib.lib.pgpass import write_pg_pass from stoq.lib.startup import setup # XXX: progress dialog for connecting (if it takes more than # 2 seconds) or creating the database log.debug('calling setup()') try: setup(self._config, self._options, register_station=False, check_schema=False, load_plugins=False) # the setup call above is not really trying to connect (since # register_station, check_schema and load_plugins are all False). # Try to really connect here. get_default_store() except (StoqlibError, PostgreSQLError) as e: log.debug('Connection failed.') error(_('Could not connect to the database'), 'error=%s uri=%s' % (str(e), store_dsn)) except DatabaseError: log.debug('Connection failed. Tring to setup .pgpass') # This is probably a missing password configuration. Setup the # pgpass file and try again. password = self._get_password() if not password: # There is no password stored in data file. Abort raise from stoqlib.database.settings import db_settings write_pg_pass(db_settings.dbname, db_settings.address, db_settings.port, db_settings.username, password) # Now that there is a pg_pass file, try to connect again try: get_default_store() except DatabaseError as e: log.debug('Connection failed again.') error(_('Could not connect to the database'), 'error=%s uri=%s' % (str(e), store_dsn))
def setup_stoq(register_station=False, name='stoqserver', version=stoqserver.version_str): info = AppInfo() info.set('name', name) info.set('version', version) info.set('ver', version) provide_utility(IAppInfo, info, replace=True) setup(config=get_config(), options=None, register_station=register_station, check_schema=True, load_plugins=True) # This is needed for api calls that requires the current branch set, # e.g. Sale.confirm main_company = api.sysparam.get_object( api.get_default_store(), 'MAIN_COMPANY') provide_utility(ICurrentBranch, main_company, replace=True)
def main(args): parser = get_option_parser() group = optparse.OptionGroup(parser, 'Daemon') group.add_option('', '--daemon-id', action="store", dest="daemon_id", help='Daemon Identifier') parser.add_option_group(group) options, args = parser.parse_args(args) if not options.daemon_id: raise SystemExit("Need a daemon id") from stoqlib.lib.message import error from stoqlib.lib.configparser import StoqConfig log.debug('reading configuration') config = StoqConfig() if options.filename: config.load(options.filename) else: config.load_default() settings = config.get_settings() try: store_dsn = settings.get_store_dsn() except: type, value, trace = sys.exc_info() error(_("Could not open the database config file"), _("Invalid config file settings, got error '%s', " "of type '%s'") % (value, type)) from stoqlib.exceptions import StoqlibError from stoqlib.database.exceptions import PostgreSQLError from stoq.lib.startup import setup log.debug('calling setup()') # XXX: progress dialog for connecting (if it takes more than # 2 seconds) or creating the database try: setup(config, options, register_station=True, check_schema=False) except (StoqlibError, PostgreSQLError) as e: error(_('Could not connect to the database'), 'error=%s dsn=%s' % (str(e), store_dsn)) raise SystemExit("Error: bad connection settings provided") daemon = Daemon(options.daemon_id) daemon.run()
def setup_stoq(register_station=False, name='stoqserver', version=stoqserver.version_str): info = AppInfo() info.set('name', name) info.set('version', version) info.set('ver', version) provide_utility(IAppInfo, info, replace=True) # FIXME: Maybe we should check_schema and load plugins here? setup(config=get_config(), options=None, register_station=register_station, check_schema=False, load_plugins=True) # This is needed for api calls that requires the current branch set, # e.g. Sale.confirm main_company = api.sysparam.get_object( api.get_default_store(), 'MAIN_COMPANY') provide_utility(ICurrentBranch, main_company, replace=True)
def load_config_and_call_setup(self): dbargs = self.settings.get_command_line_arguments() parser = get_option_parser() db_options, unused_args = parser.parse_args(dbargs) self.config.set_from_options(db_options) if needs_schema_update(): retval = run_dialog(SchemaUpdateWizard, None) if not retval: raise SystemExit() try: setup(self.config, options=self.options, check_schema=True, register_station=False, load_plugins=False) except DatabaseInconsistency as err: error(_('The database version differs from your installed ' 'version.'), str(err))
def _try_connect(self): from stoqlib.lib.message import error try: store_dsn = self._config.get_settings().get_store_dsn() except: type, value, trace = sys.exc_info() error(_("Could not open the database config file"), _("Invalid config file settings, got error '%s', " "of type '%s'") % (value, type)) from stoqlib.database.exceptions import PostgreSQLError from stoq.lib.startup import setup # XXX: progress dialog for connecting (if it takes more than # 2 seconds) or creating the database log.debug('calling setup()') try: setup(self._config, self._options, register_station=False, check_schema=False, load_plugins=False) except (StoqlibError, PostgreSQLError) as e: error(_('Could not connect to the database'), 'error=%s uri=%s' % (str(e), store_dsn))
def _setup_stoq(self): # FIXME: Maybe we should check_schema and load plugins here? setup(config=get_config(), options=None, register_station=False, check_schema=False, load_plugins=True)