eric7/CycloneDXInterface/CycloneDXConfigDialog.py

branch
eric7
changeset 9141
7085ece52151
parent 9122
ddf8ed8f7387
equal deleted inserted replaced
9140:6bbb4e047902 9141:7085ece52151
8 """ 8 """
9 9
10 import os 10 import os
11 11
12 from PyQt6.QtCore import pyqtSlot 12 from PyQt6.QtCore import pyqtSlot
13 from PyQt6.QtWidgets import QDialog 13 from PyQt6.QtWidgets import QDialog, QDialogButtonBox
14 14
15 from EricWidgets.EricApplication import ericApp 15 from EricWidgets.EricApplication import ericApp
16 from EricWidgets.EricPathPicker import EricPathPickerModes 16 from EricWidgets.EricPathPicker import EricPathPickerModes
17 17
18 from .Ui_CycloneDXConfigDialog import Ui_CycloneDXConfigDialog 18 from .Ui_CycloneDXConfigDialog import Ui_CycloneDXConfigDialog
58 """ 58 """
59 super().__init__(parent) 59 super().__init__(parent)
60 self.setupUi(self) 60 self.setupUi(self)
61 61
62 if environment == "<project>": 62 if environment == "<project>":
63 project = ericApp().getObject("Project") 63 self.__project = ericApp().getObject("Project")
64 self.__defaultDirectory = project.getProjectPath() 64 self.__defaultDirectory = self.__project.getProjectPath()
65 else: 65 else:
66 self.__project = None
66 venvManager = ericApp().getObject("VirtualEnvManager") 67 venvManager = ericApp().getObject("VirtualEnvManager")
67 self.__defaultDirectory = venvManager.getVirtualenvDirectory( 68 self.__defaultDirectory = venvManager.getVirtualenvDirectory(
68 environment) 69 environment)
69 70
70 self.environmentLabel.setText(environment) 71 self.environmentLabel.setText(environment)
91 self.fileFormatComboBox.setCurrentText( 92 self.fileFormatComboBox.setCurrentText(
92 CycloneDXConfigDialog.DefaultFileFormat) 93 CycloneDXConfigDialog.DefaultFileFormat)
93 self.on_fileFormatComboBox_currentTextChanged( 94 self.on_fileFormatComboBox_currentTextChanged(
94 CycloneDXConfigDialog.DefaultFileFormat) 95 CycloneDXConfigDialog.DefaultFileFormat)
95 96
97 self.__metadata = None
98 self.__metadataButton = self.buttonBox.addButton(
99 self.tr("Edit Metadata..."),
100 QDialogButtonBox.ButtonRole.ActionRole)
101 self.__metadataButton.clicked.connect(self.__editMetaData)
102
96 msh = self.minimumSizeHint() 103 msh = self.minimumSizeHint()
97 self.resize(max(self.width(), msh.width()), msh.height()) 104 self.resize(max(self.width(), msh.width()), msh.height())
98 105
99 @pyqtSlot() 106 @pyqtSlot()
100 def __repopulateSchemaVersionComboBox(self): 107 def __repopulateSchemaVersionComboBox(self):
133 self.filePicker.setFilters( 140 self.filePicker.setFilters(
134 self.tr("XML Files (*.xml);;All Files (*)")) 141 self.tr("XML Files (*.xml);;All Files (*)"))
135 else: 142 else:
136 self.filePicker.setFilters(self.tr("All Files (*)")) 143 self.filePicker.setFilters(self.tr("All Files (*)"))
137 144
145 @pyqtSlot()
146 def __editMetaData(self):
147 """
148 Private slot to open a dialog for editing the SBOM metadata.
149 """
150 from .CycloneDXMetaDataDialog import CycloneDXMetaDataDialog
151
152 # populate a metadata dictionary from project data
153 metadata = (
154 {
155 "Name": self.__project.getProjectName(),
156 "Type": "",
157 "Version": self.__project.getProjectVersion(),
158 "Description": self.__project.getProjectDescription(),
159 "AuthorName": self.__project.getProjectAuthor(),
160 "AuthorEmail": self.__project.getProjectAuthorEmail(),
161 "License": self.__project.getProjectLicense(),
162 "Manufacturer": "",
163 "Supplier": "",
164 }
165 if self.__metadata is None and self.__project is not None else
166 self.__metadata
167 )
168
169 dlg = CycloneDXMetaDataDialog(metadata=metadata, parent=self)
170 if dlg.exec() == QDialog.DialogCode.Accepted:
171 self.__metadata = dlg.getMetaData()
172
138 def getData(self): 173 def getData(self):
139 """ 174 """
140 Public method to get the SBOM configuration data. 175 Public method to get the SBOM configuration data.
141 176
142 @return tuple containing the input source, the input file name, the 177 @return tuple containing the input source, the input file name, the
143 file format, the schema version, the path of the SBOM file to be 178 file format, the schema version, the path of the SBOM file to be
144 written, a flag indicating to include vulnerability information 179 written, a flag indicating to include vulnerability information,
145 and a flag indicating to include dependency information 180 a flag indicating to include dependency information and a
146 @rtype tuple of (str, str, str, str, str, bool, bool) 181 dictionary containing the SBOM meta data
182 @rtype tuple of (str, str, str, str, str, bool, bool, dict)
147 """ 183 """
148 if self.environmentButton.isChecked(): 184 if self.environmentButton.isChecked():
149 inputSource = "environment" 185 inputSource = "environment"
150 inputFile = None 186 inputFile = None
151 elif self.pipenvButton.isChecked(): 187 elif self.pipenvButton.isChecked():
186 222
187 return ( 223 return (
188 inputSource, inputFile, fileFormat, schemaVersion, sbomFile, 224 inputSource, inputFile, fileFormat, schemaVersion, sbomFile,
189 self.vulnerabilityCheckBox.isChecked(), 225 self.vulnerabilityCheckBox.isChecked(),
190 self.dependenciesCheckBox.isChecked(), 226 self.dependenciesCheckBox.isChecked(),
191 ) 227 self.__metadata
228 )

eric ide

mercurial