本文整理汇总了Python中timedops.TimedOperation类的典型用法代码示例。如果您正苦于以下问题:Python TimedOperation类的具体用法?Python TimedOperation怎么用?Python TimedOperation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TimedOperation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
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
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
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: cancel_clicked
def cancel_clicked (self, widget):
self.persistent_answers['test_page_jobs_cancelled'] = True
jobids = []
for jobid, iter in self.job_to_iter.iteritems ():
jobids.append (jobid)
def cancel_jobs (jobids):
c = self.authconn
for jobid in jobids:
try:
c.cancelJob (jobid)
except cups.IPPError as e:
(e, s) = e.args
if isinstance(s, bytes):
s = s.decode('utf-8', 'replace')
if e != cups.IPP_NOT_POSSIBLE:
self.persistent_answers['test_page_cancel_failure'] = (e, s)
self.op = TimedOperation (cancel_jobs,
(jobids,),
parent=self.troubleshooter.get_window ())
try:
self.op.run ()
except (OperationCanceled, cups.IPPError):
pass
示例5: disconnect_signals
def disconnect_signals (self):
if self.bus:
self.bus.remove_signal_receiver (self.handle_dbus_signal,
path=DBUS_PATH,
dbus_interface=DBUS_IFACE)
self.print_button.disconnect (self.print_sigid)
self.cancel_button.disconnect (self.cancel_sigid)
self.test_cell.disconnect (self.test_sigid)
def cancel_subscription (sub_id):
c = self.authconn
c.cancelSubscription (sub_id)
parent = self.troubleshooter.get_window ()
self.op = TimedOperation (cancel_subscription,
(self.sub_id,),
parent=parent)
try:
self.op.run ()
except (OperationCanceled, cups.IPPError):
pass
try:
del self.sub_seq
except:
pass
GLib.source_remove (self.timer)
示例6: collect_answer
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 () }
示例7: collect_answer
def collect_answer (self):
answers = self.troubleshooter.answers
if not answers['cups_queue_listed']:
return {}
parent = self.troubleshooter.get_window ()
self.answers.update (self.persistent_answers)
if 'error_log_checkpoint' in self.answers:
return self.answers
(tmpfd, tmpfname) = tempfile.mkstemp ()
os.close (tmpfd)
try:
self.op = TimedOperation (self.authconn.getFile,
args=('/admin/log/error_log', tmpfname),
parent=parent)
self.op.run ()
except (RuntimeError, cups.IPPError):
try:
os.remove (tmpfname)
except OSError:
pass
except cups.HTTPError as e:
try:
os.remove (tmpfname)
except OSError:
pass
# 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
try:
statbuf = os.stat (tmpfname)
os.remove (tmpfname)
except OSError:
statbuf = [0, 0, 0, 0, 0, 0, 0]
self.answers['error_log_checkpoint'] = statbuf[6]
self.persistent_answers['error_log_checkpoint'] = statbuf[6]
if journal:
j = journal.Reader ()
j.seek_tail ()
cursor = j.get_previous ()['__CURSOR']
self.answers['error_log_cursor'] = cursor
self.persistent_answers['error_log_cursor'] = cursor
return self.answers
示例8: SchedulerNotRunning
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 ()
示例9: display
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
示例10: collect_answer
def collect_answer (self):
if not self.displayed:
return {}
self.answers = self.persistent_answers.copy ()
parent = self.troubleshooter.get_window ()
success = self.yes.get_active ()
self.answers['test_page_successful'] = success
class collect_jobs:
def __init__ (self, model):
self.jobs = []
model.foreach (self.each, None)
def each (self, model, path, iter, user_data):
self.jobs.append (model.get (iter, 0, 1, 2, 3, 4))
model = self.treeview.get_model ()
jobs = collect_jobs (model).jobs
def collect_attributes (jobs):
job_attrs = None
c = self.authconn
with_attrs = []
for (test, jobid, printer, doc, status) in jobs:
attrs = None
if test:
try:
attrs = c.getJobAttributes (jobid)
except AttributeError:
# getJobAttributes was introduced in pycups 1.9.35.
if job_attrs == None:
job_attrs = c.getJobs (which_jobs='all')
attrs = self.job_attrs[jobid]
with_attrs.append ((test, jobid, printer, doc, status, attrs))
return with_attrs
self.op = TimedOperation (collect_attributes,
(jobs,),
parent=parent)
try:
with_attrs = self.op.run ()
self.answers['test_page_job_status'] = with_attrs
except (OperationCanceled, cups.IPPError):
pass
return self.answers
示例11: collect_answer
def collect_answer (self):
answers = self.troubleshooter.answers
if not answers['cups_queue_listed']:
return {}
parent = self.troubleshooter.get_window ()
self.answers.update (self.persistent_answers)
if 'error_log_checkpoint' in self.answers:
return self.answers
tmpf = NamedTemporaryFile()
try:
self.op = TimedOperation (self.authconn.getFile,
args=["/admin/log/error_log"],
kwargs={'file': tmpf},
parent=parent)
self.op.run ()
except (RuntimeError, cups.IPPError) as e:
self.answers['error_log_checkpoint_exc'] = e
except cups.HTTPError as e:
self.answers['error_log_checkpoint_exc'] = e
# 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
try:
statbuf = os.stat (tmpf.name)
except OSError:
statbuf = [0, 0, 0, 0, 0, 0, 0]
self.answers['error_log_checkpoint'] = statbuf[6]
self.persistent_answers['error_log_checkpoint'] = statbuf[6]
if journal:
j = journal.Reader ()
j.seek_tail ()
cursor = j.get_previous ()['__CURSOR']
self.answers['error_log_cursor'] = cursor
self.persistent_answers['error_log_cursor'] = cursor
now = datetime.datetime.fromtimestamp (time.time ())
timestamp = now.strftime ("%F %T")
self.answers['error_log_timestamp'] = timestamp
self.persistent_answers['error_log_timestamp'] = timestamp
return self.answers
示例12: display
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
示例13: display
def display (self):
self.answers = {}
answers = self.troubleshooter.answers
if not answers['cups_queue_listed']:
return False
self.authconn = answers['_authenticated_connection']
parent = self.troubleshooter.get_window ()
def getServerSettings ():
# Fail if auth required.
cups.setPasswordCB (lambda x: '')
cups.setServer ('')
c = cups.Connection ()
return c.adminGetServerSettings ()
try:
self.op = TimedOperation (getServerSettings, parent=parent)
settings = self.op.run ()
except RuntimeError:
return False
except cups.IPPError:
settings = {}
self.forward_allowed = False
self.label.set_text ('')
if len (settings.keys ()) == 0:
# Requires root
return True
else:
self.persistent_answers['cups_server_settings'] = settings
try:
if int (settings[cups.CUPS_SERVER_DEBUG_LOGGING]) != 0:
# Already enabled
return False
except KeyError:
pass
except ValueError:
pass
return True
示例14: collect_answer
def collect_answer (self):
answers = self.troubleshooter.answers
if not answers['cups_queue_listed']:
return {}
parent = self.troubleshooter.get_window ()
self.answers.update (self.persistent_answers)
if self.answers.has_key ('error_log_checkpoint'):
return self.answers
(tmpfd, tmpfname) = tempfile.mkstemp ()
os.close (tmpfd)
try:
self.op = TimedOperation (self.authconn.getFile,
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
示例15: connect_signals
def connect_signals (self, handler):
self.print_sigid = self.print_button.connect ("clicked",
self.print_clicked)
self.cancel_sigid = self.cancel_button.connect ("clicked",
self.cancel_clicked)
self.test_sigid = self.test_cell.connect ('toggled',
self.test_toggled)
def create_subscription ():
c = self.authconn
sub_id = c.createSubscription ("/",
events=["job-created",
"job-completed",
"job-stopped",
"job-progress",
"job-state-changed"])
return sub_id
parent = self.troubleshooter.get_window ()
self.op = TimedOperation (create_subscription, parent=parent)
try:
self.sub_id = self.op.run ()
except (OperationCanceled, cups.IPPError):
pass
try:
bus = dbus.SystemBus ()
except:
bus = None
self.bus = bus
if bus:
bus.add_signal_receiver (self.handle_dbus_signal,
path=DBUS_PATH,
dbus_interface=DBUS_IFACE)
self.timer = GLib.timeout_add_seconds (1, self.update_jobs_list)