50 availableFutures = [ |
50 availableFutures = [ |
51 'division', 'absolute_import', 'with_statement', |
51 'division', 'absolute_import', 'with_statement', |
52 'print_function', 'unicode_literals', 'generator_stop', |
52 'print_function', 'unicode_literals', 'generator_stop', |
53 'annotations'] |
53 'annotations'] |
54 |
54 |
|
55 cryptoBitSelectionsDsaRsa = [ |
|
56 "512", "1024", "2048", "4096", "8192", "16384", "32786", |
|
57 ] |
|
58 cryptoBitSelectionsEc = [ |
|
59 "160", "224", "256", "384", "512", |
|
60 ] |
|
61 |
55 checkCategories = { |
62 checkCategories = { |
56 "A": QCoreApplication.translate( |
63 "A": QCoreApplication.translate( |
57 "CheckerCategories", |
64 "CheckerCategories", |
58 "Annotations"), |
65 "Annotations"), |
59 "C": QCoreApplication.translate( |
66 "C": QCoreApplication.translate( |
118 |
125 |
119 for future in CodeStyleCheckerDialog.availableFutures: |
126 for future in CodeStyleCheckerDialog.availableFutures: |
120 itm = QListWidgetItem(future, self.futuresList) |
127 itm = QListWidgetItem(future, self.futuresList) |
121 itm.setFlags(itm.flags() | Qt.ItemIsUserCheckable) |
128 itm.setFlags(itm.flags() | Qt.ItemIsUserCheckable) |
122 itm.setCheckState(Qt.Unchecked) |
129 itm.setCheckState(Qt.Unchecked) |
|
130 |
|
131 self.dsaHighRiskCombo.addItems( |
|
132 CodeStyleCheckerDialog.cryptoBitSelectionsDsaRsa) |
|
133 self.dsaMediumRiskCombo.addItems( |
|
134 CodeStyleCheckerDialog.cryptoBitSelectionsDsaRsa) |
|
135 self.rsaHighRiskCombo.addItems( |
|
136 CodeStyleCheckerDialog.cryptoBitSelectionsDsaRsa) |
|
137 self.rsaMediumRiskCombo.addItems( |
|
138 CodeStyleCheckerDialog.cryptoBitSelectionsDsaRsa) |
|
139 self.ecHighRiskCombo.addItems( |
|
140 CodeStyleCheckerDialog.cryptoBitSelectionsEc) |
|
141 self.ecMediumRiskCombo.addItems( |
|
142 CodeStyleCheckerDialog.cryptoBitSelectionsEc) |
123 |
143 |
124 self.statisticsButton = self.buttonBox.addButton( |
144 self.statisticsButton = self.buttonBox.addButton( |
125 self.tr("Statistics..."), QDialogButtonBox.ActionRole) |
145 self.tr("Statistics..."), QDialogButtonBox.ActionRole) |
126 self.statisticsButton.setToolTip( |
146 self.statisticsButton.setToolTip( |
127 self.tr("Press to show some statistics for the last run")) |
147 self.tr("Press to show some statistics for the last run")) |
455 self.__data["AnnotationsChecker"] = { |
475 self.__data["AnnotationsChecker"] = { |
456 "MinimumCoverage": 75, |
476 "MinimumCoverage": 75, |
457 "MaximumComplexity": 3, |
477 "MaximumComplexity": 3, |
458 } |
478 } |
459 |
479 |
460 # TODO: add 'SecurityChecker' |
480 if "SecurityChecker" not in self.__data: |
|
481 from .Security.SecurityDefaults import SecurityDefaults |
|
482 self.__data["SecurityChecker"] = { |
|
483 "HardcodedTmpDirectories": |
|
484 SecurityDefaults["hardcoded_tmp_directories"], |
|
485 "InsecureHashes": |
|
486 SecurityDefaults["insecure_hashes"], |
|
487 "InsecureSslProtocolVersions": |
|
488 SecurityDefaults["insecure_ssl_protocol_versions"], |
|
489 "WeakKeySizeDsaHigh": |
|
490 str(SecurityDefaults["weak_key_size_dsa_high"]), |
|
491 "WeakKeySizeDsaMedium": |
|
492 str(SecurityDefaults["weak_key_size_dsa_medium"]), |
|
493 "WeakKeySizeRsaHigh": |
|
494 str(SecurityDefaults["weak_key_size_rsa_high"]), |
|
495 "WeakKeySizeRsaMedium": |
|
496 str(SecurityDefaults["weak_key_size_rsa_medium"]), |
|
497 "WeakKeySizeEcHigh": |
|
498 str(SecurityDefaults["weak_key_size_ec_high"]), |
|
499 "WeakKeySizeEcMedium": |
|
500 str(SecurityDefaults["weak_key_size_ec_medium"]), |
|
501 "CheckTypedException": |
|
502 SecurityDefaults["check_typed_exception"], |
|
503 } |
461 |
504 |
462 self.__initCategoriesList(self.__data["EnabledCheckerCategories"]) |
505 self.__initCategoriesList(self.__data["EnabledCheckerCategories"]) |
463 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"]) |
506 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"]) |
464 self.excludeMessagesEdit.setText(self.__data["ExcludeMessages"]) |
507 self.excludeMessagesEdit.setText(self.__data["ExcludeMessages"]) |
465 self.includeMessagesEdit.setText(self.__data["IncludeMessages"]) |
508 self.includeMessagesEdit.setText(self.__data["IncludeMessages"]) |
490 self.minAnnotationsCoverageSpinBox.setValue( |
533 self.minAnnotationsCoverageSpinBox.setValue( |
491 self.__data["AnnotationsChecker"]["MinimumCoverage"]) |
534 self.__data["AnnotationsChecker"]["MinimumCoverage"]) |
492 self.maxAnnotationsComplexitySpinBox.setValue( |
535 self.maxAnnotationsComplexitySpinBox.setValue( |
493 self.__data["AnnotationsChecker"]["MaximumComplexity"]) |
536 self.__data["AnnotationsChecker"]["MaximumComplexity"]) |
494 |
537 |
|
538 # security |
|
539 self.tmpDirectoriesEdit.setPlainText("\n".join( |
|
540 self.__data["SecurityChecker"]["HardcodedTmpDirectories"])) |
|
541 self.hashesEdit.setText(", ".join( |
|
542 self.__data["SecurityChecker"]["InsecureHashes"])) |
|
543 self.insecureSslProtocolsEdit.setPlainText("\n".join( |
|
544 self.__data["SecurityChecker"]["InsecureSslProtocolVersions"])) |
|
545 self.dsaHighRiskCombo.setCurrentText( |
|
546 self.__data["SecurityChecker"]["WeakKeySizeDsaHigh"]) |
|
547 self.dsaMediumRiskCombo.setCurrentText( |
|
548 self.__data["SecurityChecker"]["WeakKeySizeDsaMedium"]) |
|
549 self.rsaHighRiskCombo.setCurrentText( |
|
550 self.__data["SecurityChecker"]["WeakKeySizeRsaHigh"]) |
|
551 self.rsaMediumRiskCombo.setCurrentText( |
|
552 self.__data["SecurityChecker"]["WeakKeySizeRsaMedium"]) |
|
553 self.ecHighRiskCombo.setCurrentText( |
|
554 self.__data["SecurityChecker"]["WeakKeySizeEcHigh"]) |
|
555 self.ecMediumRiskCombo.setCurrentText( |
|
556 self.__data["SecurityChecker"]["WeakKeySizeEcMedium"]) |
|
557 self.typedExceptionsCheckBox.setChecked( |
|
558 self.__data["SecurityChecker"]["CheckTypedException"]) |
|
559 |
495 self.__cleanupData() |
560 self.__cleanupData() |
496 |
561 |
497 def start(self, fn, save=False, repeat=None): |
562 def start(self, fn, save=False, repeat=None): |
498 """ |
563 """ |
499 Public slot to start the code style check. |
564 Public slot to start the code style check. |
554 self.__resetStatistics() |
619 self.__resetStatistics() |
555 self.__clearErrors(self.files) |
620 self.__clearErrors(self.files) |
556 self.__cleanupData() |
621 self.__cleanupData() |
557 |
622 |
558 if len(self.files) > 0: |
623 if len(self.files) > 0: |
|
624 self.securityNoteLabel.setVisible( |
|
625 "S" in self.__getCategories(True, asList=True)) |
559 self.checkProgress.setMaximum(len(self.files)) |
626 self.checkProgress.setMaximum(len(self.files)) |
560 self.checkProgressLabel.setVisible(len(self.files) > 1) |
627 self.checkProgressLabel.setVisible(len(self.files) > 1) |
561 self.checkProgress.setVisible(len(self.files) > 1) |
628 self.checkProgress.setVisible(len(self.files) > 1) |
562 QApplication.processEvents() |
629 QApplication.processEvents() |
563 |
630 |
605 self.minAnnotationsCoverageSpinBox.value(), |
672 self.minAnnotationsCoverageSpinBox.value(), |
606 "MaximumComplexity": |
673 "MaximumComplexity": |
607 self.maxAnnotationsComplexitySpinBox.value(), |
674 self.maxAnnotationsComplexitySpinBox.value(), |
608 } |
675 } |
609 |
676 |
610 # TODO: add 'SecurityChecker' |
677 securityArgs = { |
611 safetyArgs = {} |
678 "hardcoded_tmp_directories": [ |
|
679 t.strip() |
|
680 for t in self.tmpDirectoriesEdit.toPlainText().splitlines() |
|
681 ], |
|
682 "insecure_hashes": [ |
|
683 h.strip() |
|
684 for h in self.hashesEdit.text().split(",") |
|
685 ], |
|
686 "insecure_ssl_protocol_versions": [ |
|
687 p.strip() |
|
688 for p in self.insecureSslProtocolsEdit.toPlainText() |
|
689 .splitlines() |
|
690 ], |
|
691 "weak_key_size_dsa_high": |
|
692 int(self.dsaHighRiskCombo.currentText()), |
|
693 "weak_key_size_dsa_medium": |
|
694 int(self.dsaMediumRiskCombo.currentText()), |
|
695 "weak_key_size_rsa_high": |
|
696 int(self.rsaHighRiskCombo.currentText()), |
|
697 "weak_key_size_rsa_medium": |
|
698 int(self.rsaMediumRiskCombo.currentText()), |
|
699 "weak_key_size_ec_high": |
|
700 int(self.ecHighRiskCombo.currentText()), |
|
701 "weak_key_size_ec_medium": |
|
702 int(self.ecMediumRiskCombo.currentText()), |
|
703 "check_typed_exception": |
|
704 self.typedExceptionsCheckBox.isChecked(), |
|
705 } |
612 |
706 |
613 self.__options = [excludeMessages, includeMessages, repeatMessages, |
707 self.__options = [excludeMessages, includeMessages, repeatMessages, |
614 fixCodes, noFixCodes, fixIssues, maxLineLength, |
708 fixCodes, noFixCodes, fixIssues, maxLineLength, |
615 maxDocLineLength, blankLines, hangClosing, |
709 maxDocLineLength, blankLines, hangClosing, |
616 docType, codeComplexityArgs, miscellaneousArgs, |
710 docType, codeComplexityArgs, miscellaneousArgs, |
617 annotationArgs, safetyArgs] |
711 annotationArgs, securityArgs] |
618 |
712 |
619 # now go through all the files |
713 # now go through all the files |
620 self.progress = 0 |
714 self.progress = 0 |
621 self.files.sort() |
715 self.files.sort() |
622 if len(self.files) == 1: |
716 if len(self.files) == 1: |
958 "AnnotationsChecker": { |
1052 "AnnotationsChecker": { |
959 "MinimumCoverage": |
1053 "MinimumCoverage": |
960 self.minAnnotationsCoverageSpinBox.value(), |
1054 self.minAnnotationsCoverageSpinBox.value(), |
961 "MaximumComplexity": |
1055 "MaximumComplexity": |
962 self.maxAnnotationsComplexitySpinBox.value(), |
1056 self.maxAnnotationsComplexitySpinBox.value(), |
963 } |
1057 }, |
964 |
1058 "SecurityChecker": { |
965 # TODO: add 'SecurityChecker' |
1059 "HardcodedTmpDirectories": [ |
|
1060 t.strip() |
|
1061 for t in self.tmpDirectoriesEdit.toPlainText() |
|
1062 .splitlines() |
|
1063 ], |
|
1064 "InsecureHashes": [ |
|
1065 h.strip() |
|
1066 for h in self.hashesEdit.text().split(",") |
|
1067 ], |
|
1068 "InsecureSslProtocolVersions": [ |
|
1069 p.strip() |
|
1070 for p in self.insecureSslProtocolsEdit.toPlainText() |
|
1071 .splitlines() |
|
1072 ], |
|
1073 "WeakKeySizeDsaHigh": |
|
1074 self.dsaHighRiskCombo.currentText(), |
|
1075 "WeakKeySizeDsaMedium": |
|
1076 self.dsaMediumRiskCombo.currentText(), |
|
1077 "WeakKeySizeRsaHigh": |
|
1078 self.rsaHighRiskCombo.currentText(), |
|
1079 "WeakKeySizeRsaMedium": |
|
1080 self.rsaMediumRiskCombo.currentText(), |
|
1081 "WeakKeySizeEcHigh": |
|
1082 self.ecHighRiskCombo.currentText(), |
|
1083 "WeakKeySizeEcMedium": |
|
1084 self.ecMediumRiskCombo.currentText(), |
|
1085 "CheckTypedException": |
|
1086 self.typedExceptionsCheckBox.isChecked(), |
|
1087 }, |
966 } |
1088 } |
967 if data != self.__data: |
1089 if data != self.__data: |
968 self.__data = data |
1090 self.__data = data |
969 self.__project.setData("CHECKERSPARMS", "Pep8Checker", |
1091 self.__project.setData("CHECKERSPARMS", "Pep8Checker", |
970 self.__data) |
1092 self.__data) |
1058 |
1180 |
1059 vm = e5App().getObject("ViewManager") |
1181 vm = e5App().getObject("ViewManager") |
1060 vm.openSourceFile(fn, lineno=lineno, pos=position + 1) |
1182 vm.openSourceFile(fn, lineno=lineno, pos=position + 1) |
1061 editor = vm.getOpenEditor(fn) |
1183 editor = vm.getOpenEditor(fn) |
1062 |
1184 |
1063 # TODO: add other syntax errors or do syntax check once for all |
|
1064 if code in ["E901", "E902"]: |
1185 if code in ["E901", "E902"]: |
1065 editor.toggleSyntaxError(lineno, 0, True, message, True) |
1186 editor.toggleSyntaxError(lineno, 0, True, message, True) |
1066 else: |
1187 else: |
1067 editor.toggleWarning( |
1188 editor.toggleWarning( |
1068 lineno, 0, True, message, warningType=editor.WarningStyle) |
1189 lineno, 0, True, message, warningType=editor.WarningStyle) |
1195 "PEP8/MinimumAnnotationsCoverage", 75))) |
1316 "PEP8/MinimumAnnotationsCoverage", 75))) |
1196 self.maxAnnotationsComplexitySpinBox.setValue(int( |
1317 self.maxAnnotationsComplexitySpinBox.setValue(int( |
1197 Preferences.Prefs.settings.value( |
1318 Preferences.Prefs.settings.value( |
1198 "PEP8/MaximumAnnotationComplexity", 3))) |
1319 "PEP8/MaximumAnnotationComplexity", 3))) |
1199 |
1320 |
1200 # TODO: add 'SecurityChecker' |
1321 # security |
|
1322 from .Security.SecurityDefaults import SecurityDefaults |
|
1323 self.tmpDirectoriesEdit.setPlainText("\n".join( |
|
1324 Preferences.toList(Preferences.Prefs.settings.value( |
|
1325 "PEP8/HardcodedTmpDirectories", |
|
1326 SecurityDefaults["hardcoded_tmp_directories"])))) |
|
1327 self.hashesEdit.setText(", ".join( |
|
1328 Preferences.toList(Preferences.Prefs.settings.value( |
|
1329 "PEP8/InsecureHashes", |
|
1330 SecurityDefaults["insecure_hashes"])))), |
|
1331 self.insecureSslProtocolsEdit.setPlainText("\n".join( |
|
1332 Preferences.toList(Preferences.Prefs.settings.value( |
|
1333 "PEP8/InsecureSslProtocolVersions", |
|
1334 SecurityDefaults["insecure_ssl_protocol_versions"])))), |
|
1335 self.dsaHighRiskCombo.setCurrentText( |
|
1336 Preferences.Prefs.settings.value( |
|
1337 "PEP8/WeakKeySizeDsaHigh", |
|
1338 str(SecurityDefaults["weak_key_size_dsa_high"]))) |
|
1339 self.dsaMediumRiskCombo.setCurrentText( |
|
1340 Preferences.Prefs.settings.value( |
|
1341 "PEP8/WeakKeySizeDsaMedium", |
|
1342 str(SecurityDefaults["weak_key_size_dsa_medium"]))), |
|
1343 self.rsaHighRiskCombo.setCurrentText( |
|
1344 Preferences.Prefs.settings.value( |
|
1345 "PEP8/WeakKeySizeRsaHigh", |
|
1346 str(SecurityDefaults["weak_key_size_rsa_high"]))), |
|
1347 self.rsaMediumRiskCombo.setCurrentText( |
|
1348 Preferences.Prefs.settings.value( |
|
1349 "PEP8/WeakKeySizeRsaMedium", |
|
1350 str(SecurityDefaults["weak_key_size_rsa_medium"]))), |
|
1351 self.ecHighRiskCombo.setCurrentText( |
|
1352 Preferences.Prefs.settings.value( |
|
1353 "PEP8/WeakKeySizeEcHigh", |
|
1354 str(SecurityDefaults["weak_key_size_ec_high"]))), |
|
1355 self.ecMediumRiskCombo.setCurrentText( |
|
1356 Preferences.Prefs.settings.value( |
|
1357 "PEP8/WeakKeySizeEcMedium", |
|
1358 str(SecurityDefaults["weak_key_size_ec_medium"]))), |
|
1359 self.typedExceptionsCheckBox.setChecked(Preferences.toBool( |
|
1360 Preferences.Prefs.settings.value( |
|
1361 "PEP8/CheckTypedException", |
|
1362 SecurityDefaults["check_typed_exception"]))), |
1201 |
1363 |
1202 self.__cleanupData() |
1364 self.__cleanupData() |
1203 |
1365 |
1204 @pyqtSlot() |
1366 @pyqtSlot() |
1205 def on_storeDefaultButton_clicked(self): |
1367 def on_storeDefaultButton_clicked(self): |
1264 self.minAnnotationsCoverageSpinBox.value()) |
1426 self.minAnnotationsCoverageSpinBox.value()) |
1265 Preferences.Prefs.settings.setValue( |
1427 Preferences.Prefs.settings.setValue( |
1266 "PEP8/MaximumAnnotationComplexity", |
1428 "PEP8/MaximumAnnotationComplexity", |
1267 self.maxAnnotationsComplexitySpinBox.value()) |
1429 self.maxAnnotationsComplexitySpinBox.value()) |
1268 |
1430 |
1269 # TODO: add 'SecurityChecker' |
1431 # security |
|
1432 Preferences.Prefs.settings.setValue( |
|
1433 "PEP8/HardcodedTmpDirectories", |
|
1434 [t.strip() |
|
1435 for t in self.tmpDirectoriesEdit.toPlainText().splitlines() |
|
1436 ]), |
|
1437 Preferences.Prefs.settings.setValue( |
|
1438 "PEP8/InsecureHashes", |
|
1439 [h.strip() |
|
1440 for h in self.hashesEdit.text().split(",") |
|
1441 ]), |
|
1442 Preferences.Prefs.settings.setValue( |
|
1443 "PEP8/InsecureSslProtocolVersions", |
|
1444 [p.strip() |
|
1445 for p in self.insecureSslProtocolsEdit.toPlainText().splitlines() |
|
1446 ]), |
|
1447 Preferences.Prefs.settings.setValue( |
|
1448 "PEP8/WeakKeySizeDsaHigh", |
|
1449 self.dsaHighRiskCombo.currentText()), |
|
1450 Preferences.Prefs.settings.setValue( |
|
1451 "PEP8/WeakKeySizeDsaMedium", |
|
1452 self.dsaMediumRiskCombo.currentText()), |
|
1453 Preferences.Prefs.settings.setValue( |
|
1454 "PEP8/WeakKeySizeRsaHigh", |
|
1455 self.rsaHighRiskCombo.currentText()), |
|
1456 Preferences.Prefs.settings.setValue( |
|
1457 "PEP8/WeakKeySizeRsaMedium", |
|
1458 self.rsaMediumRiskCombo.currentText()), |
|
1459 Preferences.Prefs.settings.setValue( |
|
1460 "PEP8/WeakKeySizeEcHigh", |
|
1461 self.ecHighRiskCombo.currentText()), |
|
1462 Preferences.Prefs.settings.setValue( |
|
1463 "PEP8/WeakKeySizeEcMedium", |
|
1464 self.ecMediumRiskCombo.currentText()), |
|
1465 Preferences.Prefs.settings.setValue( |
|
1466 "PEP8/CheckTypedException", |
|
1467 self.typedExceptionsCheckBox.isChecked()), |
1270 |
1468 |
1271 @pyqtSlot() |
1469 @pyqtSlot() |
1272 def on_resetDefaultButton_clicked(self): |
1470 def on_resetDefaultButton_clicked(self): |
1273 """ |
1471 """ |
1274 Private slot to reset the configuration values to their default values. |
1472 Private slot to reset the configuration values to their default values. |
1312 Preferences.Prefs.settings.setValue( |
1510 Preferences.Prefs.settings.setValue( |
1313 "PEP8/MinimumAnnotationsCoverage", 75) |
1511 "PEP8/MinimumAnnotationsCoverage", 75) |
1314 Preferences.Prefs.settings.setValue( |
1512 Preferences.Prefs.settings.setValue( |
1315 "PEP8/MaximumAnnotationComplexity", 3) |
1513 "PEP8/MaximumAnnotationComplexity", 3) |
1316 |
1514 |
1317 # TODO: add 'SecurityChecker' |
1515 # security |
|
1516 from .Security.SecurityDefaults import SecurityDefaults |
|
1517 Preferences.Prefs.settings.setValue( |
|
1518 "PEP8/HardcodedTmpDirectories", |
|
1519 SecurityDefaults["hardcoded_tmp_directories"]) |
|
1520 Preferences.Prefs.settings.setValue( |
|
1521 "PEP8/InsecureHashes", |
|
1522 SecurityDefaults["insecure_hashes"]) |
|
1523 Preferences.Prefs.settings.setValue( |
|
1524 "PEP8/InsecureSslProtocolVersions", |
|
1525 SecurityDefaults["insecure_ssl_protocol_versions"]) |
|
1526 Preferences.Prefs.settings.setValue( |
|
1527 "PEP8/WeakKeySizeDsaHigh", |
|
1528 str(SecurityDefaults["weak_key_size_dsa_high"])) |
|
1529 Preferences.Prefs.settings.setValue( |
|
1530 "PEP8/WeakKeySizeDsaMedium", |
|
1531 str(SecurityDefaults["weak_key_size_dsa_medium"])) |
|
1532 Preferences.Prefs.settings.setValue( |
|
1533 "PEP8/WeakKeySizeRsaHigh", |
|
1534 str(SecurityDefaults["weak_key_size_rsa_high"])) |
|
1535 Preferences.Prefs.settings.setValue( |
|
1536 "PEP8/WeakKeySizeRsaMedium", |
|
1537 str(SecurityDefaults["weak_key_size_rsa_medium"])) |
|
1538 Preferences.Prefs.settings.setValue( |
|
1539 "PEP8/WeakKeySizeEcHigh", |
|
1540 str(SecurityDefaults["weak_key_size_ec_high"])) |
|
1541 Preferences.Prefs.settings.setValue( |
|
1542 "PEP8/WeakKeySizeEcMedium", |
|
1543 str(SecurityDefaults["weak_key_size_ec_medium"])) |
|
1544 Preferences.Prefs.settings.setValue( |
|
1545 "PEP8/CheckTypedException", |
|
1546 SecurityDefaults["check_typed_exception"]) |
1318 |
1547 |
1319 # Update UI with default values |
1548 # Update UI with default values |
1320 self.on_loadDefaultButton_clicked() |
1549 self.on_loadDefaultButton_clicked() |
1321 |
1550 |
1322 @pyqtSlot(QAbstractButton) |
1551 @pyqtSlot(QAbstractButton) |