本文整理汇总了Python中solaris_install.Popen.communicate方法的典型用法代码示例。如果您正苦于以下问题:Python Popen.communicate方法的具体用法?Python Popen.communicate怎么用?Python Popen.communicate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类solaris_install.Popen
的用法示例。
在下文中一共展示了Popen.communicate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from solaris_install import Popen [as 别名]
# 或者: from solaris_install.Popen import communicate [as 别名]
def create(self, dry_run):
""" create - method to create, newfs and mount a lofi device
"""
# create the ramdisk (if needed)
self.create_ramdisk(dry_run)
# create the lofi device
cmd = [LOFIADM, "-a", self.ramdisk]
if not dry_run:
p = Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
logger=ILN)
self.lofi_device = p.stdout.strip()
# newfs it
cmd = [NEWFS, "-m", "0", "-o", "space"]
if self.nbpi is not None:
cmd.append("-i")
cmd.append(str(self.nbpi))
cmd.append(self.lofi_device.replace("lofi", "rlofi"))
if not dry_run:
# due to the way Popen works, we can not assign a logger to the
# call, otherwise the process will complete before we can pass the
# "y" to newfs
logger = logging.getLogger(ILN)
logger.debug("Executing: %s" % " ".join(cmd))
p = Popen(cmd, stdin=Popen.PIPE, stdout=Popen.DEVNULL,
stderr=Popen.DEVNULL)
p.communicate("y\n")
# ensure a directory exists to mount the lofi device to
if not os.path.exists(self.mountpoint) and not dry_run:
os.makedirs(self.mountpoint)
cmd = [MOUNT, "-F", "ufs", "-o", "rw", self.lofi_device,
self.mountpoint]
if not dry_run:
Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
logger=ILN)
self.mounted = True
示例2: test_devnull
# 需要导入模块: from solaris_install import Popen [as 别名]
# 或者: from solaris_install.Popen import communicate [as 别名]
def test_devnull(self):
'''Test using Popen.DEVNULL for stdin'''
popen = Popen(["/usr/bin/cat"], stdin=Popen.DEVNULL, stdout=Popen.PIPE)
# Use PIPE for stdout as, for a failure case, the subprocess call
# could hang indefinitely, so we can't block on it
for wait_count in xrange(10):
# If it's not done nearly instantly, something is wrong.
# However, give the benefit of the doubt by waiting up to
# 5 seconds for completion
if popen.poll() is not None:
break
else:
time.sleep(0.5)
else:
popen.kill()
self.fail("stdin=Popen.DEVNULL did not work")
stdout = popen.communicate()[0]
self.assertEqual("", stdout)
示例3: execute
# 需要导入模块: from solaris_install import Popen [as 别名]
# 或者: from solaris_install.Popen import communicate [as 别名]
def execute(self, dry_run=False):
'''Validate script and then run it.'''
script_name = os.path.abspath(self.dmd.script)
# Verify type of script. Assumes this module is being run with enough
# privilege to read the script.
linecache.checkcache(script_name)
first_line = linecache.getline(script_name, 1)
if (first_line == ""):
errmsg = (MSG_HEADER + "Error opening scriptfile %s" % script_name)
self.logger.critical(errmsg)
raise DMMScriptAccessError(errmsg)
# Look for appropriate shebang line to denote a supported script.
# Note their appearance may have "/usr" prepended to them.
first_line = first_line.strip()
if not first_line.startswith("#!"):
errmsg = (MSG_HEADER +
'File %s: first line does not start with "#!".' %
script_name)
self.logger.critical(errmsg)
raise DMMScriptInvalidError(errmsg)
# Verify accessibility of script.
# Owner must be aiuser, or file mode must include o+rx.
script_stat = os.stat(script_name)
mode = stat.S_IMODE(script_stat.st_mode)
self.logger.info(MSG_HEADER + "Script to run: " + script_name)
self.logger.info(MSG_HEADER +
"script mode is 0%o, uid is %d, gid is %d\n" %
(mode, script_stat.st_uid, script_stat.st_gid))
self.logger.info(MSG_HEADER +
"Script validated. Running in subprocess...")
# Verify that the aiuser can access the script.
cmdlist = [SU, AIUSER_ACCOUNT_NAME, "-c",
TEST + " -r " + script_name + " -a -x " + script_name]
try:
Popen.check_call(cmdlist)
except CalledProcessError:
errmsg = MSG_HEADER + \
"Error accessing Derived Manifest script as aiuser"
self.logger.critical(errmsg)
raise DMMScriptInvalidError(errmsg)
cmdlist = [SU, AIUSER_ACCOUNT_NAME, "-c", script_name]
subproc = Popen(cmdlist, stderr=Popen.STDOUT, stdout=Popen.PIPE,
preexec_fn=self.subproc_env_setup)
self.logger.info(MSG_HEADER + "script output follows: ")
outerr, dummy = subproc.communicate()
while (subproc.returncode is None):
outerr = outerr.split("\n")
for line in outerr:
self.logger.info("> " + line)
outerr, dummy = subproc.communicate()
outerr = outerr.split("\n")
for line in outerr:
self.logger.info("> " + line)
self.logger.info(MSG_HEADER + "aimanifest logfile output follows: ")
try:
with open(self.aim_logfile, 'r') as aim_log:
for line in aim_log:
self.logger.info(">> " + line.strip())
except (OSError, IOError) as err:
self.logger.error("Error reading aimanifest logfile: %s:%s" %
(err.filename, err.strerror))
try:
os.unlink(self.aim_logfile)
except OSError as err:
self.logger.warning("MSG_HEADER: Warning: Could not delete "
"aimanifest logfile %s: %s" %
(self.aim_logfile, err.strerror))
if subproc.returncode < 0:
# Would be nice to convert number to signal string, but no
# facility for this exists in python.
errmsg = (MSG_HEADER +
"Script was terminated by signal %d" %
-subproc.returncode)
elif subproc.returncode > 0:
# Note: can't get 128 or 129 (as can be returned by a shell when it
# cannot access or run a script) because that has already been
# checked for.
errmsg = (MSG_HEADER + "Script \"" + self.dmd.script + \
"\" terminated on error.")
if subproc.returncode != 0:
self.logger.critical(errmsg)
raise DMMExecutionError(errmsg)
else:
self.logger.info(MSG_HEADER + "script completed successfully")
# Try to validate against a schema specified in the manifest DOCTYPE
#.........这里部分代码省略.........