Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --batch-mode parameter for better scripts support #209

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions orangecanvas/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def setup_main_window(self):
window.setStyleSheet(stylesheet)
window.output_view().setDocument(self.output)
window.set_widget_registry(self.registry)
window.batch_mode = self.options.batch_mode
return window

def main_window_stylesheet(self):
Expand Down Expand Up @@ -493,6 +494,11 @@ def log_level(value):
"--no-welcome", action="store_true",
help="Don't show welcome dialog."
)
parser.add_argument(
"-b", "--batch-mode", action="store_true",
help="Run in batch mode - exit after initial workflow run, "
"print errors and return exit nonzero status if any error occured."
)
parser.add_argument(
"--no-splash", action="store_true",
help="Don't show splash screen."
Expand Down
25 changes: 25 additions & 0 deletions orangecanvas/scheme/signalmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,30 @@ def has_pending_ancestor(node): # type: (SchemeNode) -> bool
))
return ready

def exit_if_batch_mode(self):
if (
getattr(self.__workflow.parent(), 'batch_mode', False) and
len(self.pending_nodes()) == 0 and
len(self.blocking_nodes()) == 0 and
len(self.invalidated_nodes()) == 0
):
errored = False
for node in self.__nodes():
for _, message in node._SchemeNode__state_messages.items():
if message.contents:
if message.severity >= 3:
errored = True
severity_str = {
2: 'warning',
3: 'error',
1: 'information',
}[message.severity]
print(
f"'{node.title}' widget {severity_str}:"
f"\t{message.contents}"
)
quit(1 if errored else 0)

@Slot()
def __process_next(self):
if not self.__state == SignalManager.Running:
Expand All @@ -1016,6 +1040,7 @@ def __process_next(self):
return

if not self.__input_queue:
self.exit_if_batch_mode()
return
if self.__has_finished:
self.__has_finished = False
Expand Down