本文整理汇总了Python中timedops.TimedSubprocess.run方法的典型用法代码示例。如果您正苦于以下问题:Python TimedSubprocess.run方法的具体用法?Python TimedSubprocess.run怎么用?Python TimedSubprocess.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timedops.TimedSubprocess
的用法示例。
在下文中一共展示了TimedSubprocess.run方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CheckSELinux
# 需要导入模块: from timedops import TimedSubprocess [as 别名]
# 或者: from timedops.TimedSubprocess import run [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 ()
示例2: VerifyPackages
# 需要导入模块: from timedops import TimedSubprocess [as 别名]
# 或者: from timedops.TimedSubprocess import run [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 ()
示例3: CheckNetworkServerSanity
# 需要导入模块: from timedops import TimedSubprocess [as 别名]
# 或者: from timedops.TimedSubprocess import run [as 别名]
class CheckNetworkServerSanity(Question):
def __init__ (self, troubleshooter):
Question.__init__ (self, troubleshooter, "Check network server sanity")
troubleshooter.new_page (Gtk.Label (), self)
def display (self):
# Collect useful information.
self.answers = {}
answers = self.troubleshooter.answers
if (not answers.has_key ('remote_server_name') and
not answers.has_key ('remote_server_ip_address')):
return False
parent = self.troubleshooter.get_window ()
server_name = answers['remote_server_name']
server_port = answers.get('remote_server_port', 631)
try_connect = False
if server_name:
# Try resolving the hostname.
try:
ai = socket.getaddrinfo (server_name, server_port)
resolves = map (lambda (family, socktype,
proto, canonname, sockaddr):
sockaddr[0], ai)
try_connect = True
except socket.gaierror:
resolves = False
self.answers['remote_server_name_resolves'] = resolves
ipaddr = answers.get ('remote_server_ip_address', '')
if resolves:
if ipaddr:
try:
resolves.index (ipaddr)
except ValueError:
# The IP address given doesn't match the server name.
# Use the IP address instead of the name.
server_name = ipaddr
try_connect = True
elif ipaddr:
server_name = ipaddr
try_connect = True
else:
server_name = answers['remote_server_ip_address']
# Validate it.
try:
ai = socket.getaddrinfo (server_name, server_port)
resolves = map (lambda (family, socktype,
proto, canonname, sockaddr):
sockaddr[0], ai)
except socket.gaierror:
resolves = False
self.answers['remote_server_name_resolves'] = resolves
try_connect = True
self.answers['remote_server_try_connect'] = server_name
if (try_connect and
answers.get ('cups_device_uri_scheme', 'ipp') in ['ipp',
'http',
'https']):
if answers.get ('cups_device_uri_scheme') == 'https':
encryption = cups.HTTP_ENCRYPT_REQUIRED
else:
encryption = cups.HTTP_ENCRYPT_IF_REQUESTED
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},
#.........这里部分代码省略.........
示例4: CheckPPDSanity
# 需要导入模块: from timedops import TimedSubprocess [as 别名]
# 或者: from timedops.TimedSubprocess import run [as 别名]
class CheckPPDSanity(Question):
def __init__ (self, troubleshooter):
Question.__init__ (self, troubleshooter, "Check PPD sanity")
vbox = Gtk.VBox ()
vbox.set_border_width (12)
vbox.set_spacing (12)
self.label = Gtk.Label ()
self.label.set_line_wrap (True)
self.label.set_use_markup (True)
self.label.set_alignment (0, 0)
vbox.pack_start (self.label, False, False, 0)
box = Gtk.HButtonBox ()
box.set_layout (Gtk.ButtonBoxStyle.START)
self.install_button = Gtk.Button.new_with_label (_("Install"))
box.add (self.install_button)
# Although we want this hidden initially,
# troubleshooter.new_page will call show_all() on the widget
# we give it. We'll need to hide this button in the display()
# callback instead.
vbox.pack_start (box, False, False, 0)
troubleshooter.new_page (vbox, self)
def display (self):
self.answers = {}
answers = self.troubleshooter.answers
if not answers['cups_queue_listed']:
return False
parent = self.troubleshooter.get_window ()
name = answers['cups_queue']
tmpf = None
try:
cups.setServer ('')
self.op = TimedOperation (cups.Connection, parent=parent)
c = self.op.run ()
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 = []
#.........这里部分代码省略.........
示例5: display
# 需要导入模块: from timedops import TimedSubprocess [as 别名]
# 或者: from timedops.TimedSubprocess import run [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
示例6: CheckUSBPermissions
# 需要导入模块: from timedops import TimedSubprocess [as 别名]
# 或者: from timedops.TimedSubprocess import run [as 别名]
class CheckUSBPermissions(Question):
def __init__ (self, troubleshooter):
Question.__init__ (self, troubleshooter, "Check USB permissions")
troubleshooter.new_page (Gtk.Label (), self)
def display (self):
self.answers = {}
answers = self.troubleshooter.answers
if answers['cups_queue_listed']:
if answers['is_cups_class']:
return False
cups_printer_dict = answers['cups_printer_dict']
device_uri = cups_printer_dict['device-uri']
elif answers.get ('cups_device_listed', False):
device_uri = answers['cups_device_uri']
else:
return False
(scheme, rest) = urllib.splittype (device_uri)
if scheme not in ['hp', 'hpfax', 'usb', 'hal']:
return False
LSUSB = "/sbin/lsusb"
if not os.access (LSUSB, os.X_OK):
return False
GETFACL = "/usr/bin/getfacl"
if not os.access (GETFACL, os.X_OK):
return False
new_environ = os.environ.copy()
new_environ['LC_ALL'] = "C"
# Run lsusb
parent = self.troubleshooter.get_window ()
try:
self.op = TimedSubprocess (parent=parent,
args=[LSUSB, "-v"],
close_fds=True,
env=new_environ,
stdin=file("/dev/null"),
stdout=subprocess.PIPE,
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 }
#.........这里部分代码省略.........