From 82b85704ce530fa0849b07891bb40517eadd5d82 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Thu, 5 Dec 2013 21:36:30 +0100 Subject: [PATCH] [entropy.output] make TextInterface methods classmethods This makes possible to fix a circular dependency in the Entropy Resources Lock management methods --- client/solo/commands/moo.py | 1 - lib/entropy/fetchers.py | 8 +++--- lib/entropy/output.py | 55 ++++++++++++++++++++----------------- rigo/RigoDaemon/app.py | 7 +++-- 4 files changed, 38 insertions(+), 33 deletions(-) diff --git a/client/solo/commands/moo.py b/client/solo/commands/moo.py index ed78761f2..248222664 100644 --- a/client/solo/commands/moo.py +++ b/client/solo/commands/moo.py @@ -12,7 +12,6 @@ import argparse from entropy.i18n import _ -from entropy.output import TextInterface from solo.commands.descriptor import SoloCommandDescriptor from solo.commands.command import SoloCommand diff --git a/lib/entropy/fetchers.py b/lib/entropy/fetchers.py index 8624e6a0d..76eb51033 100644 --- a/lib/entropy/fetchers.py +++ b/lib/entropy/fetchers.py @@ -909,7 +909,7 @@ class UrlFetcher(TextInterface): if len(average) < 2: average = " "+average current_txt += " <-> "+average+"% "+bartext - TextInterface.output(self, current_txt, back = True) + TextInterface.output(current_txt, back = True) def update(self): """ @@ -1131,7 +1131,7 @@ class MultipleUrlFetcher(TextInterface): def __show_download_files_info(self): count = 0 pl = self._url_path_list[:] - TextInterface.output(self, + TextInterface.output( "%s: %s %s" % ( darkblue(_("Aggregated download")), darkred(str(len(pl))), @@ -1145,7 +1145,7 @@ class MultipleUrlFetcher(TextInterface): count += 1 fname = os.path.basename(url) uri = spliturl(url)[1] - TextInterface.output(self, + TextInterface.output( "[%s] %s => %s" % ( darkblue(str(count)), darkgreen(uri), @@ -1299,7 +1299,7 @@ class MultipleUrlFetcher(TextInterface): if len(myavg) < 2: myavg = " "+myavg current_txt += " <-> "+myavg+"% "+bartext+" " - TextInterface.output(self, current_txt, back = True) + TextInterface.output(current_txt, back = True) self.__old_average = average diff --git a/lib/entropy/output.py b/lib/entropy/output.py index 649f0d50f..7c54fd2e0 100644 --- a/lib/entropy/output.py +++ b/lib/entropy/output.py @@ -687,7 +687,8 @@ class TextInterface(object): with the user, channel is bi-directional. """ - def output(self, text, header = "", footer = "", back = False, + @classmethod + def output(cls, text, header = "", footer = "", back = False, importance = 0, level = "info", count = None, percent = False): """ @@ -745,7 +746,8 @@ class TextInterface(object): myfunc(header+count_str+text+footer, back = back, flush = False) _flush_stdouterr() - def ask_question(self, question, importance = 0, responses = None): + @classmethod + def ask_question(cls, question, importance = 0, responses = None): """ Questions asking function. It asks the user to answer the question given @@ -803,7 +805,8 @@ class TextInterface(object): xterm_title_reset() _flush_stdouterr() - def input_box(self, title, input_parameters, cancel_button = True): + @classmethod + def input_box(cls, title, input_parameters, cancel_button = True): """ Generic input box (form) creator and data collector. @@ -844,11 +847,11 @@ class TextInterface(object): mydict = {} counter = 1 option_text, option_list = option_data - self.output(option_text) + cls.output(option_text) for item in option_list: mydict[counter] = item txt = "[%s] %s" % (darkgreen(str(counter)), blue(item),) - self.output(txt) + cls.output(txt) counter += 1 while True: try: @@ -874,17 +877,17 @@ class TextInterface(object): def list_editor(option_data, can_cancel, callback): def selaction(): - self.output('') - self.output(darkred(_("Please select an option"))) + cls.output('') + cls.output(darkred(_("Please select an option"))) if can_cancel: - self.output(" ("+blue("-1")+") "+darkred(_("Discard all"))) - self.output(" ("+blue("0")+") "+darkgreen(_("Confirm"))) - self.output(" ("+blue("1")+") "+brown(_("Add item"))) - self.output(" ("+blue("2")+") "+brown(_("Edit item"))) - self.output(" ("+blue("3")+") "+darkblue(_("Remove item"))) - self.output(" ("+blue("4")+") "+darkgreen(_("Show current list"))) + cls.output(" ("+blue("-1")+") "+darkred(_("Discard all"))) + cls.output(" ("+blue("0")+") "+darkgreen(_("Confirm"))) + cls.output(" ("+blue("1")+") "+brown(_("Add item"))) + cls.output(" ("+blue("2")+") "+brown(_("Edit item"))) + cls.output(" ("+blue("3")+") "+darkblue(_("Remove item"))) + cls.output(" ("+blue("4")+") "+darkgreen(_("Show current list"))) # wait user interaction - self.output('') + cls.output('') try: action = readtext(darkgreen(_("Your choice (type a number and press enter):"))+" ") except UnicodeDecodeError: @@ -898,18 +901,18 @@ class TextInterface(object): valid_actions.insert(0, -1) option_text, option_list = option_data txt = "%s:" % (blue(option_text),) - self.output(txt) + cls.output(txt) for item in option_list: mydict[counter] = item txt = "[%s] %s" % (darkgreen(str(counter)), blue(item),) - self.output(txt) + cls.output(txt) counter += 1 def show_current_list(): for key in sorted(mydict): txt = "[%s] %s" % (darkgreen(str(key)), blue(mydict[key]),) - self.output(txt) + cls.output(txt) while True: try: @@ -918,10 +921,10 @@ class TextInterface(object): show_current_list() action = int(sel_action) except (ValueError, TypeError,): - self.output(_("You don't have typed a number."), level = "warning") + cls.output(_("You don't have typed a number."), level = "warning") continue if action not in valid_actions: - self.output(_("Invalid action."), level = "warning") + cls.output(_("Invalid action."), level = "warning") continue if action == -1: raise KeyboardInterrupt() @@ -941,7 +944,7 @@ class TextInterface(object): mydict[counter] = s_el counter += 1 except (ValueError,): - self.output(_("Invalid string."), level = "warning") + cls.output(_("Invalid string."), level = "warning") continue break show_current_list() @@ -968,7 +971,7 @@ class TextInterface(object): raise ValueError() mydict[s_el] = new_s_val[:] except (ValueError, TypeError,): - self.output(_("Invalid element."), level = "warning") + cls.output(_("Invalid element."), level = "warning") continue break show_current_list() @@ -986,7 +989,7 @@ class TextInterface(object): raise ValueError() del mydict[s_el] except (ValueError, TypeError,): - self.output(_("Invalid element."), level = "warning") + cls.output(_("Invalid element."), level = "warning") continue break show_current_list() @@ -1007,7 +1010,7 @@ class TextInterface(object): myresult = False input_type, data = input_text if input_type == "checkbox": - answer = self.ask_question(data) + answer = cls.ask_question(data) if answer == _("Yes"): myresult = True elif input_type == "combo": @@ -1034,7 +1037,8 @@ class TextInterface(object): break return results - def edit_file(self, file_path): + @classmethod + def edit_file(cls, file_path): """ Open a file editor on given file path (file_path). @@ -1046,7 +1050,8 @@ class TextInterface(object): editor = os.getenv("EDITOR", "/bin/nano") return subprocess.call((editor, file_path)) == 0 - def set_title(self, title): + @classmethod + def set_title(cls, title): """ Set application title. diff --git a/rigo/RigoDaemon/app.py b/rigo/RigoDaemon/app.py index 4761d89d8..71a826ffc 100755 --- a/rigo/RigoDaemon/app.py +++ b/rigo/RigoDaemon/app.py @@ -187,16 +187,17 @@ class Entropy(Client): DaemonUrlFetcher.set_daemon(daemon) DaemonMultipleUrlFetcher.set_daemon(daemon) - def output(self, text, header = "", footer = "", back = False, + @classmethod + def output(cls, text, header = "", footer = "", back = False, importance = 0, level = "info", count = None, percent = False, _raw=False): - if self._DAEMON is not None: + if cls._DAEMON is not None: count_c = 0 count_t = 0 if count is not None: count_c, count_t = count GLib.idle_add( - self._DAEMON.output, + cls._DAEMON.output, text, header, footer, back, importance, level, count_c, count_t, percent, _raw)