本文整理汇总了Python中timedops.TimedOperation.cancel方法的典型用法代码示例。如果您正苦于以下问题:Python TimedOperation.cancel方法的具体用法?Python TimedOperation.cancel怎么用?Python TimedOperation.cancel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timedops.TimedOperation
的用法示例。
在下文中一共展示了TimedOperation.cancel方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from timedops import TimedOperation [as 别名]
# 或者: from timedops.TimedOperation import cancel [as 别名]
class PrinterFinder:
def __init__ (self):
self.quit = False
def find (self, hostname, callback_fn):
self.hostname = hostname
self.callback_fn = callback_fn
self.op = TimedOperation (self._do_find, callback=lambda x, y: None)
def cancel (self):
self.op.cancel ()
self.quit = True
def _do_find (self):
self._cached_attributes = dict()
for fn in [self._probe_jetdirect,
self._probe_ipp,
self._probe_snmp,
self._probe_lpd,
self._probe_hplip,
self._probe_smb]:
if self.quit:
return
try:
fn ()
except Exception, e:
nonfatalException ()
# Signal that we've finished.
if not self.quit:
self.callback_fn (None)
示例2: Welcome
# 需要导入模块: from timedops import TimedOperation [as 别名]
# 或者: from timedops.TimedOperation import cancel [as 别名]
class Welcome(Question):
def __init__ (self, troubleshooter):
Question.__init__ (self, troubleshooter, "Welcome")
welcome = gtk.HBox ()
welcome.set_spacing (12)
welcome.set_border_width (12)
image = gtk.Image ()
image.set_alignment (0, 0)
image.set_from_stock (gtk.STOCK_PRINT, gtk.ICON_SIZE_DIALOG)
intro = gtk.Label ('<span weight="bold" size="larger">' +
_("Trouble-shooting Printing") +
'</span>\n\n' +
_("The next few screens will contain some "
"questions about your problem with printing. "
"Based on your answers a solution may be "
"suggested.") + '\n\n' +
_("Click 'Forward' to begin."))
intro.set_alignment (0, 0)
intro.set_use_markup (True)
intro.set_line_wrap (True)
welcome.pack_start (image, False, False, 0)
welcome.pack_start (intro, True, True, 0)
page = troubleshooter.new_page (welcome, self)
def collect_answer (self):
parent = self.troubleshooter.get_window ()
# Store the authentication dialog instance in the answers. This
# allows the password to be cached.
factory = AuthConnFactory (parent)
self.op = TimedOperation (factory.get_connection, parent=parent)
return {'_authenticated_connection_factory': factory,
'_authenticated_connection': self.op.run () }
def cancel_operation (self):
self.op.cancel ()
示例3: NetworkCUPSPrinterShared
# 需要导入模块: from timedops import TimedOperation [as 别名]
# 或者: from timedops.TimedOperation import cancel [as 别名]
class NetworkCUPSPrinterShared(Question):
def __init__ (self, troubleshooter):
Question.__init__ (self, troubleshooter, "Queue not shared?")
page = self.initial_vbox (_("Queue Not Shared"),
_("The CUPS printer on the server is not "
"shared."))
troubleshooter.new_page (page, self)
def display (self):
self.answers = {}
answers = self.troubleshooter.answers
if ('remote_cups_queue_listed' in answers and
answers['remote_cups_queue_listed'] == False):
return False
parent = self.troubleshooter.get_window ()
if 'remote_cups_queue_attributes' not in answers:
if not ('remote_server_try_connect' in answers and
'remote_cups_queue' in answers):
return False
try:
host = answers['remote_server_try_connect']
self.op = TimedOperation (cups.Connection,
kwargs={"host": host},
parent=parent)
c = self.op.run ()
self.op = TimedOperation (c.getPrinterAttributes,
args=(answers['remote_cups_queue'],),
parent=parent)
attr = self.op.run ()
except RuntimeError:
return False
except cups.IPPError:
return False
self.answers['remote_cups_queue_attributes'] = attr
else:
attr = answers['remote_cups_queue_attributes']
if 'printer-is-shared' in attr:
# CUPS >= 1.2
if not attr['printer-is-shared']:
return True
return False
def can_click_forward (self):
return False
def collect_answer (self):
return self.answers
def cancel_operation (self):
self.op.cancel ()
示例4: SchedulerNotRunning
# 需要导入模块: from timedops import TimedOperation [as 别名]
# 或者: from timedops.TimedOperation import cancel [as 别名]
class SchedulerNotRunning(Question):
def __init__ (self, troubleshooter):
Question.__init__ (self, troubleshooter, "Scheduler not running?")
page = self.initial_vbox (_("CUPS Service Stopped"),
_("The CUPS print spooler does not appear "
"to be running. To correct this, choose "
"System->Administration->Services from "
"the main menu and look for the 'cups' "
"service."))
troubleshooter.new_page (page, self)
def display (self):
self.answers = {}
if self.troubleshooter.answers.get ('cups_queue_listed', False):
return False
parent = self.troubleshooter.get_window ()
# Find out if CUPS is running.
failure = False
try:
self.op = TimedOperation (cups.Connection,
parent=parent)
c = self.op.run ()
except RuntimeError:
failure = True
self.answers['cups_connection_failure'] = failure
return failure
def can_click_forward (self):
return False
def collect_answer (self):
return self.answers
def cancel_operation (self):
self.op.cancel ()
示例5: ErrorLogFetch
# 需要导入模块: from timedops import TimedOperation [as 别名]
# 或者: from timedops.TimedOperation import cancel [as 别名]
class ErrorLogFetch(Question):
def __init__ (self, troubleshooter):
Question.__init__ (self, troubleshooter, "Error log fetch")
troubleshooter.new_page (gtk.Label (), self)
self.persistent_answers = {}
def display (self):
answers = self.troubleshooter.answers
parent = self.troubleshooter.get_window ()
self.answers = {}
try:
checkpoint = answers['error_log_checkpoint']
except KeyError:
checkpoint = None
if self.persistent_answers.has_key ('error_log'):
checkpoint = None
def fetch_log (c):
prompt = c._get_prompt_allowed ()
c._set_prompt_allowed (False)
c._connect ()
(tmpfd, tmpfname) = tempfile.mkstemp ()
os.close (tmpfd)
success = False
try:
c.getFile ('/admin/log/error_log', tmpfname)
success = True
except cups.HTTPError:
try:
os.remove (tmpfname)
except OSError:
pass
c._set_prompt_allowed (prompt)
if success:
return tmpfname
return None
self.authconn = self.troubleshooter.answers['_authenticated_connection']
if answers.has_key ('error_log_debug_logging_set'):
try:
self.op = TimedOperation (self.authconn.adminGetServerSettings,
parent=parent)
settings = self.op.run ()
except cups.IPPError:
return False
settings[cups.CUPS_SERVER_DEBUG_LOGGING] = '0'
orig_settings = answers['cups_server_settings']
settings['MaxLogSize'] = orig_settings.get ('MaxLogSize', '2000000')
success = False
def set_settings (connection, settings):
connection.adminSetServerSettings (settings)
# Now reconnect.
attempt = 1
while attempt <= 5:
try:
time.sleep (1)
connection._connect ()
break
except RuntimeError:
# Connection failed
attempt += 1
try:
self.op = TimedOperation (set_settings,
(self.authconn, settings),
parent=parent)
self.op.run ()
self.persistent_answers['error_log_debug_logging_unset'] = True
except cups.IPPError:
pass
if checkpoint != None:
self.op = TimedOperation (fetch_log,
(self.authconn,),
parent=parent)
tmpfname = self.op.run ()
if tmpfname != None:
f = file (tmpfname)
f.seek (checkpoint)
lines = f.readlines ()
os.remove (tmpfname)
self.answers = { 'error_log': map (lambda x: x.strip (),
lines) }
return False
def collect_answer (self):
answers = self.persistent_answers.copy ()
answers.update (self.answers)
return answers
def cancel_operation (self):
self.op.cancel ()
# Abandon the CUPS connection and make another.
#.........这里部分代码省略.........
示例6: ErrorLogCheckpoint
# 需要导入模块: from timedops import TimedOperation [as 别名]
# 或者: from timedops.TimedOperation import cancel [as 别名]
#.........这里部分代码省略.........
args=('/admin/log/error_log', tmpfname),
parent=parent)
self.op.run ()
except RuntimeError:
try:
os.remove (tmpfname)
except OSError:
pass
return self.answers
except cups.IPPError:
try:
os.remove (tmpfname)
except OSError:
pass
return self.answers
statbuf = os.stat (tmpfname)
os.remove (tmpfname)
self.answers['error_log_checkpoint'] = statbuf[6]
self.persistent_answers['error_log_checkpoint'] = statbuf[6]
return self.answers
def can_click_forward (self):
return self.forward_allowed
def enable_clicked (self, button, handler):
parent = self.troubleshooter.get_window ()
self.troubleshooter.busy ()
try:
self.op = TimedOperation (self.authconn.adminGetServerSettings,
parent=parent)
settings = self.op.run ()
except (cups.IPPError, OperationCanceled):
self.troubleshooter.ready ()
self.forward_allowed = True
handler (button)
return
self.persistent_answers['cups_server_settings'] = settings.copy ()
MAXLOGSIZE='MaxLogSize'
try:
prev_debug = int (settings[cups.CUPS_SERVER_DEBUG_LOGGING])
except KeyError:
prev_debug = 0
try:
prev_logsize = int (settings[MAXLOGSIZE])
except (KeyError, ValueError):
prev_logsize = -1
if prev_debug == 0 or prev_logsize != '0':
settings[cups.CUPS_SERVER_DEBUG_LOGGING] = '1'
settings[MAXLOGSIZE] = '0'
success = False
def set_settings (connection, settings):
connection.adminSetServerSettings (settings)
# Now reconnect.
attempt = 1
while attempt <= 5:
try:
time.sleep (1)
connection._connect ()
break
except RuntimeError:
# Connection failed
attempt += 1
try:
debugprint ("Settings to set: " + repr (settings))
self.op = TimedOperation (set_settings,
args=(self.authconn, settings,),
parent=parent)
self.op.run ()
success = True
except cups.IPPError:
pass
except RuntimeError:
pass
if success:
self.persistent_answers['error_log_debug_logging_set'] = True
self.label.set_text (_("Debug logging enabled."))
else:
self.label.set_text (_("Debug logging was already enabled."))
self.forward_allowed = True
self.troubleshooter.ready ()
handler (button)
def cancel_operation (self):
self.op.cancel ()
# Abandon the CUPS connection and make another.
answers = self.troubleshooter.answers
factory = answers['_authenticated_connection_factory']
self.authconn = factory.get_connection ()
self.answers['_authenticated_connection'] = self.authconn
示例7: ErrorLogFetch
# 需要导入模块: from timedops import TimedOperation [as 别名]
# 或者: from timedops.TimedOperation import cancel [as 别名]
#.........这里部分代码省略.........
os.remove (tmpf.file)
except OSError:
pass
c._set_prompt_allowed (prompt)
if success:
return tmpf.file
return None
now = datetime.datetime.fromtimestamp (time.time ()).strftime ("%F %T")
self.authconn = self.troubleshooter.answers['_authenticated_connection']
if 'error_log_debug_logging_set' in answers:
try:
self.op = TimedOperation (self.authconn.adminGetServerSettings,
parent=parent)
settings = self.op.run ()
except cups.IPPError:
return False
settings[cups.CUPS_SERVER_DEBUG_LOGGING] = '0'
orig_settings = answers['cups_server_settings']
settings['MaxLogSize'] = orig_settings.get ('MaxLogSize', '2000000')
success = False
def set_settings (connection, settings):
connection.adminSetServerSettings (settings)
# Now reconnect.
attempt = 1
while attempt <= 5:
try:
time.sleep (1)
connection._connect ()
break
except RuntimeError:
# Connection failed
attempt += 1
try:
self.op = TimedOperation (set_settings,
(self.authconn, settings),
parent=parent)
self.op.run ()
self.persistent_answers['error_log_debug_logging_unset'] = True
except cups.IPPError:
pass
self.answers = {}
if journal and cursor != None:
def journal_format (x):
try:
priority = "XACEWNIDd"[x['PRIORITY']]
except (IndexError, TypeError):
priority = " "
return (priority + " " +
x['__REALTIME_TIMESTAMP'].strftime("[%m/%b/%Y:%T]") +
" " + x['MESSAGE'])
r = journal.Reader ()
r.seek_cursor (cursor)
r.add_match (_SYSTEMD_UNIT="cups.service")
self.answers['journal'] = [journal_format (x) for x in r]
if checkpoint != None:
self.op = TimedOperation (fetch_log,
(self.authconn,),
parent=parent)
tmpfname = self.op.run ()
if tmpfname != None:
f = open (tmpfname)
f.seek (checkpoint)
lines = f.readlines ()
os.remove (tmpfname)
self.answers = { 'error_log': [x.strip () for x in lines] }
if (len (self.answers.get ('journal', [])) +
len (self.answers.get ('error_log', []))) == 0:
cmd = ("su -c 'journalctl -u cups.service "
"--since=\"%s\" --until=\"%s\"' > troubleshoot-logs.txt" %
(answers['error_log_timestamp'], now))
self.entry.set_text (cmd)
return True
return False
def collect_answer (self):
answers = self.persistent_answers.copy ()
answers.update (self.answers)
return answers
def cancel_operation (self):
self.op.cancel ()
# Abandon the CUPS connection and make another.
answers = self.troubleshooter.answers
factory = answers['_authenticated_connection_factory']
self.authconn = factory.get_connection ()
self.answers['_authenticated_connection'] = self.authconn
示例8: ErrorLogFetch
# 需要导入模块: from timedops import TimedOperation [as 别名]
# 或者: from timedops.TimedOperation import cancel [as 别名]
#.........这里部分代码省略.........
c._set_prompt_allowed (False)
c._connect ()
(tmpfd, tmpfname) = tempfile.mkstemp ()
os.close (tmpfd)
success = False
try:
c.getFile ('/admin/log/error_log', tmpfname)
success = True
except cups.HTTPError:
try:
os.remove (tmpfname)
except OSError:
pass
c._set_prompt_allowed (prompt)
if success:
return tmpfname
return None
self.authconn = self.troubleshooter.answers['_authenticated_connection']
if 'error_log_debug_logging_set' in answers:
try:
self.op = TimedOperation (self.authconn.adminGetServerSettings,
parent=parent)
settings = self.op.run ()
except cups.IPPError:
return False
settings[cups.CUPS_SERVER_DEBUG_LOGGING] = '0'
orig_settings = answers['cups_server_settings']
settings['MaxLogSize'] = orig_settings.get ('MaxLogSize', '2000000')
success = False
def set_settings (connection, settings):
connection.adminSetServerSettings (settings)
# Now reconnect.
attempt = 1
while attempt <= 5:
try:
time.sleep (1)
connection._connect ()
break
except RuntimeError:
# Connection failed
attempt += 1
try:
self.op = TimedOperation (set_settings,
(self.authconn, settings),
parent=parent)
self.op.run ()
self.persistent_answers['error_log_debug_logging_unset'] = True
except cups.IPPError:
pass
self.answers = {}
if journal and cursor != None:
def journal_format (x):
try:
priority = "XACEWNIDd"[x['PRIORITY']]
except (IndexError, TypeError):
priority = " "
return (priority + " " +
x['__REALTIME_TIMESTAMP'].strftime("[%m/%b/%Y:%T]") +
" " + x['MESSAGE'])
r = journal.Reader ()
r.seek_cursor (cursor)
r.add_match (_COMM="cupsd")
self.answers['journal'] = [journal_format (x) for x in r]
if checkpoint != None:
self.op = TimedOperation (fetch_log,
(self.authconn,),
parent=parent)
tmpfname = self.op.run ()
if tmpfname != None:
f = open (tmpfname)
f.seek (checkpoint)
lines = f.readlines ()
os.remove (tmpfname)
self.answers = { 'error_log': [x.strip () for x in lines] }
return False
def collect_answer (self):
answers = self.persistent_answers.copy ()
answers.update (self.answers)
return answers
def cancel_operation (self):
self.op.cancel ()
# Abandon the CUPS connection and make another.
answers = self.troubleshooter.answers
factory = answers['_authenticated_connection_factory']
self.authconn = factory.get_connection ()
self.answers['_authenticated_connection'] = self.authconn
示例9: PrintTestPage
# 需要导入模块: from timedops import TimedOperation [as 别名]
# 或者: from timedops.TimedOperation import cancel [as 别名]
class PrintTestPage(Question):
STATE = { cups.IPP_JOB_PENDING: _("Pending"),
cups.IPP_JOB_HELD: _("Held"),
cups.IPP_JOB_PROCESSING: _("Processing"),
cups.IPP_JOB_STOPPED: _("Stopped"),
cups.IPP_JOB_CANCELED: _("Canceled"),
cups.IPP_JOB_ABORTED: _("Aborted"),
cups.IPP_JOB_COMPLETED: _("Completed") }
def __init__ (self, troubleshooter):
Question.__init__ (self, troubleshooter, "Print test page")
page = Gtk.VBox ()
page.set_spacing (12)
page.set_border_width (12)
label = Gtk.Label ()
label.set_alignment (0, 0)
label.set_use_markup (True)
label.set_line_wrap (True)
page.pack_start (label, False, False, 0)
self.main_label = label
self.main_label_text = ('<span weight="bold" size="larger">' +
_("Test Page") + '</span>\n\n' +
_("Now print a test page. If you are having "
"problems printing a specific document, "
"print that document now and mark the print "
"job below."))
hbox = Gtk.HButtonBox ()
hbox.set_border_width (0)
hbox.set_spacing (3)
hbox.set_layout (Gtk.ButtonBoxStyle.START)
self.print_button = Gtk.Button.new_with_label (_("Print Test Page"))
hbox.pack_start (self.print_button, False, False, 0)
self.cancel_button = Gtk.Button.new_with_label (_("Cancel All Jobs"))
hbox.pack_start (self.cancel_button, False, False, 0)
page.pack_start (hbox, False, False, 0)
tv = Gtk.TreeView ()
test_cell = Gtk.CellRendererToggle ()
test = Gtk.TreeViewColumn (_("Test"), test_cell, active=0)
job = Gtk.TreeViewColumn (_("Job"), Gtk.CellRendererText (), text=1)
printer_cell = Gtk.CellRendererText ()
printer = Gtk.TreeViewColumn (_("Printer"), printer_cell, text=2)
name_cell = Gtk.CellRendererText ()
name = Gtk.TreeViewColumn (_("Document"), name_cell, text=3)
status = Gtk.TreeViewColumn (_("Status"), Gtk.CellRendererText (),
text=4)
test_cell.set_radio (False)
self.test_cell = test_cell
printer.set_resizable (True)
printer_cell.set_property ("ellipsize", Pango.EllipsizeMode.END)
printer_cell.set_property ("width-chars", 20)
name.set_resizable (True)
name_cell.set_property ("ellipsize", Pango.EllipsizeMode.END)
name_cell.set_property ("width-chars", 20)
status.set_resizable (True)
tv.append_column (test)
tv.append_column (job)
tv.append_column (printer)
tv.append_column (name)
tv.append_column (status)
tv.set_rules_hint (True)
sw = Gtk.ScrolledWindow ()
sw.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
sw.set_shadow_type (Gtk.ShadowType.IN)
sw.add (tv)
self.treeview = tv
page.pack_start (sw, False, False, 0)
label = Gtk.Label(label=_("Did the marked print jobs print correctly?"))
label.set_line_wrap (True)
label.set_alignment (0, 0)
page.pack_start (label, False, False, 0)
vbox = Gtk.VBox ()
vbox.set_spacing (6)
self.yes = Gtk.RadioButton (label=_("Yes"))
no = Gtk.RadioButton.new_with_label_from_widget (self.yes, _("No"))
vbox.pack_start (self.yes, False, False, 0)
vbox.pack_start (no, False, False, 0)
page.pack_start (vbox, False, False, 0)
self.persistent_answers = {}
troubleshooter.new_page (page, self)
def display (self):
answers = self.troubleshooter.answers
if 'cups_queue' not in answers:
return False
parent = self.troubleshooter.get_window ()
self.authconn = answers['_authenticated_connection']
mediatype = None
defaults = answers.get ('cups_printer_ppd_defaults', {})
for opts in defaults.values ():
for opt, value in opts.items ():
if opt == "MediaType":
mediatype = value
break
#.........这里部分代码省略.........
示例10: __init__
# 需要导入模块: from timedops import TimedOperation [as 别名]
# 或者: from timedops.TimedOperation import cancel [as 别名]
class PrinterFinder:
def __init__ (self):
self.quit = False
def find (self, hostname, callback_fn):
self.hostname = hostname
self.callback_fn = callback_fn
self.op = TimedOperation (self._do_find, callback=lambda x, y: None)
def cancel (self):
self.op.cancel ()
self.quit = True
def _do_find (self):
self._cached_attributes = dict()
for fn in [self._probe_hplip,
self._probe_jetdirect,
self._probe_ipp,
self._probe_snmp,
self._probe_lpd,
self._probe_smb]:
if self.quit:
return
try:
fn ()
except Exception:
nonfatalException ()
# Signal that we've finished.
if not self.quit:
self.callback_fn (None)
def _new_device (self, uri, info, location = None):
device_dict = { 'device-class': 'network',
'device-info': "%s" % info }
if location:
device_dict['device-location']=location
device_dict.update (self._cached_attributes)
new_device = cupshelpers.Device (uri, **device_dict)
debugprint ("Device found: %s" % uri)
self.callback_fn (new_device)
def _probe_snmp (self):
# Run the CUPS SNMP backend, pointing it at the host.
try:
debugprint ("snmp: trying")
p = subprocess.Popen (args=["/usr/lib/cups/backend/snmp",
self.hostname],
close_fds=True,
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
except OSError as e:
debugprint ("snmp: no good")
if e.errno == errno.ENOENT:
return
raise
(stdout, stderr) = p.communicate ()
if p.returncode != 0:
debugprint ("snmp: no good (return code %d)" % p.returncode)
return
if self.quit:
debugprint ("snmp: no good")
return
for line in stdout.decode ().split ('\n'):
words = wordsep (line)
n = len (words)
if n == 6:
(device_class, uri, make_and_model,
info, device_id, device_location) = words
elif n == 5:
(device_class, uri, make_and_model, info, device_id) = words
elif n == 4:
(device_class, uri, make_and_model, info) = words
else:
continue
device_dict = { 'device-class': device_class,
'device-make-and-model': make_and_model,
'device-info': info }
if n == 5:
debugprint ("snmp: Device ID found:\n%s" %
device_id)
device_dict['device-id'] = device_id
if n == 6:
device_dict['device-location'] = device_location
device = cupshelpers.Device (uri, **device_dict)
debugprint ("Device found: %s" % uri)
self.callback_fn (device)
# Cache the make and model for use by other search methods
# that are not able to determine it.
self._cached_attributes['device-make-and-model'] = make_and_model
self._cached_attributes['device_id'] = device_id
#.........这里部分代码省略.........
示例11: ChooseNetworkPrinter
# 需要导入模块: from timedops import TimedOperation [as 别名]
# 或者: from timedops.TimedOperation import cancel [as 别名]
#.........这里部分代码省略.........
model = Gtk.ListStore (str,
str,
str,
GObject.TYPE_PYOBJECT)
self.model = model
self.treeview.set_model (model)
iter = model.append (None)
model.set (iter, 0, _("Not listed"), 1, '', 2, '', 3, 0)
parent = self.troubleshooter.get_window ()
try:
self.op = TimedOperation (cups.Connection,
kwargs={"host": server},
parent=parent)
c = self.op.run ()
self.op = TimedOperation (c.getDests, parent=parent)
dests = self.op.run ()
printers = None
dests_list = []
for (name, instance), dest in dests.items ():
if name is None:
continue
if instance is not None:
queue = "%s/%s" % (name, instance)
else:
queue = name
if printers is None:
self.op = TimedOperation (c.getPrinters)
printers = self.op.run ()
if name not in printers:
info = _("Unknown")
location = _("Unknown")
else:
printer = printers[name]
info = printer.get('printer-info', _("Unknown"))
location = printer.get('printer-location', _("Unknown"))
dests_list.append ((queue, location, info, dest))
dests_list.sort (key=lambda x: x[0])
for queue, location, info, dest in dests_list:
iter = model.append (None)
model.set (iter, 0, queue, 1, location, 2, info, 3, dest)
except cups.HTTPError:
pass
except cups.IPPError:
pass
except RuntimeError:
pass
return True
def connect_signals (self, handler):
self.signal_id = self.treeview.connect ("cursor-changed", handler)
def disconnect_signals (self):
self.treeview.disconnect (self.signal_id)
def can_click_forward (self):
model, iter = self.treeview.get_selection ().get_selected ()
if iter is None:
return False
return True
def collect_answer (self):
if not self.troubleshooter.answers.get ('remote_server_cups', False):
return {}
model, iter = self.treeview.get_selection ().get_selected ()
if not model:
return {}
dest = model.get_value (iter, 3)
if dest == 0:
class enum_dests:
def __init__ (self, model):
self.dests = []
model.foreach (self.each, None)
def each (self, model, path, iter, user_data):
dest = model.get_value (iter, 3)
if dest:
self.dests.append ((dest.name, dest.instance))
return { 'remote_cups_queue_listed': False,
'remote_cups_dests_available': enum_dests (model).dests }
else:
return { 'remote_cups_queue_listed': True,
'remote_cups_dest': dest,
'remote_cups_queue': dest.name,
'remote_cups_instance': dest.instance }
def cancel_operation (self):
self.op.cancel ()
示例12: DeviceListed
# 需要导入模块: from timedops import TimedOperation [as 别名]
# 或者: from timedops.TimedOperation import cancel [as 别名]
#.........这里部分代码省略.........
model.set (iter, 0, _("Not listed"), 1, '', 2, '', 3, NotListed)
devices = {}
parent = self.troubleshooter.get_window ()
# Skip device list if this page is hidden and we're skipping
# backwards past it.
if not (answers['cups_queue_listed'] and
self.troubleshooter.is_moving_backwards ()):
# Otherwise, fetch devices.
self.authconn = answers['_authenticated_connection']
try:
self.op = TimedOperation (self.authconn.getDevices,
parent=parent)
devices = self.op.run ()
devices_list = []
for uri, device in devices.items ():
if uri.find (':') == -1:
continue
if device.get('device-class') != 'direct':
continue
name = device.get('device-info', _("Unknown"))
info = device.get('device-make-and-model', _("Unknown"))
devices_list.append ((name, info, uri, device))
devices_list.sort (key=lambda x: x[0])
for name, info, uri, device in devices_list:
iter = model.append (None)
model.set (iter, 0, name, 1, info, 2, uri, 3, device)
except cups.HTTPError:
pass
except cups.IPPError:
pass
except RuntimeError:
pass
if answers['cups_queue_listed']:
try:
printer_dict = answers['cups_printer_dict']
uri = printer_dict['device-uri']
device = devices[uri]
self.answers['cups_device_dict'] = device
except KeyError:
pass
return False
return True
def connect_signals (self, handler):
self.signal_id = self.treeview.connect ("cursor-changed", handler)
def disconnect_signals (self):
self.treeview.disconnect (self.signal_id)
def can_click_forward (self):
model, iter = self.treeview.get_selection ().get_selected ()
if iter is None:
return False
return True
def collect_answer (self):
if not self.displayed:
return self.answers
model, iter = self.treeview.get_selection ().get_selected ()
device = model.get_value (iter, 3)
if device == NotListed:
class enum_devices:
def __init__ (self, model):
self.devices = {}
model.foreach (self.each, None)
def each (self, model, path, iter, user_data):
uri = model.get_value (iter, 2)
device = model.get_value (iter, 3)
if device != NotListed:
self.devices[uri] = device
self.answers['cups_device_listed'] = False
avail = enum_devices (model).devices
self.answers['cups_devices_available'] = avail
else:
uri = model.get_value (iter, 2)
self.answers['cups_device_listed'] = True
self.answers['cups_device_uri'] = uri
self.answers['cups_device_attributes'] = device
return self.answers
def cancel_operation (self):
self.op.cancel ()
# Abandon the CUPS connection and make another.
answers = self.troubleshooter.answers
factory = answers['_authenticated_connection_factory']
self.authconn = factory.get_connection ()
self.answers['_authenticated_connection'] = self.authconn
示例13: PrinterStateReasons
# 需要导入模块: from timedops import TimedOperation [as 别名]
# 或者: from timedops.TimedOperation import cancel [as 别名]
class PrinterStateReasons(Question):
def __init__ (self, troubleshooter):
Question.__init__ (self, troubleshooter, "Printer state reasons")
page = self.initial_vbox (_("Status Messages"),
_("There are status messages associated with "
"this queue."))
self.label = Gtk.Label ()
self.label.set_alignment (0, 0)
self.label.set_line_wrap (True)
page.pack_start (self.label, False, False, 0)
troubleshooter.new_page (page, self)
def display (self):
troubleshooter = self.troubleshooter
try:
queue = troubleshooter.answers['cups_queue']
except KeyError:
return False
parent = self.troubleshooter.get_window ()
cups.setServer ('')
self.op = TimedOperation (cups.Connection, parent=parent)
c = self.op.run ()
self.op = TimedOperation (c.getPrinterAttributes,
args=(queue,),
parent=parent)
dict = self.op.run ()
the_ppdcache = ppdcache.PPDCache ()
text = ''
state_message = dict['printer-state-message']
if state_message:
text += _("The printer's state message is: '%s'.") % state_message
text += '\n\n'
state_reasons_list = dict['printer-state-reasons']
if type (state_reasons_list) == str:
state_reasons_list = [state_reasons_list]
self.state_message = state_message
self.state_reasons = state_reasons_list
human_readable_errors = []
human_readable_warnings = []
for reason in state_reasons_list:
if reason == "none":
continue
r = statereason.StateReason (queue, reason, the_ppdcache)
(title, description) = r.get_description ()
level = r.get_level ()
if level == statereason.StateReason.ERROR:
human_readable_errors.append (description)
elif level == statereason.StateReason.WARNING:
human_readable_warnings.append (description)
if human_readable_errors:
text += _("Errors are listed below:") + '\n'
text += reduce (lambda x, y: x + "\n" + y, human_readable_errors)
text += '\n\n'
if human_readable_warnings:
text += _("Warnings are listed below:") + '\n'
text += reduce (lambda x, y: x + "\n" + y, human_readable_warnings)
self.label.set_text (text)
if (state_message == '' and
len (human_readable_errors) == 0 and
len (human_readable_warnings) == 0):
return False
# If this screen has been show before, don't show it again if
# nothing changed.
if 'printer-state-message' in troubleshooter.answers:
if (troubleshooter.answers['printer-state-message'] ==
self.state_message and
troubleshooter.answers['printer-state-reasons'] ==
self.state_reasons):
return False
return True
def collect_answer (self):
if not self.displayed:
return {}
return { 'printer-state-message': self.state_message,
'printer-state-reasons': self.state_reasons }
def cancel_operation (self):
self.op.cancel ()