Commit e023beb5 authored by Tristan Van Berkom's avatar Tristan Van Berkom

_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.
parent c205991e
Pipeline #22167696 passed with stages
in 30 minutes and 23 seconds
......@@ -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))
......
......@@ -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)
......
#!/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 <http://www.gnu.org/licenses/>.
#
# Authors:
# Tristan Van Berkom <tristan.vanberkom@codethink.co.uk>
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))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment