class fileAnalyzer: def __init__(self, filepath): self.filepath = filepath self.log_analyzer = LogAnalyzer(self.OnReadComplete) def OnReadComplete(self): for x in range(0, len(self.log_analyzer.msg_logs)): print self.log_analyzer.msg_logs[x] print "===========================================================" print len(self.log_analyzer.msg_logs) def ReadFile(self): self.log_analyzer.AnalyzeFile(filepath, pcktypes)
def openFile(self, Paths, selectedTypes): if not self._log_analyzer: Logger.info("Logviewer: Importing LogAnalyzer") from mobile_insight.analyzer import LogAnalyzer self._log_analyzer = LogAnalyzer(self.OnReadComplete) self._log_analyzer.AnalyzeFile(Paths, selectedTypes)
class LogViewerScreen(MobileInsightScreenBase): cancel = ObjectProperty(None) loaded = ObjectProperty(None) loadinggrid = ObjectProperty(None) ok = ObjectProperty(None) ReadComplete = ObjectProperty(None) name = StringProperty('LogViewerScreen') def __init__(self, **kw): super(LogViewerScreen, self).__init__(**kw) self._log_analyzer = None self.selectedTypes = None def SetInitialGrid(self, *args): if self.ReadComplete == 'Yes': self.ReadComplete = '' self.loaded = 'Yes' self.grid_scroll.effect_y = ScrollEffect() self.onReset() def exit_open_popup(self, instance): idx = self.app.available_screens.index('HomeScreen') self.app.go_screen(idx) return False def dismiss_open_popup(self): self.open_popup.dismiss() return False def dismiss_filter_popup(self, *args): self.filter_popup.dismiss() def dismiss_search_popup(self, *args): self.search_popup.dismiss() def dismiss_goto_popup(self, *args): self.goto_popup.dismiss() # Open # Pick a .mi2log file that you would like to load. # Logs are organized by their Type ID. # Click the row to see the whole log def onOpen(self, *args): self.open_popup = Popup( title='Open file', content=Open_Popup(load=self.load), # background_normal='', background_color=(0 / 255.0, 161 / 255.0, 247 / 255.0, 1), # color=(0/255.0, 161/255.0, 247/255.0, 1), auto_dismiss=True) # self.open_popup.bind(on_dismiss=self.exit_open_popup) self.open_popup.open() def load(self, path, filename, *args): load_failed_popup = Popup( title='Error while opening file', content=Label(text='Please select a valid file'), size_hint=(0.8, 0.2)) if filename == []: self.dismiss_open_popup() load_failed_popup.open() else: name, extension = os.path.splitext(filename[0]) if extension == ['.mi2log'][0]: self.loading_num = 2 self.loading_popup = Popup(title='', content=Label(text='Loading.', font_size=self.width / 25), size_hint=(0.3, 0.2), separator_height=0, title_size=0) self.loading_popup.open() Clock.schedule_interval(self.loading, 1) Clock.unschedule(self.check_scroll_limit) self.grid.clear_widgets() with open(os.path.join(path, filename[0])) as stream: t = Thread(target=self.openFile, args=(os.path.join(path, filename[0]), self.selectedTypes)) t.start() self.dismiss_open_popup() else: self.dismiss_open_popup() load_failed_popup.open() def openFile(self, Paths, selectedTypes): if not self._log_analyzer: Logger.info("Logviewer: Importing LogAnalyzer") from mobile_insight.analyzer import LogAnalyzer self._log_analyzer = LogAnalyzer(self.OnReadComplete) self._log_analyzer.AnalyzeFile(Paths, selectedTypes) def OnReadComplete(self): self.data = self._log_analyzer.msg_logs self.data_view = self.data self.ReadComplete = 'Yes' Clock.schedule_once(self.SetInitialGrid, 0.1) def check_scroll_limit(self, *args): if not self.loadinggrid == 'Yes': Move = '0' rows = len(self.data_view) scrolltop = self.grid_scroll.vbar[0] + self.grid_scroll.vbar[1] scrollbottom = self.grid_scroll.vbar[0] if rows <= 50: nrows = rows else: nrows = 50 if scrolltop >= 1 and self.k != 0: Move = 'up' self.SetUpGrid(self.data_view, rows, Move) if scrollbottom <= 0 and self.k != rows - nrows: Move = 'down' self.SetUpGrid(self.data_view, rows, Move) def SetUpGrid(self, data, rows, Move): self.grid.bind(minimum_height=self.grid.setter('height')) self.grid.clear_widgets() if rows <= 50: nrows = rows else: nrows = 50 if Move == 'init': self.k = 0 if Move == 'up' or Move == 'up!': self.k -= 25 if Move == 'down': self.k += 25 if rows <= self.k + 50 and Move != '': self.k = rows - 50 Move == 'over' if 0 >= self.k and Move != 'up!': self.k = 0 self.loadinggrid = 'Yes' if Move == 'init' or '': self.grid_scroll.scroll_y = 1 if Move == 'over': self.grid_scroll.scroll_y = 0 if Move == 'up' or Move == 'up!': self.grid_scroll.scroll_y = 1 - 25 / (nrows - 13.5) if Move == 'down': self.grid_scroll.scroll_y = 1 - 11.5 / (nrows - 13.5) if Move == '': self.grid_scroll.scroll_y = -13.5 / \ (nrows - 13.5) + (rows - self.k) / (nrows - 13.5) self.k = rows - nrows for i in range(self.k, self.k + nrows): self.grid.add_widget( Label(text=str(i + 1), size_hint_x=0.1, color=(0, 0, 0, 1))) self.grid.add_widget( Button(text=' ' + str(data[i]["Timestamp"]) + '\n ' + str(data[i]["TypeID"]), font_size=self.height / 50, on_release=self.grid_popup, id=str(data[i]["Payload"]), text_size=(self.width * 0.9, self.height * 0.05), background_normal='', background_color=(0 / 255.0, 161 / 255.0, 247 / 255.0, 0.65), halign='left')) self.loadinggrid = 'No' if self.loading_num != '': Clock.unschedule(self.loading) self.loading_popup.dismiss() self.loading_num = '' def grid_popup(self, data): val = xml.dom.minidom.parseString(data.id) pretty_xml_as_string = val.toprettyxml(indent=" ", newl="\n") scroll = ScrollView() label = TextInput(text=str(pretty_xml_as_string), readonly=True, size_hint_y=None) # label = TextInput(text = json.dumps(xmltodict.parse(pretty_xml_as_string), indent = 1), readonly = True, size_hint_y = None) label.bind(minimum_height=label.setter('height')) scroll.add_widget(label) popup = Popup(title='Timestamp : %s\nType : %s' % (str.split(data.text)[0], str.split(data.text)[2]), content=scroll, size_hint=(0.8, 0.8)) popup.open() def loading(self, *args): if self.loading_num == 1: self.loading_popup.content = Label(text='Loading.', font_size=self.width / 25) if self.loading_num == 2: self.loading_popup.content = Label(text='Loading..', font_size=self.width / 25) if self.loading_num == 3: self.loading_popup.content = Label(text='Loading...', font_size=self.width / 25) self.loading_num = 0 self.loading_num += 1 # GoBack # Go back to Home Screen def onGoBack(self, app): idx = app.available_screens.index('HomeScreen') app.go_screen(idx) # app.root.ids.sm.switch_to(app.home_screen) # Filter # Pick certain Type IDs to view # To reset everything, press the Reset button def onFilter(self): popup = BoxLayout(orientation='vertical', size=self.size, pos=self.pos) self.filter_popup = Popup(title='Filter', content=popup, size_hint=(0.9, 0.9), auto_dismiss=False) scroll = ScrollView() checkbox = GridLayout(cols=2, row_force_default=True, row_default_height=self.height / 20, size_hint_y=None) checkbox.bind(minimum_height=checkbox.setter('height')) select_all = GridLayout(cols=2, row_force_default=True, row_default_height=self.height / 20, size_hint_y=0.08) self.select_all_checkbox = CheckBox(size_hint_x=0.2) select_all_label = Label(text='Select All', text_size=(self.width * 0.7, None), halign='left') select_all.add_widget(self.select_all_checkbox) select_all.add_widget(select_all_label) cancel = Button(text='Cancel', on_release=self.dismiss_filter_popup) ok = Button(text='Ok', on_release=self.filter_ok) buttons = BoxLayout(size_hint_y=None, height=self.height / 20) buttons.add_widget(cancel) buttons.add_widget(ok) scroll.add_widget(checkbox) popup.add_widget(scroll) popup.add_widget(select_all) popup.add_widget(buttons) self.filter_rows = {} for i in range(len(self._log_analyzer.supported_types)): self.filter_rows[i] = CheckBox(size_hint_x=0.2) checkbox.add_widget(self.filter_rows[i]) checkbox.add_widget( Label(text=str(list(self._log_analyzer.supported_types)[i]))) self.select_all_checkbox.bind(active=self.filter_select_all) self.filter_popup.open() def filter_ok(self, *args): if self.loaded == 'Yes': self.selectedtypes = [] for i in range(len(self._log_analyzer.supported_types)): if self.filter_rows[i].active: self.selectedtypes += [ list(self._log_analyzer.supported_types)[i] ] if not self.selectedtypes == []: self.data_view = [ x for x in self.data_view if x["TypeID"] in self.selectedtypes ] self.SetUpGrid(self.data_view, len(self.data_view), 'init') Clock.unschedule(self.check_scroll_limit) Clock.schedule_interval(self.check_scroll_limit, 0.11) self.dismiss_filter_popup() else: self.dismiss_filter_popup() def filter_select_all(self, *args): if self.select_all_checkbox.active: for i in range(len(self._log_analyzer.supported_types)): self.filter_rows[i].active = True else: for i in range(len(self._log_analyzer.supported_types)): self.filter_rows[i].active = False # Search # Search for a keyword in the Payload that shows up when a row is pressed # To reset everything, press the Reset button def onSearch(self): popup = BoxLayout(orientation='vertical', size=self.size, pos=self.pos) self.search_popup = Popup(title='Search', content=popup, size_hint=(0.9, 0.25), auto_dismiss=False) self.search_textinput = TextInput() cancel = Button(text='Cancel', on_release=self.dismiss_search_popup) ok = Button(text='Ok', on_release=self.search_ok) buttons = BoxLayout(size_hint_y=None, height=self.height / 20) buttons.add_widget(cancel) buttons.add_widget(ok) popup.add_widget(self.search_textinput) popup.add_widget(buttons) self.search_popup.open() def search_ok(self, *args): if self.loaded == 'Yes': self.data_view = [ x for x in self.data_view if self.search_textinput.text in x["Payload"] ] self.SetUpGrid(self.data_view, len(self.data_view), 'init') self.dismiss_search_popup() Clock.unschedule(self.check_scroll_limit) Clock.schedule_interval(self.check_scroll_limit, 0.11) else: self.dismiss_search_popup() # Reset # Reset the grid to the state before filtering and/or searching def onReset(self): if self.loaded == 'Yes': self.data_view = self.data self.SetUpGrid(self.data_view, len(self.data_view), 'init') Clock.unschedule(self.check_scroll_limit) Clock.schedule_interval(self.check_scroll_limit, 0.11) # Go To # Go to the selected row def onGoTo(self): if self.loaded == 'Yes': popup = BoxLayout(orientation='vertical', size=self.size, pos=self.pos) self.goto_popup = Popup(title='Go To' + ' (1~' + str(len(self.data_view)) + ')', content=popup, size_hint=(0.9, 0.25), auto_dismiss=False) self.goto_textinput = TextInput() cancel = Button(text='Cancel', on_release=self.dismiss_goto_popup) ok = Button(text='Ok', on_release=self.goto_ok) buttons = BoxLayout(size_hint_y=None, height=self.height / 20) buttons.add_widget(cancel) buttons.add_widget(ok) popup.add_widget(self.goto_textinput) popup.add_widget(buttons) self.goto_popup.open() def goto_ok(self, *args): rows = len(self.data_view) num = self.goto_textinput.text if num.isdigit(): if int(num) > 0 and rows >= int(num): if int(num) >= rows - 12: self.k = rows self.dismiss_goto_popup() self.SetUpGrid(self.data, len(self.data), 'over') else: self.k = int(num) - 1 self.dismiss_goto_popup() if self.k >= rows - 24: self.SetUpGrid(self.data, len(self.data), '') else: self.SetUpGrid(self.data, len(self.data), 'up!') Clock.unschedule(self.check_scroll_limit) Clock.schedule_interval(self.check_scroll_limit, 0.11) else: self.dismiss_goto_popup() goto_failed_popup = Popup( title='Error', content=Label( text='Please write an integer in the given range'), size_hint=(0.8, 0.2)) goto_failed_popup.open() else: self.dismiss_goto_popup() goto_failed_popup = Popup( title='Error', content=Label( text='Please write an integer in the given range'), size_hint=(0.8, 0.2)) goto_failed_popup.open()
def openFile(self, Paths, selectedTypes): if not self._log_analyzer: self._log_analyzer = LogAnalyzer(self.OnReadComplete) self._log_analyzer.AnalyzeFile(Paths, selectedTypes)
def basicGUI(self): self._log_analyzer = LogAnalyzer(self.OnReadComplete) menuBar = wx.MenuBar() fileButton = wx.Menu() editButton = wx.Menu() openItem = fileButton.Append(ID_FILE_OPEN, "Open", "Open log file") exitItem = fileButton.Append(ID_FILE_EXIT, "Exit", "Exit application") menuBar.Append(fileButton, 'File') menuBar.Append(editButton, "Edit") self.SetMenuBar(menuBar) self.Bind(wx.EVT_MENU, self.Quit, exitItem) self.Bind(wx.EVT_MENU, self.Open, openItem) # Toolbar self.toolbar = self.CreateToolBar( wx.TB_FLAT | wx.TB_TEXT | wx.TB_HORIZONTAL | wx.NO_BORDER) toolbar_open = self.toolbar.AddLabelTool( ID_TB_OPEN, "Open", wx.Bitmap("/usr/local/share/mobileinsight/icons/open.png")) self.toolbar.AddSeparator() toolbar_filter = self.toolbar.AddLabelTool( ID_TB_FILTER, "Filter", wx.Bitmap("/usr/local/share/mobileinsight/icons/filter.png")) self.toolbar.AddSeparator() toolbar_search = self.toolbar.AddLabelTool( ID_TB_SEARCH, "Search", wx.Bitmap("/usr/local/share/mobileinsight/icons/search.png")) self.toolbar.AddSeparator() toolbar_time = self.toolbar.AddLabelTool( ID_TB_TIME, "Time Window", wx.Bitmap("/usr/local/share/mobileinsight/icons/time.png")) self.toolbar.AddSeparator() toolbar_reset = self.toolbar.AddLabelTool( ID_TB_RESET, "Reset", wx.Bitmap("/usr/local/share/mobileinsight/icons/reset.png")) # self.toolbar.AddSeparator() # toolbar_graph = self.toolbar.AddLabelTool(ID_TB_GRAPH, "Graph", wx.Bitmap("/usr/local/share/mobileinsight/icons/graph.png")) self.toolbar.AddSeparator() toolbar_about = self.toolbar.AddLabelTool( ID_TB_GRAPH, "About", wx.Bitmap("/usr/local/share/mobileinsight/icons/about.png")) self.Bind(wx.EVT_TOOL, self.Open, toolbar_open) self.Bind(wx.EVT_TOOL, self.OnFilter, toolbar_filter) self.Bind(wx.EVT_TOOL, self.OnSearch, toolbar_search) self.Bind(wx.EVT_TOOL, self.OnTime, toolbar_time) self.Bind(wx.EVT_TOOL, self.OnReset, toolbar_reset) # self.Bind(wx.EVT_TOOL, self.OnGraph, toolbar_graph) self.Bind(wx.EVT_TOOL, self.OnAbout, toolbar_about) self.toolbar.Realize() # Main Panel panel = wx.Panel(self, -1, size=(-1, -1), style=wx.BORDER_RAISED) mainSizer = wx.BoxSizer(wx.HORIZONTAL) hbox = wx.BoxSizer(wx.HORIZONTAL) self.grid = wx.grid.Grid(self) self.grid.CreateGrid(50, 2) self.grid.SetSelectionMode(1) # 1 is Select Row self.grid.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnGridSelect) self.grid.SetColLabelValue(0, "Timestamp") self.grid.SetColLabelValue(1, "Type ID") hbox.Add(self.grid, 5, wx.EXPAND | wx.ALL, 10) leftPanel = wx.Panel(self, -1, size=(-1, -1), style=wx.BORDER_RAISED) leftbox = wx.BoxSizer(wx.VERTICAL) self.status_text = wx.StaticText( leftPanel, label="Welcome to MobileInsight 5.0!\n\nMobileInsight is a Python 3 package for mobile network monitoring and analysis on the end device.", style=wx.ALIGN_LEFT) self.details_text = wx.TextCtrl( leftPanel, style=wx.ALIGN_LEFT | wx.TE_MULTILINE) leftbox.Add(self.status_text, 1, wx.EXPAND | wx.HORIZONTAL) leftbox.Add(self.details_text, 3, wx.EXPAND) leftPanel.SetSizer(leftbox) hbox.Add(leftPanel, 4, wx.EXPAND | wx.ALL, 10) self.grid.SetColSize(0, 200) self.grid.SetColSize(1, 300) self.grid.ForceRefresh() panel.SetSizer(hbox) mainSizer.Add(panel, 1, wx.EXPAND, 0) self.SetSizer(mainSizer) self.statusbar = self.CreateStatusBar() self.Bind(wx.EVT_CLOSE, self.Quit) self.SetTitle("MobileInsight") self.SetSize((1200, 800)) self.Centre() self.Show(True) self.data = None EVT_RESULT(self, self.OnResult)
class WindowClass(wx.Frame): def __init__(self, *args, **kwargs): super(WindowClass, self).__init__(*args, **kwargs) self.min_time = datetime.strptime("3000 Jan 1", '%Y %b %d') self.max_time = datetime.strptime("1900 Jan 1", '%Y %b %d') self.selectedTypes = None # Message Filters self.basicGUI() def basicGUI(self): self._log_analyzer = LogAnalyzer(self.OnReadComplete) menuBar = wx.MenuBar() fileButton = wx.Menu() editButton = wx.Menu() openItem = fileButton.Append(ID_FILE_OPEN, "Open", "Open log file") exitItem = fileButton.Append(ID_FILE_EXIT, "Exit", "Exit application") menuBar.Append(fileButton, 'File') menuBar.Append(editButton, "Edit") self.SetMenuBar(menuBar) self.Bind(wx.EVT_MENU, self.Quit, exitItem) self.Bind(wx.EVT_MENU, self.Open, openItem) # Toolbar self.toolbar = self.CreateToolBar( wx.TB_FLAT | wx.TB_TEXT | wx.TB_HORIZONTAL | wx.NO_BORDER) toolbar_open = self.toolbar.AddLabelTool( ID_TB_OPEN, "Open", wx.Bitmap("/usr/local/share/mobileinsight/icons/open.png")) self.toolbar.AddSeparator() toolbar_filter = self.toolbar.AddLabelTool( ID_TB_FILTER, "Filter", wx.Bitmap("/usr/local/share/mobileinsight/icons/filter.png")) self.toolbar.AddSeparator() toolbar_search = self.toolbar.AddLabelTool( ID_TB_SEARCH, "Search", wx.Bitmap("/usr/local/share/mobileinsight/icons/search.png")) self.toolbar.AddSeparator() toolbar_time = self.toolbar.AddLabelTool( ID_TB_TIME, "Time Window", wx.Bitmap("/usr/local/share/mobileinsight/icons/time.png")) self.toolbar.AddSeparator() toolbar_reset = self.toolbar.AddLabelTool( ID_TB_RESET, "Reset", wx.Bitmap("/usr/local/share/mobileinsight/icons/reset.png")) # self.toolbar.AddSeparator() # toolbar_graph = self.toolbar.AddLabelTool(ID_TB_GRAPH, "Graph", wx.Bitmap("/usr/local/share/mobileinsight/icons/graph.png")) self.toolbar.AddSeparator() toolbar_about = self.toolbar.AddLabelTool( ID_TB_GRAPH, "About", wx.Bitmap("/usr/local/share/mobileinsight/icons/about.png")) self.Bind(wx.EVT_TOOL, self.Open, toolbar_open) self.Bind(wx.EVT_TOOL, self.OnFilter, toolbar_filter) self.Bind(wx.EVT_TOOL, self.OnSearch, toolbar_search) self.Bind(wx.EVT_TOOL, self.OnTime, toolbar_time) self.Bind(wx.EVT_TOOL, self.OnReset, toolbar_reset) # self.Bind(wx.EVT_TOOL, self.OnGraph, toolbar_graph) self.Bind(wx.EVT_TOOL, self.OnAbout, toolbar_about) self.toolbar.Realize() # Main Panel panel = wx.Panel(self, -1, size=(-1, -1), style=wx.BORDER_RAISED) mainSizer = wx.BoxSizer(wx.HORIZONTAL) hbox = wx.BoxSizer(wx.HORIZONTAL) self.grid = wx.grid.Grid(self) self.grid.CreateGrid(50, 2) self.grid.SetSelectionMode(1) # 1 is Select Row self.grid.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnGridSelect) self.grid.SetColLabelValue(0, "Timestamp") self.grid.SetColLabelValue(1, "Type ID") hbox.Add(self.grid, 5, wx.EXPAND | wx.ALL, 10) leftPanel = wx.Panel(self, -1, size=(-1, -1), style=wx.BORDER_RAISED) leftbox = wx.BoxSizer(wx.VERTICAL) self.status_text = wx.StaticText( leftPanel, label="Welcome to MobileInsight 5.0!\n\nMobileInsight is a Python 3 package for mobile network monitoring and analysis on the end device.", style=wx.ALIGN_LEFT) self.details_text = wx.TextCtrl( leftPanel, style=wx.ALIGN_LEFT | wx.TE_MULTILINE) leftbox.Add(self.status_text, 1, wx.EXPAND | wx.HORIZONTAL) leftbox.Add(self.details_text, 3, wx.EXPAND) leftPanel.SetSizer(leftbox) hbox.Add(leftPanel, 4, wx.EXPAND | wx.ALL, 10) self.grid.SetColSize(0, 200) self.grid.SetColSize(1, 300) self.grid.ForceRefresh() panel.SetSizer(hbox) mainSizer.Add(panel, 1, wx.EXPAND, 0) self.SetSizer(mainSizer) self.statusbar = self.CreateStatusBar() self.Bind(wx.EVT_CLOSE, self.Quit) self.SetTitle("MobileInsight") self.SetSize((1200, 800)) self.Centre() self.Show(True) self.data = None EVT_RESULT(self, self.OnResult) def OnResult(self, event): if self.progressDialog: self.progressDialog.EndModal(wx.ID_CANCEL) self.progressDialog.Destroy() data = event.data if data: self.statusbar.SetStatusText("Read %d logs" % len(data)) self.data = data self.data_view = self.data self.SetupGrid() def Open(self, e): openFileDialog = wx.FileDialog( self, "Open Log file", "", "", "log files (*.mi2log) |*.mi2log| All files |*.*", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST | wx.FD_MULTIPLE) if (openFileDialog.ShowModal() == wx.ID_OK): # print 'Selected %s' %openFileDialog.GetPath() print(('Selected %s' % openFileDialog.Paths)) try: self.grid.ClearGrid() # thread.start_new_thread(openFile,(openFileDialog.GetPath(),)) # t = Thread(target = self.openFile, args=(openFileDialog.GetPath(),self.selectedTypes)) t = Thread( target=self.openFile, args=( openFileDialog.Paths, self.selectedTypes)) self.progressDialog = ProgressDialog(self) t.start() self.progressDialog.ShowModal() if len(openFileDialog.Paths) == 1: self.SetTitle(openFileDialog.GetPath()) else: self.SetTitle( "Multiple files in " + openFileDialog.Directory) except e: print(("Error while opening file.", e)) # if (random() > 0.5): # self.SetupGrid(self.data1) # else: # self.SetupGrid(self.data2) def OnFilter(self, e): types = list(self._log_analyzer.supported_types) checkboxDialog = MyMCD(self, "Filter", "", types) if (checkboxDialog.ShowModal() == wx.ID_OK): self.selectedTypes = [types[x] for x in checkboxDialog.GetSelections()] if self.data: self.data_view = [ x for x in self.data if x["TypeID"] in self.selectedTypes] self.SetupGrid() def OnTime(self, e): timewindowDialog = TimeWindowDialog(self, self.min_time, self.max_time) if (timewindowDialog.ShowModal() == wx.ID_OK): select_start = timewindowDialog.cur_start select_end = timewindowDialog.cur_end self.data_view = [ x for x in self.data_view if datetime.strptime( x["Timestamp"], '%Y-%m-%d %H:%M:%S.%f') >= select_start and datetime.strptime( x["Timestamp"], '%Y-%m-%d %H:%M:%S.%f') <= select_end] self.SetupGrid() def OnReset(self, e): if self.data: self.data_view = self.data self.SetupGrid() # def openFile(self, filePath,selectedTypes): # self._log_analyzer.AnalyzeFile(filePath,selectedTypes) def openFile(self, Paths, selectedTypes): self._log_analyzer.AnalyzeFile(Paths, selectedTypes) def OnSearch(self, e): search_dlg = wx.TextEntryDialog( self, "Search for", "", "", style=wx.OK | wx.CANCEL) if (search_dlg.ShowModal() == wx.ID_OK): keyword = search_dlg.GetValue() self.data_view = [ x for x in self.data_view if keyword in x["Payload"]] self.SetupGrid() search_dlg.Destroy() def OnAbout(self, e): about_text = ( 'MobileInsight GUI\n\n\n' + 'Copyright (c) 2014-2016 MobileInsight Team\n\n' + 'Developers:\n Moustafa Alzantot,\n' + ' Priyanka Avinash Kachare,\n' + ' Michael Ivan,\n' + ' Yuanjie Li') search_dlg = wx.MessageDialog( self, about_text, "About MobileInsight GUI", wx.OK) search_dlg.ShowModal() def OnGridSelect(self, e): #self.statusbar.SetStatusText("Selected %d" %e.GetRow()) row = e.GetRow() if (row < len(self.data_view)): self.status_text.SetLabel( "Time Stamp : %s Type : %s" % (str( self.data_view[row]["Timestamp"]), str( self.data_view[row]["TypeID"]))) # self.details_text.SetValue(str(self.data_view[row]["Payload"])) val = xml.dom.minidom.parseString( str(self.data_view[row]["Payload"])) pretty_xml_as_string = val.toprettyxml(indent=" ", newl="\n") self.details_text.SetValue(pretty_xml_as_string) e.Skip() def Quit(self, e): self.Destroy() def OnReadComplete(self): evt = ResultEvent(self._log_analyzer.msg_logs) wx.PostEvent(wx.GetApp().frame, evt) def SetupGrid(self): self.min_time = datetime.strptime("3000 Jan 1", '%Y %b %d') self.max_time = datetime.strptime("1900 Jan 1", '%Y %b %d') n = len(self.data_view) # self.grid.CreateGrid(max(25, n), 2) if n > self.grid.GetNumberRows(): self.grid.InsertRows(0, n - self.grid.GetNumberRows()) else: self.grid.DeleteRows(0, self.grid.GetNumberRows() - n) self.grid.ClearGrid() self.grid.SetColLabelValue(0, "Timestamp") self.grid.SetColLabelValue(1, "Type ID") for i in range(n): try: cur_time = datetime.strptime( self.data_view[i]["Timestamp"], '%Y-%m-%d %H:%M:%S.%f') except Exception as e: cur_time = datetime.strptime( self.data_view[i]["Timestamp"], '%Y-%m-%d %H:%M:%S') self.min_time = min(self.min_time, cur_time) self.max_time = max(self.max_time, cur_time) self.grid.SetCellValue(i, 0, str(self.data_view[i]["Timestamp"])) self.grid.SetCellValue(i, 1, str(self.data_view[i]["TypeID"])) self.grid.SetReadOnly(i, 0) self.grid.SetReadOnly(i, 1)
def __init__(self, filepath): self.filepath = filepath self.log_analyzer = LogAnalyzer(self.OnReadComplete)