ksace.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:stacki-ace 作者: Teradata 项目源码 文件源码
def doScript(section, script, scriptnum):
    fname = '/run/ks-script-%s-%d' % (section, scriptnum)

    f = open(fname, 'w')
    f.write('#!%s\n\n' % script.interp)

    s = '%s' % script
    for line in s.split('\n'):
        if line.startswith('%pre') or line.startswith('%post') \
                or line.startswith('%end'):
            #
            # skip
            #
            continue

        f.write('%s\n' % line)

    f.close()
    os.chmod(fname, 0700)

    pid = os.fork()

    if pid == 0:
        if section == 'post' and script.inChroot:
            shutil.copy(fname, '/run/mnt/sysimage%s' % fname)
            os.chroot('/run/mnt/sysimage')

        #
        # set stdout and stderr to files on the disk so we can examine
        # the output and errors
        #
        fout = open('%s.out' % fname, 'w')
        ferr = open('%s.err' % fname, 'w')

        subprocess.call([ fname ], stdout = fout, stderr = ferr)

        fout.close()
        ferr.close()
        sys.exit(0)
    else:
        os.wait()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号