Example #1
0
 def __restoreDefaults(self):
     res = QMessageBox.warning(
         self, "Restore all Defaults?",
         "Are you sure that you want to replace your existing expressions for files & directories with the defaults?",
         QMessageBox.Yes | QMessageBox.Cancel)
     if res == QMessageBox.StandardButton(QMessageBox.Yes):
         self.__loadRules(self.rules.defaultFileExclusionRules(),
                          self.ui.treeViewFiles)
         self.__loadRules(self.rules.defaultDirExclusionRules(),
                          self.ui.treeViewDirs)
         self.__loadRules(self.rules.defaultRegistryExclusionRules(),
                          self.ui.treeViewReg)
         QMessageBox.information(self, "Restoration Complete",
                                 "The defaults have been restored")
    def __createPackage(self):
        # get the destination directory, if it does not exist - prompt and create it
        dstroot = self.__userSpecifiedDSTROOT()
        if not os.path.exists(dstroot):
            opt = QMessageBox.warning(
                self, "Destination Doesn't Exist",
                "The destination directory does not exist:\r\n{}\r\n\nDo you want to create it?"
                .format(dstroot))
            if opt != QMessageBox.StandardButton(QMessageBox.Ok):
                return
            os.makedirs(dstroot)
            if not os.path.exists(dstroot):
                QMessageBox.error(
                    self, "Failed to Create Directory",
                    "There was a problem creating the directory:\r\n{}".format(
                        dstroot))
                return

        # check if the scripts dir is specified, if it is, then it must exist
        scripts_dir = self.ui.lineEditScriptsDirectory.text()
        if len(scripts_dir) > 0:
            if not os.path.exists(scripts_dir):
                res = QMessageBox.warning(self,\
                                          "Scripts Directory",\
                                          "The scripts directory you specified does not exist - if you continue, the package will be created without scripting support\r\n\nDo you want to continue?",\
                                          buttons = QMessageBox.StandardButton(QMessageBox.Ok + QMessageBox.Cancel))
                if res != QMessageBox.StandardButton(QMessageBox.Ok):
                    return

        total_items = self.document.countScanningResults()
        self.__prepareProgress("Copying data files ...", total_items)

        # create a new DSTROOT
        the_dir = os.path.join(dstroot, "DSTROOT")
        if not os.path.exists(the_dir):
            os.makedirs(the_dir)
        self.dstroot_path = tempfile.mkdtemp(dir=the_dir)
        self.package_name = self.ui.lineEditPackageName.text()

        # grab all the stuff we're supposed to export, and write it into a DSTROOT, then point
        # pkgbuild at it.
        # 1. construct a DSTROOT
        # 2. decide whether to run an analysis or create the pkg
        # 3. done.
        word = "DSTROOT creation"
        pkg_process = True

        if self.__createDSTRoot():
            if self.ui.gbSimple.isChecked():
                word = "creation"
                self.__prepareProgress("Constructing PKG...")
                pkg_process = self.__constructPackage()
            else:
                word = "analysis"
                self.__prepareProgress("Analyzing PKG...")
                pkg_process = self.__analyzePackage()

            html = "<a href='{}'>{}</href>".format(self.dstroot_path,
                                                   self.dstroot_path)
            if pkg_process:
                pkg_result = "Package {} completed OK ({})".format(word, html)
            else:
                pkg_result = "Package {} failed to complete because of the packaging command failed (check logs)".format(
                    word)
        else:
            pkg_result = "Package {} failed (check logs)".format(word)

        self.__finishProgress(pkg_result)