Esempio n. 1
0
    def __init__(self, szprefix, no_warn=False, parent=None):
        """Filler 2 class constructor."""
        QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # check single instance
        try:
            self.single_instance = SingleInstance(LOCKFILE)
        except IOError:
            logger.error('another instance of Filler 2 is running, exiting...')
            self.criticalError(
                _translate(
                    "MainWindow",
                    "Cannot acquire a single instance lock. There is "
                    "another Filler 2 program running on the system."))

        # parse local SZARP configuration
        try:
            self.parser = IPKParser(szprefix)
        except IOError as err:
            logger.error("cannot read SZARP configuration")
            logger.error(str(err))
            self.criticalError(
                _translate("MainWindow", "Cannot read SZARP configuration") +
                " (%s)." % err.bad_path)
            sys.exit(1)
        except ValueError as err:
            logger.error(str(err))
            self.criticalError(
                _translate("MainWindow", "Non-valid SZARP database prefix."))
            sys.exit(1)

        logger.info("editing database of prefix '%s'", self.parser.ipk_prefix)

        # verify SZARP prefix versus hostname
        if no_warn == False:
            try:
                process = subprocess.Popen(["/bin/hostname", "-s"],
                                           stdout=subprocess.PIPE)
                out, err = process.communicate()
                if err == None:
                    hostname = out[:-1]

                if hostname != self.parser.ipk_prefix:
                    self.warningBox(
                        _translate(
                            "MainWindow",
                            "Warning! Database prefix differs from hostname, "
                            "you are probably modifying non-local database."))
            except OSError:
                pass

        ### initialize Qt4 widgets ##

        # name of the local configuration
        self.ui.titleLabel.setText(self.parser.getTitle())

        # list of parameter sets
        self.ui.listOfSets.addItem(
            _translate("MainWindow", "--- Choose a set of parameters ---"))
        self.ui.listOfSets.addItems(self.parser.getSets())
        self.ui.listOfSets.model().setData(
            self.ui.listOfSets.model().index(0, 0), QVariant(0),
            Qt.UserRole - 1)
        self.ui.listOfSets.setEnabled(True)

        # parameter's type combobox
        self.dialog_factory = ValueDialogFactory()

        for name, icon, desc in self.dialog_factory.get_dialogs():
            self.ui.valueType.addItem(icon, desc, QVariant((name, desc)))

        self.ui.valueType.model().setData(
            self.ui.valueType.model().index(0, 0), QVariant(0),
            Qt.UserRole - 1)

        # date interval variables
        self.fromDate = None
        self.toDate = None

        # table of changes
        base = 64
        self.ui.changesTable.setColumnCount(6)
        self.ui.changesTable.setColumnWidth(0,
                                            6 * base - 24)  # param's draw_name
        self.ui.changesTable.setColumnWidth(1, 3 * base)  # "from" date
        self.ui.changesTable.setColumnWidth(2, 3 * base)  # "to" date
        self.ui.changesTable.setColumnWidth(3, 3 * base)  # param's value type
        self.ui.changesTable.setColumnWidth(4,
                                            base - 20)  # remove entry button
        self.ui.changesTable.setColumnHidden(5, True)  # param's full name

        self.ui.changesTable.horizontalHeader().setVisible(False)
        self.ui.changesTable.setRowCount(0)