securtcrt session配置转xshell的session配置

参数:

1.securtcrt的session目录

2.一个xshell的模版文件

3.输出目录(必须不存在,自动创建)

#!/usr/bin/python
# -*- coding:utf-8 -*-
#转换secrt的session文件到xshell的session文件
import os
from sys import *

def gen_xshell_session(path, tpl_file, out_session):
    os.mkdir(out_session)
    for f in os.listdir(path):
        print(f)
        fn = path + '/' + f
        if  os.path.isdir(fn):
            od = out_session + '/' + f
            gen_xshell_session(fn, tpl_file, od)
        else:
            if f.startswith('__'):
                continue
            ext = f.find('.ini')
            ip = f[0:ext]
            xshell_cfg_file = out_session + '/' + ip + '.xsh'
            ifn = open(tpl_file, 'r')
            lns = ifn.readlines()
            ifn.close()
            tpl = os.path.basename(tpl_file)
            tpl_n = tpl.find('.xsh')
            tpl_ip = tpl[0:tpl_n]
            ofn = open(xshell_cfg_file, 'w')
            for ln in lns:
                ln = ln.replace(tpl_ip, ip)
                ofn.write(ln)
            ofn.close()






if __name__ == '__main__':
    secrt_session = argv[1]
    xshell_xsh_tpl_file = argv[2]
    xshell_out_session_dir = argv[3]

    gen_xshell_session(secrt_session, xshell_xsh_tpl_file, xshell_out_session_dir)

 

 

posted @ 2013-11-02 15:37  绿色冰点  Views(3389)  Comments(1Edit  收藏  举报