Beispiel #1
0
def main(args):
    # Do this as soon as possible so we can log any early traceback
    setup_excepthook()

    if platform.system() == 'Windows':
        _windows_fixes()

    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)

    return handler.run_cmd(cmd, options, *args)
Beispiel #2
0
    def prepare_test(self):
        """Prepares to run a standalone test.
        This initializes Stoq and creates a store and returns
        an example creator.

        :returns: an :py:class:`~stoqlib.domain.exampledata.ExampleCreator`
        """
        # FIXME: We need to move this into stoqlib
        from stoq.gui.shell.bootstrap import boot_shell
        from stoq.lib.options import get_option_parser
        parser = get_option_parser()
        options = parser.parse_args(sys.argv[1:])[0]
        options.wizard = False
        options.splashscreen = False
        options.autoreload = False
        options.login_username = u'admin'
        options.non_fatal_warnings = False
        shell = boot_shell(options, initial=False)
        shell._dbconn.connect()
        shell._do_login()

        from stoqlib.domain.exampledata import ExampleCreator
        ec = ExampleCreator()
        store = self.new_store()
        ec.set_store(store)
        return ec
Beispiel #3
0
    def prepare_test(self):
        """Prepares to run a standalone test.
        This initializes Stoq and creates a store and returns
        an example creator.

        :returns: an :py:class:`~stoqlib.domain.exampledata.ExampleCreator`
        """
        # FIXME: We need to move this into stoqlib
        from stoq.gui.shell.bootstrap import boot_shell
        from stoq.lib.options import get_option_parser
        parser = get_option_parser()
        options = parser.parse_args(sys.argv[1:])[0]
        options.wizard = False
        options.splashscreen = False
        options.autoreload = False
        options.login_username = u'admin'
        options.non_fatal_warnings = False
        shell = boot_shell(options, initial=False)
        shell._dbconn.connect()
        shell._do_login()

        from stoqlib.domain.exampledata import ExampleCreator
        ec = ExampleCreator()
        store = self.new_store()
        ec.set_store(store)
        return ec
Beispiel #4
0
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)
Beispiel #5
0
def main(args):
    args = args[1:]
    if not args:
        # defaults to help
        args.append('help')

    cmd = args[0]
    args = args[1:]

    # FIXME: Set the default encoding to utf-8 just like pygtk used to do.
    # This probably will not be necessary in python3
    reload(sys)
    sys.setdefaultencoding('utf-8')

    # 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)
Beispiel #6
0
def get_shell(args):
    log.info('parsing command line arguments: %s ' % (args, ))
    from stoq.lib.options import get_option_parser
    parser = get_option_parser()

    group = optparse.OptionGroup(parser, 'Stoq')
    group.add_option('', '--wizard',
                     action="store_true",
                     dest="wizard",
                     default=None,
                     help='Run the wizard')
    group.add_option('', '--login-username',
                     action="store",
                     dest="login_username",
                     default=None,
                     help='Username to login to stoq with')
    group.add_option('', '--no-splash-screen',
                     action="store_false",
                     dest="splashscreen",
                     default=True,
                     help='Disable the splash screen')
    group.add_option('', '--version',
                     action="store_true",
                     dest="version",
                     help='Show the application version')
    parser.add_option_group(group)

    options, args = parser.parse_args(args)

    if options.version:
        import stoq
        raise SystemExit(stoq.version)

    from stoq.gui.shell.shell import Shell
    return args, Shell(options)
Beispiel #7
0
def main(args):
    if platform.system() == 'Windows':
        _windows_fixes()

    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)

    global SENTRY_URL, raven_client
    SENTRY_URL = config.get('Sentry', 'url') or SENTRY_URL
    raven_client = raven.Client(SENTRY_URL, release=stoqserver.version_str)
    setup_excepthook(SENTRY_URL)

    return handler.run_cmd(cmd, options, *args)
Beispiel #8
0
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)
Beispiel #9
0
def main(args):
    if platform.system() == 'Windows':
        _windows_fixes()

    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)

    global SENTRY_URL, raven_client
    SENTRY_URL = config.get('Sentry', 'url') or SENTRY_URL
    raven_client = raven.Client(SENTRY_URL, release=stoqserver.version_str)
    setup_excepthook(SENTRY_URL)

    return handler.run_cmd(cmd, options, *args)
Beispiel #10
0
def get_shell(args):
    log.info('parsing command line arguments: %s ' % (args, ))
    from stoq.lib.options import get_option_parser
    parser = get_option_parser()

    group = optparse.OptionGroup(parser, 'Stoq')
    group.add_option('-A',
                     '--autoreload',
                     action="store_true",
                     dest="autoreload",
                     help='Autoreload application when source is modified')
    group.add_option('',
                     '--fatal-warnings',
                     action="store_false",
                     dest="non_fatal_warnings",
                     default=True,
                     help='Make all warnings fatal')
    group.add_option('',
                     '--login-username',
                     action="store",
                     dest="login_username",
                     default=None,
                     help='Username to login to stoq with')
    group.add_option('',
                     '--no-splash-screen',
                     action="store_false",
                     dest="splashscreen",
                     default=True,
                     help='Disable the splash screen')
    group.add_option('',
                     '--version',
                     action="store_true",
                     dest="version",
                     help='Show the application version')
    group.add_option('',
                     '--wizard',
                     action="store_true",
                     dest="wizard",
                     default=None,
                     help='Run the wizard')
    parser.add_option_group(group)

    options, args = parser.parse_args(args)

    if options.version:
        import stoq
        print(stoq.version)
        raise SystemExit()

    from stoq.gui.shell.bootstrap import boot_shell
    shell = boot_shell(options)

    return args, shell
Beispiel #11
0
def get_shell(args):
    log.info('parsing command line arguments: %s ' % (args, ))
    from stoq.lib.options import get_option_parser
    parser = get_option_parser()

    group = optparse.OptionGroup(parser, 'Stoq')
    group.add_option('-A', '--autoreload',
                     action="store_true",
                     dest="autoreload",
                     help='Autoreload application when source is modified')
    group.add_option('', '--quiet',
                     action="store_true",
                     dest="quiet",
                     help='Be quiet about warnings')
    group.add_option('', '--fatal-warnings',
                     action="store_false",
                     dest="non_fatal_warnings",
                     default=True,
                     help='Make all warnings fatal')
    group.add_option('', '--login-username',
                     action="store",
                     dest="login_username",
                     default=None,
                     help='Username to login to stoq with')
    group.add_option('', '--no-splash-screen',
                     action="store_false",
                     dest="splashscreen",
                     default=True,
                     help='Disable the splash screen')
    group.add_option('', '--version',
                     action="store_true",
                     dest="version",
                     help='Show the application version')
    group.add_option('', '--wizard',
                     action="store_true",
                     dest="wizard",
                     default=None,
                     help='Run the wizard')
    parser.add_option_group(group)

    options, args = parser.parse_args(args)

    if options.version:
        import stoq
        print(stoq.version)
        raise SystemExit()

    from stoq.gui.shell.bootstrap import boot_shell
    shell = boot_shell(options)

    return args, shell
Beispiel #12
0
 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))
Beispiel #13
0
 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))
Beispiel #14
0
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()
Beispiel #15
0
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()
Beispiel #16
0
def main(args):
    if platform.system() == 'Windows':
        _windows_fixes()

    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)
    setup_sentry(options)

    return handler.run_cmd(cmd, options, *args)
Beispiel #17
0
    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))
Beispiel #18
0
    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))
Beispiel #19
0
def main(args):
    args = args[1:]
    if not args:
        # defaults to help
        args.append('help')

    cmd = args[0]
    args = args[1:]

    # 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)
Beispiel #20
0
def main(args):
    args = args[1:]
    if not args:
        # defaults to help
        args.append('help')

    cmd = args[0]
    args = args[1:]

    # 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)
Beispiel #21
0
def setup(config=None, options=None, register_station=True, check_schema=True,
          load_plugins=True):
    """
    Loads the configuration from arguments and configuration file.

    @param config: a StoqConfig instance
    @param options: a Optionparser instance
    @param register_station: if we should register the branch station.
    @param check_schema: if we should check the schema
    @param load_plugins: if we should load plugins for the system
    """

    # NOTE: No GUI calls are allowed in here
    #       If you change anything here, you need to verify that all
    #       callsites are still working properly.
    #       bin/stoq
    #       bin/stoqdbadmin
    #       python stoq/tests/runtest.py

    if options is None:
        parser = get_option_parser()
        options, args = parser.parse_args(sys.argv)

    if options.verbose:
        from kiwi.log import set_log_level
        set_log_level('stoq*', 0)

    setup_path()

    if config is None:
        config = StoqConfig()
        if options.filename:
            config.load(options.filename)
        else:
            config.load_default()
    config.set_from_options(options)

    register_config(config)

    if options and options.sqldebug:
        enable_debugging()

    from stoq.lib.applist import ApplicationDescriptions
    provide_utility(IApplicationDescriptions, ApplicationDescriptions(),
                    replace=True)

    db_settings = config.get_settings()
    try:
        default_store = get_default_store()
    except DatabaseError as e:
        # Only raise an error if a database is actually required
        if register_station or load_plugins or check_schema:
            error(e.short, str(e.msg))
        else:
            default_store = None

    if register_station:
        db_settings.check_version(default_store)
        if check_schema:
            migration = StoqlibSchemaMigration()
            migration.check()

        if options and options.sqldebug:
            enable_debugging()

        set_current_branch_station(default_store, station_name=None)

    if load_plugins:
        from stoqlib.lib.pluginmanager import get_plugin_manager
        manager = get_plugin_manager()
        manager.activate_installed_plugins()

    if check_schema:
        if not default_store.table_exists('system_table'):
            error(
                _("Database schema error"),
                _("Table 'system_table' does not exist.\n"
                  "Consult your database administrator to solve this problem."))

        if check_schema:
            migration = StoqlibSchemaMigration()
            migration.check()
Beispiel #22
0
def setup(config=None, options=None, register_station=True, check_schema=True,
          load_plugins=True):
    """
    Loads the configuration from arguments and configuration file.

    @param config: a StoqConfig instance
    @param options: a Optionparser instance
    @param register_station: if we should register the branch station.
    @param check_schema: if we should check the schema
    @param load_plugins: if we should load plugins for the system
    """

    # NOTE: No GUI calls are allowed in here
    #       If you change anything here, you need to verify that all
    #       callsites are still working properly.
    #       bin/stoq
    #       bin/stoqdbadmin
    #       python stoq/tests/runtest.py

    if options is None:
        parser = get_option_parser()
        options, args = parser.parse_args(sys.argv)

    if options.verbose:
        from kiwi.log import set_log_level
        set_log_level('stoq*', 0)

    setup_path()

    if config is None:
        config = StoqConfig()
        if options.filename:
            config.load(options.filename)
        else:
            config.load_default()
    config.set_from_options(options)

    register_config(config)

    if options and options.sqldebug:
        enable_debugging()

    from stoq.lib.applist import ApplicationDescriptions
    provide_utility(IApplicationDescriptions, ApplicationDescriptions(),
                    replace=True)

    if register_station:
        try:
            default_store = get_default_store()
        except DatabaseError as e:
            error(e.short, str(e.msg))

        config.get_settings().check_version(default_store)

        if check_schema:
            migration = StoqlibSchemaMigration()
            migration.check()

        if options and options.sqldebug:
            enable_debugging()

        set_current_branch_station(default_store, station_name=None)

    if load_plugins:
        from stoqlib.lib.pluginmanager import get_plugin_manager
        manager = get_plugin_manager()
        manager.activate_installed_plugins()

    if check_schema:
        default_store = get_default_store()
        if not default_store.table_exists('system_table'):
            error(
                _("Database schema error"),
                _("Table 'system_table' does not exist.\n"
                  "Consult your database administrator to solve this problem."))

        if check_schema:
            migration = StoqlibSchemaMigration()
            migration.check()