]> git.ipfire.org Git - pakfire.git/commitdiff
ui: Import CLI abstraction
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 30 Nov 2016 18:48:46 +0000 (19:48 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 30 Nov 2016 18:48:46 +0000 (19:48 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/pakfire/ui/base.py [new file with mode: 0644]
src/pakfire/ui/cli.py [new file with mode: 0644]

index dd8a739fd12b073a66bb078405f1c283015e279f..bdd4e63316b08fe8ffd14ed600c7d724f849fdd6 100644 (file)
@@ -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 (file)
index 0000000..9fe2145
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+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 (file)
index 0000000..68eddc6
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+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)