mirror of
https://github.com/SELinuxProject/setools
synced 2025-04-28 22:35:06 +00:00
ApolMainWindow: Do not save tab/workspace if there are errors.
Tabs should raise RuntimeError in save() if they have criteria errors. For #97 and #98.
This commit is contained in:
parent
a82be1fbdb
commit
09bca896da
@ -410,6 +410,16 @@ class ApolMainWindow(SEToolsWidget, QMainWindow):
|
|||||||
self.load_settings(new=True)
|
self.load_settings(new=True)
|
||||||
|
|
||||||
def save_settings(self):
|
def save_settings(self):
|
||||||
|
try:
|
||||||
|
settings = self._get_settings()
|
||||||
|
|
||||||
|
except RuntimeError:
|
||||||
|
self.log.critical("Errors in the query prevent saving the settings.")
|
||||||
|
self.error_msg.critical(self, "Unable to save settings",
|
||||||
|
"Please resolve errors in the query before saving the settings."
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
filename = QFileDialog.getSaveFileName(self, "Save analysis tab settings", "analysis.apolt",
|
filename = QFileDialog.getSaveFileName(self, "Save analysis tab settings", "analysis.apolt",
|
||||||
"Apol Tab Settings File (*.apolt);;"
|
"Apol Tab Settings File (*.apolt);;"
|
||||||
"All Files (*)")[0]
|
"All Files (*)")[0]
|
||||||
@ -417,8 +427,6 @@ class ApolMainWindow(SEToolsWidget, QMainWindow):
|
|||||||
if not filename:
|
if not filename:
|
||||||
return
|
return
|
||||||
|
|
||||||
settings = self._get_settings()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(filename, "w") as fd:
|
with open(filename, "w") as fd:
|
||||||
json.dump(settings, fd, indent=1)
|
json.dump(settings, fd, indent=1)
|
||||||
@ -556,14 +564,8 @@ class ApolMainWindow(SEToolsWidget, QMainWindow):
|
|||||||
format("\n\n".join(loading_errors)))
|
format("\n\n".join(loading_errors)))
|
||||||
|
|
||||||
def save_workspace(self):
|
def save_workspace(self):
|
||||||
filename = QFileDialog.getSaveFileName(self, "Save analysis workspace", "workspace.apolw",
|
|
||||||
"Apol Workspace Files (*.apolw);;"
|
|
||||||
"All Files (*)")[0]
|
|
||||||
|
|
||||||
if not filename:
|
|
||||||
return
|
|
||||||
|
|
||||||
workspace = {}
|
workspace = {}
|
||||||
|
try:
|
||||||
workspace["__policy__"] = os.path.abspath(str(self._policy))
|
workspace["__policy__"] = os.path.abspath(str(self._policy))
|
||||||
workspace["__permmap__"] = os.path.abspath(str(self._permmap))
|
workspace["__permmap__"] = os.path.abspath(str(self._permmap))
|
||||||
workspace["__tabs__"] = []
|
workspace["__tabs__"] = []
|
||||||
@ -579,6 +581,20 @@ class ApolMainWindow(SEToolsWidget, QMainWindow):
|
|||||||
|
|
||||||
workspace["__tabs__"].append(settings)
|
workspace["__tabs__"].append(settings)
|
||||||
|
|
||||||
|
except RuntimeError:
|
||||||
|
self.log.critical("Errors in the query prevent saving the workspace.")
|
||||||
|
self.error_msg.critical(self, "Unable to save workspace",
|
||||||
|
"Please resolve errors in tab \"{0}\" before saving the"
|
||||||
|
" settings.".format(self.AnalysisTabs.tabText(index)))
|
||||||
|
return
|
||||||
|
|
||||||
|
filename = QFileDialog.getSaveFileName(self, "Save analysis workspace", "workspace.apolw",
|
||||||
|
"Apol Workspace Files (*.apolw);;"
|
||||||
|
"All Files (*)")[0]
|
||||||
|
|
||||||
|
if not filename:
|
||||||
|
return
|
||||||
|
|
||||||
with open(filename, "w") as fd:
|
with open(filename, "w") as fd:
|
||||||
json.dump(workspace, fd, indent=1)
|
json.dump(workspace, fd, indent=1)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user