Exemplo n.º 1
0
    def cmd_updateschema(self, options):
        """Update the database schema"""
        from stoqlib.database.migration import StoqlibSchemaMigration
        from stoqlib.lib.environment import is_developer_mode
        from stoqlib.net.server import ServerProxy

        self._read_config(options,
                          check_schema=False,
                          load_plugins=False,
                          register_station=False)

        # This is a little bit tricky to be able to apply the initial
        # plugin infrastructure
        migration = StoqlibSchemaMigration()

        if is_developer_mode():
            backup = False
        else:
            backup = options.disable_backup

        server = ServerProxy()
        running = server.check_running()
        if running:
            server.call('pause_tasks')

        try:
            retval = migration.update(backup=backup)
        finally:
            # The schema was upgraded. If it was running before,
            # restart it so it can load the new code
            if running:
                server.call('restart')

        return 0 if retval else 1
Exemplo n.º 2
0
    def set_value_generic(self, param_name, value):
        """Update the internal cache for a parameter

        :param param_name: the parameter name
        :param value: value
        :type value: unicode
        """
        # FIXME: Find a better way of doing this after we integrate stoq.link
        # better with Stoq.
        if param_name == 'ONLINE_SERVICES':
            from stoqlib.net.server import ServerProxy
            p = ServerProxy(timeout=5)
            threadit(lambda: p.check_running() and p.call('restart'))

        self._values[param_name] = value
Exemplo n.º 3
0
        def migrate(retval):
            server = ServerProxy()
            running = yield server.check_running()
            if running:
                yield server.call('pause_tasks')

            try:
                retval[0] = yield migration.update_async(backup=backup)
            finally:
                # The schema was upgraded. If it was running before,
                # restart it so it can load the new code
                if running:
                    yield server.call('restart')

                if reactor.running:
                    reactor.stop()
Exemplo n.º 4
0
    def cmd_init(self, options):
        """Creates and initializes a database"""
        # Create a database user before trying to connect
        if options.create_dbuser:
            if not options.username:
                raise SystemExit("This option requires a --username set")
            retval = self._create_dbuser(options.username)
            if retval != 0:
                return retval
        config = self._read_config(options,
                                   register_station=False,
                                   check_schema=False,
                                   load_plugins=False)

        from stoqlib.database.admin import initialize_system
        from stoqlib.database.runtime import set_default_store
        from stoqlib.database.settings import db_settings
        from stoqlib.lib.pgpass import write_pg_pass
        from stoqlib.net.server import ServerProxy
        if options.dbname:
            db_settings.dbname = options.dbname
        if options.address:
            db_settings.address = options.address
        if options.port:
            db_settings.port = options.port
        if options.username:
            db_settings.username = options.username
        if options.password:
            db_settings.password = options.password
            # a password was sent via command line. Make sure we can run psql by
            # setting up pgpass
            write_pg_pass(db_settings.dbname, db_settings.address,
                          db_settings.port, db_settings.username,
                          db_settings.password)

        server = ServerProxy()
        running = server.check_running()
        if running:
            server.call('pause_tasks')
        # ServerProxy may have opened a store
        set_default_store(None)

        try:
            initialize_system(password='',
                              force=options.force,
                              empty=options.empty)
        except ValueError as e:
            # Database server is missing pg_trgm
            if 'pg_trgm' in str(e):
                return 31
            else:
                raise

        if options.create_examples or options.demo:
            from stoqlib.importers.stoqlibexamples import create
            create(utilities=True)

        if options.register_station and not options.empty:
            self._register_station()

        if options.pre_plugins:
            self._register_plugins(str(options.pre_plugins).split(','))

        if options.plugins:
            self._enable_plugins(str(options.plugins).split(','))

        if options.demo:
            self._enable_demo()

        config.flush()

        # The schema was upgraded. If it was running before,
        # restart it so it can load the new code
        if running:
            server.call('restart')

        return 0
Exemplo n.º 5
0
 def setup_proxies(self):
     self.add_proxy(self.model, self.proxy_widgets)
     self._proxy = ServerProxy(timeout=60)
Exemplo n.º 6
0
 def __init__(self):
     ResourceStatus.__init__(self)
     self._webservice = WebService()
     self._server = ServerProxy()
Exemplo n.º 7
0
 def __init__(self):
     ResourceStatus.__init__(self)
     self._server = ServerProxy()