当前位置: 首页>>代码示例>>Python>>正文


Python TimedOperation.has_key方法代码示例

本文整理汇总了Python中timedops.TimedOperation.has_key方法的典型用法代码示例。如果您正苦于以下问题:Python TimedOperation.has_key方法的具体用法?Python TimedOperation.has_key怎么用?Python TimedOperation.has_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在timedops.TimedOperation的用法示例。


在下文中一共展示了TimedOperation.has_key方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: display

# 需要导入模块: from timedops import TimedOperation [as 别名]
# 或者: from timedops.TimedOperation import has_key [as 别名]
    def display (self):
        # Collect information useful for the various checks.

        self.answers = {}

        answers = self.troubleshooter.answers
        if not answers['cups_queue_listed']:
            return False

        name = answers['cups_queue']

        parent = self.troubleshooter.get_window ()

        # Find out if this is a printer or a class.
        try:
            cups.setServer ('')
            c = TimedOperation (cups.Connection, parent=parent).run ()
            printers = TimedOperation (c.getPrinters, parent=parent).run ()
            if printers.has_key (name):
                self.answers['is_cups_class'] = False
                queue = printers[name]
                self.answers['cups_printer_dict'] = queue
            else:
                self.answers['is_cups_class'] = True
                classes = TimedOperation (c.getClasses, parent=parent).run ()
                queue = classes[name]
                self.answers['cups_class_dict'] = queue

            attrs = TimedOperation (c.getPrinterAttributes, (name,),
                                    parent=parent).run ()
            self.answers['local_cups_queue_attributes'] = attrs
        except:
            pass

        if self.answers.has_key ('cups_printer_dict'):
            cups_printer_dict = self.answers['cups_printer_dict']
            uri = cups_printer_dict['device-uri']
            (scheme, rest) = urllib.splittype (uri)
            self.answers['cups_device_uri_scheme'] = scheme
            if scheme in ["ipp", "http", "https"]:
                (hostport, rest) = urllib.splithost (rest)
                (host, port) = urllib.splitnport (hostport, defport=631)
                self.answers['remote_server_name'] = host
                self.answers['remote_server_port'] = port
            elif scheme == "smb":
                u = smburi.SMBURI (uri)
                (group, host, share, user, password) = u.separate ()
                new_environ = os.environ.copy()
                new_environ['LC_ALL'] = "C"
                if group:
                    args = ["nmblookup", "-W", group, host]
                else:
                    args = ["nmblookup", host]
                try:
                    p = TimedSubprocess (parent=parent,
                                         timeout=5000,
                                         args=args,
                                         env=new_environ,
                                         close_fds=True,
                                         stdin=file("/dev/null"),
                                         stdout=subprocess.PIPE,
                                         stderr=subprocess.PIPE)
                    result = p.run ()
                    self.answers['nmblookup_output'] = result
                    for line in result[0]:
                        if line.startswith ("querying"):
                            continue
                        spc = line.find (' ')
                        if (spc != -1 and
                            not line[spc:].startswith (" failed ")):
                            # Remember the IP address.
                            self.answers['remote_server_name'] = line[:spc]
                            break
                except OSError:
                    # Problem executing command.
                    pass
            elif scheme == "hp":
                new_environ = os.environ.copy()
                new_environ['LC_ALL'] = "C"
                new_environ['DISPLAY'] = ""
                try:
                    p = TimedSubprocess (parent=parent,
                                         timeout=3000,
                                         args=["hp-info", "-d" + uri],
                                         close_fds=True,
                                         env=new_environ,
                                         stdin=file("/dev/null"),
                                         stdout=subprocess.PIPE,
                                         stderr=subprocess.PIPE)
                    self.answers['hplip_output'] = p.run ()
                except OSError:
                    # Problem executing command.
                    pass

            r = cups_printer_dict['printer-type'] & cups.CUPS_PRINTER_REMOTE
            self.answers['cups_printer_remote'] = (r != 0)
        return False
开发者ID:thnguyn2,项目名称:ECE_527_MP,代码行数:99,代码来源:CheckPrinterSanity.py


注:本文中的timedops.TimedOperation.has_key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。