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


Python TimedSubprocess.cancel方法代码示例

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


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

示例1: CheckSELinux

# 需要导入模块: from timedops import TimedSubprocess [as 别名]
# 或者: from timedops.TimedSubprocess import cancel [as 别名]
class CheckSELinux(Question):
    def __init__ (self, troubleshooter):
        Question.__init__ (self, troubleshooter, "Check SELinux contexts")
        troubleshooter.new_page (Gtk.Label (), self)

    def display (self):
        self.answers = {}
        #answers = self.troubleshooter.answers

        RESTORECON = "/sbin/restorecon"
        if not os.access (RESTORECON, os.X_OK):
            return False

        try:
            import selinux
        except ImportError:
            return False
        if not selinux.is_selinux_enabled():
            return False

        paths = ["/etc/cups/", "/usr/lib/cups/", "/usr/share/cups/"]
        null = open ("/dev/null", "r+")
        parent = self.troubleshooter.get_window ()
        contexts = {}
        new_environ = os.environ.copy()
        new_environ['LC_ALL'] = "C"
        restorecon_args = [RESTORECON, "-nvR"].extend(paths)
        try:
            # Run restorecon -nvR
            self.op = TimedSubprocess (parent=parent,
                                       args=restorecon_args,
                                       close_fds=True,
                                       env=new_environ,
                                       stdin=null,
                                       stdout=subprocess.PIPE,
                                       stderr=null)
            (restorecon_stdout, restorecon_stderr, result) = self.op.run ()
        except:
            # Problem executing command.
            return False
        for line in restorecon_stdout:
            l = shlex.split (line)
            if (len (l) < 1):
                continue
            contexts[l[2]] = l[4]
        self.answers['selinux_contexts'] = contexts
        return False

    def collect_answer (self):
        return self.answers

    def cancel_operation (self):
        self.op.cancel ()
开发者ID:daniel-dressler,项目名称:system-config-printer,代码行数:55,代码来源:CheckSELinux.py

示例2: VerifyPackages

# 需要导入模块: from timedops import TimedSubprocess [as 别名]
# 或者: from timedops.TimedSubprocess import cancel [as 别名]
class VerifyPackages(Question):
    def __init__ (self, troubleshooter):
        Question.__init__ (self, troubleshooter, "Verify packages")
        troubleshooter.new_page (Gtk.Label (), self)

    def display (self):
        self.answers = {}
        packages_verification = {}

        package_manager="/bin/rpm"
        if not os.access (package_manager, os.X_OK):
            return False

        packages = ["cups",
                    "foomatic",
                    "gutenprint",
                    "hpijs",
                    "hplip",
                    "system-config-printer"]
        null = open ("/dev/null", "r+")
        parent = self.troubleshooter.get_window ()

        new_environ = os.environ.copy()
        new_environ['LC_ALL'] = "C"

        for package in packages:
            verification_args = [package_manager, "-V", package]
            try:
                self.op = TimedSubprocess (parent=parent,
                                           args=verification_args,
                                           close_fds=True,
                                           env=new_environ,
                                           stdin=null,
                                           stdout=subprocess.PIPE,
                                           stderr=null)
                (verif_stdout, verif_stderr, result) = self.op.run ()
            except:
                # Problem executing command.
                return False
            packages_verification[package] = verif_stdout[:-1]

        self.answers['packages_verification'] = packages_verification
        return False

    def collect_answer (self):
        return self.answers

    def cancel_operation (self):
        self.op.cancel ()
开发者ID:daniel-dressler,项目名称:system-config-printer,代码行数:51,代码来源:VerifyPackages.py

示例3: CheckNetworkServerSanity

# 需要导入模块: from timedops import TimedSubprocess [as 别名]
# 或者: from timedops.TimedSubprocess import cancel [as 别名]

#.........这里部分代码省略.........

            try:
                self.op = TimedOperation (cups.Connection,
                                          kwargs={"host": server_name,
                                                  "port": server_port,
                                                  "encryption": encryption},
                                          parent=parent)
                c = self.op.run ()
                ipp_connect = True
            except RuntimeError:
                ipp_connect = False

            self.answers['remote_server_connect_ipp'] = ipp_connect

            if ipp_connect:
                try:
                    self.op = TimedOperation (c.getPrinters, parent=parent)
                    self.op.run ()
                    cups_server = True
                except:
                    cups_server = False

                self.answers['remote_server_cups'] = cups_server

                if cups_server:
                    cups_printer_dict = answers.get ('cups_printer_dict', {})
                    uri = cups_printer_dict.get ('device-uri', None)
                    if uri:
                        try:
                            self.op = TimedOperation (c.getPrinterAttributes,
                                                      kwargs={"uri": uri},
                                                      parent=parent)
                            attr = self.op.run ()
                            self.answers['remote_cups_queue_attributes'] = attr
                        except:
                            pass

        if try_connect:
            # Try to see if we can connect using smbc.
            context = None
            try:
                context = smbc.Context ()
                name = self.answers['remote_server_try_connect']
                self.op = TimedOperation (context.opendir,
                                          args=("smb://%s/" % name,),
                                          parent=parent)
                dir = self.op.run ()
                self.op = TimedOperation (dir.getdents, parent=parent)
                shares = self.op.run ()
                self.answers['remote_server_smb'] = True
                self.answers['remote_server_smb_shares'] = shares
            except NameError:
                # No smbc support
                pass
            except RuntimeError as e:
                (e, s) = e.args
                self.answers['remote_server_smb_shares'] = (e, s)

            if context != None and answers.has_key ('cups_printer_dict'):
                uri = answers['cups_printer_dict'].get ('device-uri', '')
                u = smburi.SMBURI (uri)
                (group, host, share, user, password) = u.separate ()
                accessible = False
                try:
                    self.op = TimedOperation (context.open,
                                              args=("smb://%s/%s" % (host,
                                                                     share),
                                                    os.O_RDWR,
                                                    0777),
                                              parent=parent)
                    f  = self.op.run ()
                    accessible = True
                except RuntimeError as e:
                    (e, s) = e.args
                    accessible = (e, s)

                self.answers['remote_server_smb_share_anon_access'] = accessible

        # Try traceroute if we haven't already.
        if (try_connect and
            not answers.has_key ('remote_server_traceroute')):
            try:
                self.op = TimedSubprocess (parent=parent, close_fds=True,
                                           args=['traceroute', '-w', '1',
                                                 server_name],
                                           stdin=file("/dev/null"),
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE)
                self.answers['remote_server_traceroute'] = self.op.run ()
            except:
                # Problem executing command.
                pass

        return False

    def collect_answer (self):
        return self.answers

    def cancel_operation (self):
        self.op.cancel ()
开发者ID:incrazyboyy,项目名称:RPiTC-X,代码行数:104,代码来源:CheckNetworkServerSanity.py

示例4: CheckPPDSanity

# 需要导入模块: from timedops import TimedSubprocess [as 别名]
# 或者: from timedops.TimedSubprocess import cancel [as 别名]

#.........这里部分代码省略.........
            self.op = TimedOperation (c.getPPD, args=(name,), parent=parent)
            tmpf = self.op.run ()
        except RuntimeError:
            return False
        except cups.IPPError:
            return False

        self.install_button.hide ()
        title = None
        text = None
        try:
            ppd = cups.PPD (tmpf)
            self.answers['cups_printer_ppd_valid'] = True

            def options (options_list):
                o = {}
                for option in options_list:
                    o[option.keyword] = option.defchoice
                return o

            defaults = {}
            for group in ppd.optionGroups:
                g = options (group.options)
                for subgroup in group.subgroups:
                    g[subgroup.name] = options (subgroup.options)
                defaults[group.name] = g
            self.answers['cups_printer_ppd_defaults'] = defaults
        except RuntimeError:
            title = _("Invalid PPD File")
            self.answers['cups_printer_ppd_valid'] = False
            try:
                self.op = TimedSubprocess (parent=parent,
                                           args=['cupstestppd', '-rvv', tmpf],
                                           close_fds=True,
                                           stdin=subprocess.DEVNULL,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE)
                result = self.op.run ()
                self.answers['cupstestppd_output'] = result
                text = _("The PPD file for printer '%s' does not conform "
                         "to the specification.  "
                         "Possible reason follows:") % name
                text += '\n' + reduce (lambda x, y: x + '\n' + y, result[0])
            except OSError:
                # Perhaps cupstestppd is not in the path.
                text = _("There is a problem with the PPD file for "
                         "printer '%s'.") % name

        if tmpf:
            os.unlink (tmpf)

        if title == None and not answers['cups_printer_remote']:
            (pkgs, exes) = cupshelpers.missingPackagesAndExecutables (ppd)
            self.answers['missing_pkgs_and_exes'] = (pkgs, exes)
            if len (pkgs) > 0 or len (exes) > 0:
                title = _("Missing Printer Driver")
                if len (pkgs) > 0:
                    try:
                        self.packagekit = installpackage.PackageKit ()
                    except:
                        pkgs = []

                if len (pkgs) > 0:
                    self.package = pkgs[0]
                    text = _("Printer '%s' requires the %s package but it "
                             "is not currently installed.") % (name,
                                                               self.package)
                    self.install_button.show ()
                else:
                    text = _("Printer '%s' requires the '%s' program but it "
                             "is not currently installed.") % (name,
                                                               (exes + pkgs)[0])

        if title != None:
            self.label.set_markup ('<span weight="bold" size="larger">' +
                                   title + '</span>\n\n' + text)

        return title != None

    def connect_signals (self, handle):
        self.button_sigid = self.install_button.connect ("clicked",
                                                         self.install_clicked)

    def disconnect_signals (self):
        self.install_button.disconnect (self.button_sigid)

    def collect_answer (self):
        return self.answers

    def cancel_operation (self):
        self.op.cancel ()

    def install_clicked (self, button):
        pkgs = self.answers.get('packages_installed', [])
        pkgs.append (self.package)
        self.answers['packages_installed'] = pkgs
        try:
            self.packagekit.InstallPackageName (0, 0, self.package)
        except:
            pass
开发者ID:Distrotech,项目名称:system-config-printer,代码行数:104,代码来源:CheckPPDSanity.py

示例5: CheckUSBPermissions

# 需要导入模块: from timedops import TimedSubprocess [as 别名]
# 或者: from timedops.TimedSubprocess import cancel [as 别名]

#.........这里部分代码省略.........
                                       stderr=subprocess.PIPE)
            (lsusb_stdout, lsusb_stderr, result) = self.op.run ()
        except:
            # Problem executing command.
            return False

        # Now parse it.
        dev_by_id = {}
        this_dev = None
        for line in lsusb_stdout:
            if (this_dev != None and
                ((line.find ("bInterfaceClass") != -1 and
                  line.find ("7 Printer") != -1) or
                 (line.find ("bInterfaceSubClass") != -1 and
                  line.find ("1 Printer") != -1))):
                mfr = dev_by_id.get (this_mfr_id, {})
                mdl = mfr.get (this_mdl_id, [])
                mdl.append (this_dev)
                mfr[this_mdl_id] = mdl
                dev_by_id[this_mfr_id] = mfr
                this_dev = None
                continue

            separators = [ ('Bus ', 3),
                           (' Device ', 3),
                           (': ID ', 4),
                           (':', 4),
                           (' ', -1)]
            fields = []
            i = 0
            p = line
            while i < len (separators):
                (sep, length) = separators[i]
                if not p.startswith (sep):
                    break
                start = len (sep)
                if length == -1:
                    end = len (p)
                    fields.append (p[start:])
                else:
                    end = start + length
                    fields.append (p[start:end])

                p = p[end:]
                i += 1

            if i < len (separators):
                continue

            if not scheme.startswith ('hp') and fields[2] != '03f0':
                # Skip non-HP printers if we know we're using HPLIP.
                continue

            this_dev = { 'bus': fields[0],
                         'dev': fields[1],
                         'name': fields[4],
                         'full': line }
            this_mfr_id = fields[2]
            this_mdl_id = fields[3]

        infos = {}
        paths = []
        if not scheme.startswith ('hp'):
            paths.extend (glob.glob ("/dev/usb/lp?"))
        for mfr_id, mdls in dev_by_id.iteritems ():
            for mdl_id, devs in mdls.iteritems ():
                for dev in devs:
                    path = "/dev/bus/usb/%s/%s" % (dev['bus'], dev['dev'])
                    paths.append (path)
                    infos[path] = dev['full']

        perms = []
        for path in paths:
            try:
                self.op = TimedSubprocess (parent=parent,
                                           args=[GETFACL, path],
                                           close_fds=True,
                                           env=new_environ,
                                           stdin=file("/dev/null"),
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE)
                (getfacl_stdout, getfacl_stderr, result) = self.op.run ()
                output = filter (lambda x: len (x) > 0, getfacl_stdout)
            except:
                # Problem executing command.
                output = []

            info = infos.get (path, path)
            perms.append ((info, output))

        self.answers['getfacl_output'] = perms

        # Don't actually display anything, just collect information.
        return False

    def collect_answer (self):
        return self.answers

    def cancel_operation (self):
        self.op.cancel ()
开发者ID:incrazyboyy,项目名称:RPiTC-X,代码行数:104,代码来源:CheckUSBPermissions.py


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