From e023beb56b180316a58f409d48f158e9dc1ece95 Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Thu, 17 May 2018 14:41:11 +0900 Subject: _frontend: Notify failures when on linux Opens the door to platform specific frontend features, and implements a platform specific "notify" method. This is based on Valentin David's patch on merge request 447, and this fixes issue #385. --- buildstream/_frontend/app.py | 40 +++++++++++++++++++++++++++++++++++++++ buildstream/_frontend/cli.py | 2 +- buildstream/_frontend/linuxapp.py | 34 +++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 buildstream/_frontend/linuxapp.py (limited to 'buildstream') diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py index 331c35fe2..fa07a9a54 100644 --- a/buildstream/_frontend/app.py +++ b/buildstream/_frontend/app.py @@ -125,6 +125,25 @@ class App(): # Set soft limit to hard limit resource.setrlimit(resource.RLIMIT_NOFILE, (limits[1], limits[1])) + # create() + # + # Should be used instead of the regular constructor. + # + # This will select a platform specific App implementation + # + # Args: + # The same args as the App() constructor + # + @classmethod + def create(cls, *args, **kwargs): + if sys.platform.startswith('linux'): + # Use an App with linux specific features + from .linuxapp import LinuxApp + return LinuxApp(*args, **kwargs) + else: + # The base App() class is default + return App(*args, **kwargs) + # initialized() # # Context manager to initialize the application and optionally run a session @@ -372,6 +391,24 @@ class App(): if self.stream: self.stream.cleanup() + ############################################################ + # Abstract Class Methods # + ############################################################ + + # notify() + # + # Notify the user of something which occurred, this + # is intended to grab attention from the user. + # + # This is guaranteed to only be called in interactive mode + # + # Args: + # title (str): The notification title + # text (str): The notification text + # + def notify(self, title, text): + pass + ############################################################ # Local Functions # ############################################################ @@ -521,6 +558,9 @@ class App(): while choice not in ['continue', 'quit', 'terminate', 'retry']: click.echo(summary, err=True) + self.notify("BuildStream failure", "{} on element {}" + .format(failure.action_name, element.name)) + try: choice = click.prompt("Choice:", default='continue', err=True, value_proc=_prefix_choice_value_proc(choices)) diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py index 3c91cf80d..c321fa99f 100644 --- a/buildstream/_frontend/cli.py +++ b/buildstream/_frontend/cli.py @@ -170,7 +170,7 @@ def cli(context, **kwargs): from .app import App # Create the App, giving it the main arguments - context.obj = App(dict(kwargs)) + context.obj = App.create(dict(kwargs)) context.call_on_close(context.obj.cleanup) diff --git a/buildstream/_frontend/linuxapp.py b/buildstream/_frontend/linuxapp.py new file mode 100644 index 000000000..436a619c8 --- /dev/null +++ b/buildstream/_frontend/linuxapp.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2018 Codethink Limited +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see . +# +# Authors: +# Tristan Van Berkom +import os +import click + +from .app import App + + +# A linux specific App implementation +# +class LinuxApp(App): + + def notify(self, title, text): + + term = os.environ('TERM') + if term in ('xterm', 'vte'): + click.echo("\033]777;notify;{};{}\007".format(title, text)) -- cgit v1.2.1