From: Michael Tremer Date: Wed, 30 Nov 2016 18:48:46 +0000 (+0100) Subject: ui: Import CLI abstraction X-Git-Tag: 0.9.28~1285^2~1451 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a25761553add7b23d45b853a78c28050097831b;p=pakfire.git ui: Import CLI abstraction Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index dd8a739fd..bdd4e6331 100644 --- a/Makefile.am +++ b/Makefile.am @@ -157,6 +157,8 @@ pakfire_repositorydir = $(pythondir)/pakfire/repository pakfire_ui_PYTHON = \ src/pakfire/ui/__init__.py \ + src/pakfire/ui/base.py \ + src/pakfire/ui/cli.py \ src/pakfire/ui/helpers.py \ src/pakfire/ui/progressbar.py diff --git a/src/pakfire/ui/base.py b/src/pakfire/ui/base.py new file mode 100644 index 000000000..9fe214544 --- /dev/null +++ b/src/pakfire/ui/base.py @@ -0,0 +1,39 @@ +#!/usr/bin/python +############################################################################### +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2014 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program 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 General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +class UI(object): + def __init__(self): + pass + + def is_interactive(self): + """ + Returns True if a user can interact with the interface. + """ + raise NotImplementedError + + def alert(self, msg): + """ + Prints an important message to the user. + """ + raise NotImplementedError + + def message(self, msg, level=None): + raise NotImplementedError diff --git a/src/pakfire/ui/cli.py b/src/pakfire/ui/cli.py new file mode 100644 index 000000000..68eddc6ff --- /dev/null +++ b/src/pakfire/ui/cli.py @@ -0,0 +1,41 @@ +#!/usr/bin/python +############################################################################### +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2014 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program 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 General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +import sys + +from . import base +from . import helpers + +class CliUI(base.UI): + def write(self, data): + print data, + + def is_interactive(self): + """ + Returns True if this is running on an interactive shell. + """ + return sys.stdin.isatty() and sys.stdout.isatty() and sys.stderr.isatty() + + def message(self, msg, level=None): + """ + Simply print out the given message. + """ + self.write("%s\n" % msg)