Exemplo n.º 1
0
    def connect(self):
        """Connect to master db.
        """
        host = self.gui.getDBhost()
        pw = getPw(host, self.dbname, self.dbuser)
        if (pw == None):
            return False
        cData = {   u"host" : host,
                    u"db"   : self.dbname,
                    u"user" : self.dbuser,
                    u"pw"   : pw
                }

        db = DBm(cData)
        if not db.isOpen():
            warning(_("Couldn't open master database"))
            return False
        self.dbm = db
        return True
Exemplo n.º 2
0
    def init(self):
        self.db = None

        self.gui = GuiWidget(self.settings)
        self.gui.show()
        c0 = self.gui.cursor()
        self.gui.setCursor(QtGui.QCursor(QtCore.Qt.BusyCursor))

        # Connect to control database
        connectData = getConnectInfo(self.settings, ADMIN)
        if not connectData:
            return
        db = DB(connectData)
        self.gui.setCursor(c0)
        if not db.isOpen():
            error(_("Couldn't open control database"))
            return # actually error shouldn't return
        self.db = db

        self.app.init(self.gui)

        # set up lists of available databases, admins, users, etc.
        # and initialize the main module
        self.cp.init(self.gui, self.db)
Exemplo n.º 3
0
    def init(self):
        self.db = None

        self.gui = GuiWidget(self.settings)
        self.gui.show()
        c0 = self.gui.cursor()
        self.gui.setCursor(QtGui.QCursor(QtCore.Qt.BusyCursor))

        # Connect to control database
        connectData = getConnectInfo(self.settings, ADMIN)
        if not connectData:
            return
        db = DB(connectData)
        self.gui.setCursor(c0)
        if not db.isOpen():
            error(_("Couldn't open control database"))
            return  # actually error shouldn't return
        self.db = db

        self.app.init(self.gui)

        # set up lists of available databases, admins, users, etc.
        # and initialize the main module
        self.cp.init(self.gui, self.db)
Exemplo n.º 4
0
def go():
    gui.report("  ------------------------------------\n")
    # Connect to control database
    connectData = getConnectInfo(app.settings, "postgres")
    if not connectData:
        return False

    gui.report(_("Connecting to postgres@%s") % connectData[u"host"])

    dbzc = connectData[u"db"]
    connectData[u"db"] = u"postgres"
    dbp = DB(connectData)
    if not dbp.isOpen():
        error(_("Couldn't open 'postgres' database"))
        return False

    gui.report(_("Checking existing databases"))

    if dbp.read1(u"SELECT datname FROM pg_database WHERE datname = ?",
            (dbzc,)):
        if not confirmationDialog(_("Remove Control Database?"),
                _("The control database (%s) already exists."
                  " Should it be removed, with everything it contains?")
                        % dbzc, False):
            dbp.close()
            return False

        connectData[u"db"] = dbzc
        userset = set()
        try:
            # Remove all databases and users
            db = DB(connectData)
            try:
                info = db.read(u"SELECT * FROM databases")
            except:
                info = None
            db.close()
            if info:
                for id, name, finalized, users in info:
                    gui.report(_("Removing database '%s'") % name)
                    dbp.send(u"DROP DATABASE IF EXISTS %s" % name)
                    userset |= set(users.split())

            gui.report(_("Removing database '%s'") % dbzc)
            dbp.send(u"DROP DATABASE %s" % dbzc)

        except:
            #print_exc()

            error(_("Couldn't remove old data -"
                    " summon a PostgreSQL expert:\n%s") % format_exc())

        gui.report(_("Trying to remove users ..."))
        try:
            dbp.send(u"DROP ROLE IF EXISTS %s" % USERROLE)
        except:
            gui.report(_("  ... couldn't remove user '%s'") % USERROLE)
        try:
            dbp.send(u"DROP ROLE IF EXISTS %s" % ADMIN)
        except:
            gui.report(_("  ... couldn't remove user '%s'") % ADMIN)
        for u in userset:
            try:
                dbp.send(u"DROP ROLE IF EXISTS %s" % u)
            except:
                gui.report(_("  ... couldn't remove user '%s'") % u)

    gui.report(_("\nCreating control database"))
    dbp.send(u"CREATE DATABASE %s ENCODING 'UTF8'" % dbzc)
    dbp.close()
    dbp = None

    connectData[u"db"] = dbzc
    db = DB(connectData)
    if not db.isOpen():
        error(_("Couldn't open control database"))
        return False

    try:
        setupCDB(db)
    except:
        db.close()
        error(_("Couldn't set up the '%s' database."
                " Please try again:\n%s") % (dbzc, format_exc()))
        return False
    gui.report(_("\nSuccess! The control database is ready."))
    gui.report(_("  Now use the control panel (zgcp) to set up"
            " report databases."))

    db.close()
    return True
Exemplo n.º 5
0
def go():
    gui.report("  ------------------------------------\n")
    # Connect to control database
    connectData = getConnectInfo(app.settings, "postgres")
    if not connectData:
        return False

    gui.report(_("Connecting to postgres@%s") % connectData[u"host"])

    dbzc = connectData[u"db"]
    connectData[u"db"] = u"postgres"
    dbp = DB(connectData)
    if not dbp.isOpen():
        error(_("Couldn't open 'postgres' database"))
        return False

    gui.report(_("Checking existing databases"))

    if dbp.read1(u"SELECT datname FROM pg_database WHERE datname = ?",
                 (dbzc, )):
        if not confirmationDialog(
                _("Remove Control Database?"),
                _("The control database (%s) already exists."
                  " Should it be removed, with everything it contains?") %
                dbzc, False):
            dbp.close()
            return False

        connectData[u"db"] = dbzc
        userset = set()
        try:
            # Remove all databases and users
            db = DB(connectData)
            try:
                info = db.read(u"SELECT * FROM databases")
            except:
                info = None
            db.close()
            if info:
                for id, name, finalized, users in info:
                    gui.report(_("Removing database '%s'") % name)
                    dbp.send(u"DROP DATABASE IF EXISTS %s" % name)
                    userset |= set(users.split())

            gui.report(_("Removing database '%s'") % dbzc)
            dbp.send(u"DROP DATABASE %s" % dbzc)

        except:
            #print_exc()

            error(
                _("Couldn't remove old data -"
                  " summon a PostgreSQL expert:\n%s") % format_exc())

        gui.report(_("Trying to remove users ..."))
        try:
            dbp.send(u"DROP ROLE IF EXISTS %s" % USERROLE)
        except:
            gui.report(_("  ... couldn't remove user '%s'") % USERROLE)
        try:
            dbp.send(u"DROP ROLE IF EXISTS %s" % ADMIN)
        except:
            gui.report(_("  ... couldn't remove user '%s'") % ADMIN)
        for u in userset:
            try:
                dbp.send(u"DROP ROLE IF EXISTS %s" % u)
            except:
                gui.report(_("  ... couldn't remove user '%s'") % u)

    gui.report(_("\nCreating control database"))
    dbp.send(u"CREATE DATABASE %s ENCODING 'UTF8'" % dbzc)
    dbp.close()
    dbp = None

    connectData[u"db"] = dbzc
    db = DB(connectData)
    if not db.isOpen():
        error(_("Couldn't open control database"))
        return False

    try:
        setupCDB(db)
    except:
        db.close()
        error(
            _("Couldn't set up the '%s' database."
              " Please try again:\n%s") % (dbzc, format_exc()))
        return False
    gui.report(_("\nSuccess! The control database is ready."))
    gui.report(
        _("  Now use the control panel (zgcp) to set up"
          " report databases."))

    db.close()
    return True