diff --git a/bin/Helper.py b/bin/Helper.py index 1429904d..8d9caf3b 100755 --- a/bin/Helper.py +++ b/bin/Helper.py @@ -161,7 +161,9 @@ class Process(object): else: path = "?" value = str(timestamp) + ", " + path + complete_path = os.environ['AIL_HOME'] + "/PASTES/" + path self.r_temp.set("MODULE_"+self.subscriber_name + "_" + str(self.moduleNum), value) + self.r_temp.set("MODULE_"+self.subscriber_name + "_" + str(self.moduleNum) + "_PATH", complete_path) self.r_temp.sadd("MODULE_TYPE_"+self.subscriber_name, str(self.moduleNum)) return message @@ -169,6 +171,7 @@ class Process(object): path = "?" value = str(timestamp) + ", " + path self.r_temp.set("MODULE_"+self.subscriber_name + "_" + str(self.moduleNum), value) + self.r_temp.set("MODULE_"+self.subscriber_name + "_" + str(self.moduleNum) + "_PATH", complete_path) self.r_temp.sadd("MODULE_TYPE_"+self.subscriber_name, str(self.moduleNum)) return message diff --git a/bin/ModulesInformationV2.py b/bin/ModulesInformationV2.py index 8cb9bd4f..930d0075 100755 --- a/bin/ModulesInformationV2.py +++ b/bin/ModulesInformationV2.py @@ -16,6 +16,7 @@ import json import redis import psutil from subprocess import PIPE, Popen +from packages import Paste # CONFIG VARIABLES kill_retry_threshold = 60 #1m @@ -42,6 +43,8 @@ QUEUE_STATUS = {} CPU_TABLE = {} CPU_OBJECT_TABLE = {} +COMPLETE_PASTE_PATH_PER_PID = {} + class CListBox(ListBox): def __init__(self, queue_name, *args, **kwargs): @@ -299,16 +302,17 @@ class Action_choice(Frame): self.add_layout(layout) self.label = CLabel("Choose action on module {} {}") layout.add_widget(self.label) - layout2 = Layout([1,1,1]) + layout2 = Layout([1,1,1,1]) self.add_layout(layout2) layout2.add_widget(Button("Cancel", self._cancel), 0) + layout2.add_widget(Button("Show current paste", self._showpaste), 1) self._killBtn = Button("KILL", self._kill) - layout2.add_widget(self._killBtn, 1) - layout2.add_widget(Button("START", self._start), 2) - layout3 = Layout([1,1,1]) + layout2.add_widget(self._killBtn, 2) + layout2.add_widget(Button("START", self._start), 3) + layout3 = Layout([1,1,1,1]) self.add_layout(layout3) self.textEdit = Text("Amount", "amount") - layout3.add_widget(self.textEdit, 2) + layout3.add_widget(self.textEdit, 3) self.fix() @@ -340,6 +344,11 @@ class Action_choice(Frame): self.save() raise NextScene("dashboard") + def _showpaste(self): + self.label._text = "Choose action on module {} {}" + self.save() + raise NextScene("show_paste") + def _setValue(self): self._killBtn.disabled = False global current_selected_value, current_selected_queue @@ -352,14 +361,95 @@ class Action_choice(Frame): pid = "" self.label._text = self.label._text.format(modulename, pid) +class Show_paste(Frame): + def __init__(self, screen): + super(Show_paste, self).__init__(screen, + screen.height, + screen.width, + hover_focus=True, + on_load=self._setValue, + title="Show current paste", + reduce_cpu=True) + + # Create the form for displaying the list of contacts. + layout = Layout([100], fill_frame=True) + self.layout = layout + self.add_layout(layout) + + self.label_list = [] + self.num_label = 41 + for i in range(self.num_label): + self.label_list += [Label("THE PASTE CONTENT " + str(i))] + layout.add_widget(self.label_list[i]) + + layout2 = Layout([100]) + self.add_layout(layout2) + layout2.add_widget(Button("Ok", self._ok), 0) + self.fix() + + def _ok(self): + global current_selected_value, current_selected_queue, current_selected_action, current_selected_amount + current_selected_value = 0 + current_selected_amount = 0 + current_selected_action = "" + self.save() + raise NextScene("dashboard") + + def _setValue(self): + try: + #Verify that the module have a paste + if COMPLETE_PASTE_PATH_PER_PID[current_selected_value] is None: + self.label_list[0]._text = "No paste for this module" + for i in range(1,self.num_label): + self.label_list[i]._text = "" + return + + paste = Paste.Paste(COMPLETE_PASTE_PATH_PER_PID[current_selected_value]) + old_content = paste.get_p_content()[0:4000] + + #Replace unprintable char by ? + content = "" + for i, c in enumerate(old_content): + if ord(c) > 127: + content += '?' + else: + content += c + + #Print in the correct label + to_print = "" + i = 0 + for line in content.split("\n"): + if i==self.num_label: + break + self.label_list[i]._text = str(i) + ". " + line.replace("\r","") + i += 1 + + while i