예제 #1
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_InstallWizard()
        self.ui.setupUi(self)

        self.logfile = open("failed.log", "a")

        self.installComplete = False

        self.postSetup()
        self.initEvents()
 def __init__(self, parent=None):
     QtGui.QWidget.__init__(self, parent)
     self.ui = Ui_InstallWizard()
     self.ui.setupUi(self)        
     
     self.logfile = open("failed.log", "a")
     
     self.installComplete = False
     
     self.postSetup()
     self.initEvents()
예제 #3
0
class HelioviewerInstallWizard(QtGui.QWizard):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_InstallWizard()
        self.ui.setupUi(self)

        self.logfile = open("failed.log", "a")

        self.installComplete = False

        self.postSetup()
        self.initEvents()

    def postSetup(self):
        self.setPixmap(QtGui.QWizard.LogoPixmap,
                       QtGui.QPixmap(":/Logos/color.png"))
        self.setupValidators()

    def setupValidators(self):
        # Mandatory fields
        self.ui.dbAdminPage.registerField("dbAdminUserName*",
                                          self.ui.dbAdminUserName)
        self.ui.dbAdminPage.registerField("dbAdminPassword*",
                                          self.ui.dbAdminPassword)
        self.ui.hvDatabaseSetupPage.registerField("hvDatabaseName*",
                                                  self.ui.hvDatabaseName)
        self.ui.hvDatabaseSetupPage.registerField("hvUserName*",
                                                  self.ui.hvUserName)
        self.ui.hvDatabaseSetupPage.registerField("hvPassword*",
                                                  self.ui.hvPassword)

        alphanum = QtGui.QRegExpValidator(QtCore.QRegExp("[\w$]*"), self)
        passwd = QtGui.QRegExpValidator(
            QtCore.QRegExp("[\w!@#\$%\^&\*\(\)_\+\.,\?'\"]*"), self)

        # DB Admin Info
        self.ui.dbAdminUserName.setValidator(alphanum)
        self.ui.dbAdminPassword.setValidator(passwd)
        self.ui.hvDatabaseName.setValidator(alphanum)
        self.ui.hvUserName.setValidator(alphanum)
        self.ui.hvPassword.setValidator(passwd)

    def initializePage(self, page):
        if page is __INSTALL_PAGE__:
            jp2dir = str(self.ui.jp2RootDirInput.text())

            self.ui.statusMsg.setText("Searching for JPEG 2000 Images...")
            self.images = traverse_directory(jp2dir)
            n = len(self.images)

            if n == 0:
                print("No JPEG 2000 images found. Exiting installation.")
                sys.exit(2)
            else:
                self.ui.installProgress.setMaximum(n // __STEP_FXN_THROTTLE__)
                self.ui.statusMsg.setText("""\
Found %d JPEG2000 images.

If this is correct, please press "Start" to begin processing.
                """ % n)
            #self.processImages()

    def validateCurrentPage(self):
        ''' Validates information for a given page '''
        page = self.currentId()

        #print "Validating page %s" % str(page)

        # Database type & administrator information
        if page is __DBADMIN_PAGE__:
            canConnect = check_db_info(str(self.ui.dbAdminUserName.text()),
                                       str(self.ui.dbAdminPassword.text()),
                                       self.ui.mysqlRadioBtn.isChecked())
            if not canConnect:
                self.ui.dbAdminStatus.setText(
                    "<span style='color: red;'>Unable to connect to the database. Please check your login information and try again.</span>"
                )
            else:
                self.ui.dbAdminStatus.clear()
            return canConnect

        # JP2 Archive location
        elif page is __JP2DIR_PAGE__:
            pathExists = os.path.isdir(self.ui.jp2RootDirInput.text())
            if not pathExists:
                self.ui.jp2ArchiveStatus.setText(
                    "<span style='color: red;'>Not a valid location. Please check the filepath and permissions and try again.</span>"
                )
            else:
                self.ui.jp2ArchiveStatus.clear()
            return pathExists

        # Install page
        elif page is __INSTALL_PAGE__:
            return self.installComplete

        # No validation required
        else:
            return True

    def processImages(self):
        ''' Process JPEG 2000 archive and enter information into the database '''
        admin, adminpass, hvdb, hvuser, hvpass, jp2dir, mysql = self.getFormFields(
        )

        self.ui.startProcessingBtn.setEnabled(False)

        self.ui.statusMsg.setText("Creating database schema")

        cursor = setup_database_schema(admin, adminpass, hvdb, hvuser, hvpass,
                                       mysql)

        process_jp2_images(self.images, jp2dir, cursor, mysql,
                           self.updateProgress)

        cursor.close()
        #self.ui.installProgress.setValue(len(images))

        self.ui.statusMsg.setText("Finished!")
        self.installComplete = True

    def updateProgress(self, img):
        value = self.ui.installProgress.value() + 1
        self.ui.installProgress.setValue(value)
        self.ui.statusMsg.setText("Processing image:\n    %s" % img)

    def getFormFields(self):
        ''' Grab form information '''
        mysql = self.ui.mysqlRadioBtn.isChecked()
        admin = str(self.ui.dbAdminUserName.text())
        adminpass = str(self.ui.dbAdminPassword.text())
        hvdb = str(self.ui.hvDatabaseName.text())
        hvuser = str(self.ui.hvUserName.text())
        hvpass = str(self.ui.hvPassword.text())
        jp2dir = str(self.ui.jp2RootDirInput.text())

        return admin, adminpass, hvdb, hvuser, hvpass, jp2dir, mysql

    def initEvents(self):
        QtCore.QObject.connect(self.ui.jp2BrowseBtn,
                               QtCore.SIGNAL("clicked()"),
                               self.openBrowseDialog)
        QtCore.QObject.connect(self.ui.startProcessingBtn,
                               QtCore.SIGNAL("clicked()"), self.processImages)

    def openBrowseDialog(self):
        fd = QtGui.QFileDialog(self)
        directory = fd.getExistingDirectory()
        self.ui.jp2RootDirInput.setText(directory)
class HelioviewerInstallWizard(QtGui.QWizard):

    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_InstallWizard()
        self.ui.setupUi(self)        
        
        self.logfile = open("failed.log", "a")
        
        self.installComplete = False
        
        self.postSetup()
        self.initEvents()

    def postSetup(self):
        self.setPixmap(QtGui.QWizard.LogoPixmap, QtGui.QPixmap(":/Logos/color.png"))
        self.setupValidators()


    def setupValidators(self):
        # Mandatory fields
        self.ui.dbAdminPage.registerField("dbAdminUserName*", self.ui.dbAdminUserName)
        self.ui.dbAdminPage.registerField("dbAdminPassword*", self.ui.dbAdminPassword)
        self.ui.hvDatabaseSetupPage.registerField("hvDatabaseName*", self.ui.hvDatabaseName)
        self.ui.hvDatabaseSetupPage.registerField("hvUserName*", self.ui.hvUserName)
        self.ui.hvDatabaseSetupPage.registerField("hvPassword*", self.ui.hvPassword)

        alphanum = QtGui.QRegExpValidator(QtCore.QRegExp("[\w$]*"), self)
        passwd   = QtGui.QRegExpValidator(QtCore.QRegExp("[\w!@#\$%\^&\*\(\)_\+\.,\?'\"]*"), self)

        # DB Admin Info
        self.ui.dbAdminUserName.setValidator(alphanum)
        self.ui.dbAdminPassword.setValidator(passwd)
        self.ui.hvDatabaseName.setValidator(alphanum)
        self.ui.hvUserName.setValidator(alphanum)
        self.ui.hvPassword.setValidator(passwd)


    def initializePage(self, page):
        if page is __INSTALL_PAGE__:
            jp2dir = str(self.ui.jp2RootDirInput.text())
            
            self.ui.statusMsg.setText("Searching for JPEG 2000 Images...")
            self.images = traverse_directory(jp2dir)
            n = len(self.images)

            if n == 0:
                print("No JPEG 2000 images found. Exiting installation.")
                sys.exit(2)
            else:
                self.ui.installProgress.setMaximum(n // __STEP_FXN_THROTTLE__)
                self.ui.statusMsg.setText("""\
Found %d JPEG2000 images.

If this is correct, please press "Start" to begin processing.
                """ % n)
            #self.processImages()

    def validateCurrentPage(self):
        ''' Validates information for a given page '''
        page = self.currentId()

        #print "Validating page %s" % str(page)

        # Database type & administrator information
        if page is __DBADMIN_PAGE__:
            canConnect = check_db_info(str(self.ui.dbAdminUserName.text()), str(self.ui.dbAdminPassword.text()), self.ui.mysqlRadioBtn.isChecked())
            if not canConnect:
                self.ui.dbAdminStatus.setText("<span style='color: red;'>Unable to connect to the database. Please check your login information and try again.</span>")
            else:
                self.ui.dbAdminStatus.clear()
            return canConnect

        # JP2 Archive location
        elif page is __JP2DIR_PAGE__:
            pathExists = os.path.isdir(self.ui.jp2RootDirInput.text())
            if not pathExists:
                self.ui.jp2ArchiveStatus.setText("<span style='color: red;'>Not a valid location. Please check the filepath and permissions and try again.</span>")
            else:
                self.ui.jp2ArchiveStatus.clear()
            return pathExists
        
        # Install page
        elif page is __INSTALL_PAGE__:
            return self.installComplete

        # No validation required
        else:
            return True

    def processImages(self):
        ''' Process JPEG 2000 archive and enter information into the database '''
        admin, adminpass, hvdb, hvuser, hvpass, jp2dir, mysql = self.getFormFields()

        self.ui.startProcessingBtn.setEnabled(False)

        self.ui.statusMsg.setText("Creating database schema")

        db, cursor = setup_database_schema(admin, adminpass, "localhost", hvdb, hvuser, hvpass, mysql)

        process_jp2_images(self.images, jp2dir, cursor, mysql, self.updateProgress)
    
        cursor.close()
        #self.ui.installProgress.setValue(len(images))
    
        self.ui.statusMsg.setText("Finished!")
        self.installComplete = True
    
    def updateProgress(self, img):
        value = self.ui.installProgress.value() + 1
        self.ui.installProgress.setValue(value)
        self.ui.statusMsg.setText("Processing image:\n    %s" % img)

    def getFormFields(self):
        ''' Grab form information '''
        mysql = self.ui.mysqlRadioBtn.isChecked()
        admin = str(self.ui.dbAdminUserName.text())
        adminpass = str(self.ui.dbAdminPassword.text())
        hvdb   = str(self.ui.hvDatabaseName.text())
        hvuser = str(self.ui.hvUserName.text())
        hvpass = str(self.ui.hvPassword.text())
        jp2dir = str(self.ui.jp2RootDirInput.text())

        return admin, adminpass, hvdb, hvuser, hvpass, jp2dir, mysql

    def initEvents(self):
        QtCore.QObject.connect(self.ui.jp2BrowseBtn, QtCore.SIGNAL("clicked()"), self.openBrowseDialog)
        QtCore.QObject.connect(self.ui.startProcessingBtn, QtCore.SIGNAL("clicked()"), self.processImages)

    def openBrowseDialog(self):
        fd = QtGui.QFileDialog(self)
        directory = fd.getExistingDirectory()
        self.ui.jp2RootDirInput.setText(directory)