How to use _report_traceback method in Slash

Best Python code snippet using slash

__init__.py

Source:__init__.py Github

copy

Full Screen

1#!/usr/bin/python32## Printing troubleshooter3## Copyright (C) 2008, 2009, 2010, 2012 Red Hat, Inc.4## Author: Tim Waugh <twaugh@redhat.com>5## This program is free software; you can redistribute it and/or modify6## it under the terms of the GNU General Public License as published by7## the Free Software Foundation; either version 2 of the License, or8## (at your option) any later version.9## This program is distributed in the hope that it will be useful,10## but WITHOUT ANY WARRANTY; without even the implied warranty of11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12## GNU General Public License for more details.13## You should have received a copy of the GNU General Public License14## along with this program; if not, write to the Free Software15## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.16from gi.repository import Gdk17from gi.repository import Gtk18import pprint19import sys20import datetime21import time22import traceback23if __name__ == "__main__":24 import os.path25 import gettext26 gettext.textdomain ('system-config-printer')27 if sys.argv[0][0] != '/':28 cwd = os.getcwd ()29 path = cwd + os.path.sep + sys.argv[0]30 else:31 path = sys.argv[0]32 sub = os.path.dirname (path)33 root = os.path.dirname (sub)34 sys.path.append (root)35from . import base36from .base import *37class Troubleshooter:38 def __init__ (self, quitfn=None, parent=None):39 self._in_module_call = False40 main = Gtk.Window ()41 if parent:42 main.set_transient_for (parent)43 main.set_position (Gtk.WindowPosition.CENTER_ON_PARENT)44 main.set_modal (True)45 main.set_title (_("Printing troubleshooter"))46 main.set_property ("default-width", 400)47 main.set_property ("default-height", 350)48 main.connect ("delete_event", self.quit)49 self.main = main50 self.quitfn = quitfn51 vbox = Gtk.VBox ()52 main.add (vbox)53 ntbk = Gtk.Notebook ()54 ntbk.set_border_width (6)55 vbox.pack_start (ntbk, True, True, 0)56 vbox.pack_start (Gtk.HSeparator (), False, False, 0)57 box = Gtk.HButtonBox ()58 box.set_border_width (6)59 box.set_spacing (3)60 box.set_layout (Gtk.ButtonBoxStyle.END)61 back = Gtk.Button.new_from_stock (Gtk.STOCK_GO_BACK)62 back.connect ('clicked', self._on_back_clicked)63 back.set_sensitive (False)64 self.back = back65 close = Gtk.Button.new_from_stock (Gtk.STOCK_CLOSE)66 close.connect ('clicked', self.quit)67 self.close = close68 cancel = Gtk.Button.new_from_stock (Gtk.STOCK_CANCEL)69 cancel.connect ('clicked', self.quit)70 self.cancel = cancel71 forward = Gtk.Button.new_from_stock (Gtk.STOCK_GO_FORWARD)72 forward.connect ('clicked', self._on_forward_clicked)73 self.forward = forward74 box.pack_start (back, False, False, 0)75 box.pack_start (cancel, False, False, 0)76 box.pack_start (close, False, False, 0)77 box.pack_start (forward, False, False, 0)78 vbox.pack_start (box, False, False, 0)79 forward.set_property('can-default', True)80 forward.set_property('has-default', True)81 ntbk.set_current_page (0)82 ntbk.set_show_tabs (False)83 self.ntbk = ntbk84 self.current_page = 085 self.questions = []86 self.question_answers = []87 # timestamp should be accessible through whole troubleshoot88 now = datetime.datetime.fromtimestamp (time.time ())89 self.answers = {'error_log_timestamp': now.strftime ("%F %T")}90 self.moving_backwards = False91 main.show_all ()92 def quit (self, *args):93 if self._in_module_call:94 try:95 self.questions[self.current_page].cancel_operation ()96 except:97 self._report_traceback ()98 return99 try:100 self.questions[self.current_page].disconnect_signals ()101 except:102 self._report_traceback ()103 # Delete the questions so that their __del__ hooks can run.104 # Do this in reverse order of creation.105 for i in range (len (self.questions)):106 self.questions.pop ()107 self.main.hide ()108 if self.quitfn:109 self.quitfn (self)110 def get_window (self):111 # Any error dialogs etc from the modules need to be able112 # to set themselves transient for this window.113 return self.main114 def no_more_questions (self, question):115 page = self.questions.index (question)116 debugprint ("Page %d: No more questions." % page)117 self.questions = self.questions[:page + 1]118 self.question_answers = self.question_answers[:page + 1]119 for p in range (self.ntbk.get_n_pages () - 1, page, -1):120 self.ntbk.remove_page (p)121 self._set_back_forward_buttons ()122 def new_page (self, widget, question):123 page = len (self.questions)124 debugprint ("Page %d: new: %s" % (page, str (question)))125 self.questions.append (question)126 self.question_answers.append ([])127 self.ntbk.insert_page (widget, None, page)128 widget.show_all ()129 if page == 0:130 try:131 question.connect_signals (self._set_back_forward_buttons)132 except:133 self._report_traceback ()134 self.ntbk.set_current_page (page)135 self.current_page = page136 self._set_back_forward_buttons ()137 return page138 def is_moving_backwards (self):139 return self.moving_backwards140 def answers_as_text (self):141 text = ""142 n = 1143 for i in range (self.current_page):144 answers = self.question_answers[i].copy ()145 for hidden in [x for x in answers.keys() if x.startswith ("_")]:146 del answers[hidden]147 if len (list(answers.keys ())) == 0:148 continue149 text += "Page %d (%s):" % (n, self.questions[i]) + '\n'150 text += pprint.pformat (answers) + '\n'151 n += 1152 return text.rstrip () + '\n'153 def busy (self):154 self._in_module_call = True155 self.forward.set_sensitive (False)156 self.back.set_sensitive (False)157 gdkwin = self.get_window ().get_window()158 if gdkwin:159 gdkwin.set_cursor (Gdk.Cursor.new(Gdk.CursorType.WATCH))160 while Gtk.events_pending ():161 Gtk.main_iteration ()162 def ready (self):163 self._in_module_call = False164 gdkwin = self.get_window ().get_window()165 if gdkwin:166 gdkwin.set_cursor (Gdk.Cursor.new(Gdk.CursorType.LEFT_PTR))167 self._set_back_forward_buttons ()168 def _set_back_forward_buttons (self, *args):169 page = self.current_page170 self.back.set_sensitive (page != 0)171 if len (self.questions) == page + 1:172 # Out of questions.173 debugprint ("Out of questions")174 self.forward.set_sensitive (False)175 self.close.show ()176 self.cancel.hide ()177 else:178 can = self._can_click_forward (self.questions[page])179 debugprint ("Page %d: can click forward? %s" % (page, can))180 self.forward.set_sensitive (can)181 self.close.hide ()182 self.cancel.show ()183 def _on_back_clicked (self, widget):184 self.busy ()185 self.moving_backwards = True186 try:187 self.questions[self.current_page].disconnect_signals ()188 except:189 self._report_traceback ()190 self.current_page -= 1191 question = self.questions[self.current_page]192 while not self._display (question):193 # Skip this one. 194 debugprint ("Page %d: skip" % (self.current_page))195 self.current_page -= 1196 question = self.questions[self.current_page]197 self.ntbk.set_current_page (self.current_page)198 answers = {}199 for i in range (self.current_page):200 answers.update (self.question_answers[i])201 self.answers = answers202 try:203 self.questions[self.current_page].\204 connect_signals (self._set_back_forward_buttons)205 except:206 self._report_traceback ()207 self.moving_backwards = False208 self.ready ()209 def _on_forward_clicked (self, widget):210 self.busy ()211 answer_dict = self._collect_answer (self.questions[self.current_page])212 self.question_answers[self.current_page] = answer_dict213 self.answers.update (answer_dict)214 try:215 self.questions[self.current_page].disconnect_signals ()216 except:217 self._report_traceback ()218 self.current_page += 1219 question = self.questions[self.current_page]220 while not self._display (question):221 # Skip this one, but collect its answers.222 answer_dict = self._collect_answer (question)223 self.question_answers[self.current_page] = answer_dict224 self.answers.update (answer_dict)225 debugprint ("Page %d: skip" % (self.current_page))226 self.current_page += 1227 question = self.questions[self.current_page]228 self.ntbk.set_current_page (self.current_page)229 try:230 question.connect_signals (self._set_back_forward_buttons)231 except:232 self._report_traceback ()233 self.ready ()234 if get_debugging ():235 self._dump_answers ()236 def _dump_answers (self):237 debugprint (self.answers_as_text ())238 def _report_traceback (self):239 try:240 print("Traceback:")241 (type, value, tb) = sys.exc_info ()242 tblast = traceback.extract_tb (tb, limit=None)243 if len (tblast):244 tblast = tblast[:len (tblast) - 1]245 extxt = traceback.format_exception_only (type, value)246 for line in traceback.format_tb(tb):247 print(line.strip ())248 print(extxt[0].strip ())249 except:250 pass251 def _display (self, question):252 result = False253 try:254 result = question.display ()255 except:256 self._report_traceback ()257 question.displayed = result258 return result259 def _can_click_forward (self, question):260 try:261 return question.can_click_forward ()262 except:263 self._report_traceback ()264 return True265 def _collect_answer (self, question):266 answer = {}267 try:268 answer = question.collect_answer ()269 except:270 self._report_traceback ()271 return answer272QUESTIONS = ["Welcome",273 "SchedulerNotRunning",274 "CheckLocalServerPublishing",275 "ChoosePrinter",276 "CheckPrinterSanity",277 "CheckPPDSanity",278 "LocalOrRemote",279 "DeviceListed",280 "CheckUSBPermissions",281 "RemoteAddress",282 "CheckNetworkServerSanity",283 "ChooseNetworkPrinter",284 "NetworkCUPSPrinterShared",285 "QueueNotEnabled",286 "QueueRejectingJobs",287 "PrinterStateReasons",288 "VerifyPackages",289 "CheckSELinux",290 "ServerFirewalled",291 "ErrorLogCheckpoint",292 "PrintTestPage",293 "ErrorLogFetch",294 "PrinterStateReasons",295 "ErrorLogParse",296 "Locale",297 "Shrug"]298def run (quitfn=None, parent=None):299 troubleshooter = Troubleshooter (quitfn, parent=parent)300 modules_imported = []301 for module in QUESTIONS:302 try:303 if not module in modules_imported:304 exec ("from .%s import %s" % (module, module))305 modules_imported.append (module)306 exec ("%s (troubleshooter)" % module)307 except:308 troubleshooter._report_traceback ()309 return troubleshooter310if __name__ == "__main__":311 import getopt312 try:313 opts, args = getopt.gnu_getopt (sys.argv[1:], '',314 ['debug'])315 for opt, optarg in opts:316 if opt == '--debug':317 set_debugging (True)318 except getopt.GetoptError:319 pass320 Gdk.threads_init()321 run (Gtk.main_quit)322 Gdk.threads_enter ()323 Gtk.main ()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful