码迷,mamicode.com
首页 > 编程语言 > 详细

test Python source code plugin with Windows live writter 2012–

时间:2015-09-12 00:42:15      阅读:506      评论:0      收藏:0      [点我收藏+]

标签:

内容介绍ZT:

http://www.cnblogs.com/liuxianan/archive/2013/04/13/3018732.html

博客园官方给出了2个,一个一个介绍。

1、WindowsLiveWriter.CNBlogs.CodeHighlighter.rar

这个插件生成的高亮代码与网页上的一模一样,插入后即可立即显示效果,不过貌似它必须联网才能实时显示效果,因为博客园官方说这是基于“云处理”的。安装方法很简单,将上面的压缩包解压然后复制里面的文件到:

C:\Program Files (x86)\Windows Live\Writer\Plugins,然后重启Writer即可看到:

技术分享

I just did a quick test with this CNBlogs.CodeHighlighter plug-in :

 

技术分享

 

#!/usr/local/bin/python
# -*- coding: utf-8 -*-.
# line of utf-8 is for multi-language
# optional 4-spaces before line rule for Python.

import sys
sys.path.append("/homes/sli/pexpect-2.3/")
import pexpect
import time
import re
import os

statsre = re.compile("(May 1. \d+:\d+:\d+).*? Input  packets:[ ]+(\d+).*? Output packets:[ ]+(\d+).*? Errors: (\d+),", re.DOTALL)

# def function_name():
# The definition ends where the indentation ends.

def logging(fo, str):
    fo.write(str)
    print str

def process(prev, output):
    m = statsre.findall(output)
    val = int(m[0][3])
    #if prev:
    #    if (val-prev>0):
    #        print "%d drops at %s" % (val-prev, m[0][0])
    return val

# input() actually evaluates the input as Python code.
# raw_input() returns the verbatim string entered by the user.
routername = raw_input("enter routername:")   # raw_input is the same as input but omits the evaluation.

for i in range(10):
    print "Loop #%d" % i
    try:
        cct =  pexpect.spawn("ssh labroot@%s" % routername)  # ssh the router and answered yes/no first before this script
#        cct.expect("login: ")
#        cct.sendline("labroot")
        cct.expect("assword:")
        cct.sendline("lab123")
        cct.expect("> ")
        print "on router Iqbal-RE0, 1st try ok!"
        prompt = cct.before.split(\n)[-1]+">"    # correct one for the prompt
        prompt0 = cct.before
        prompt1 = cct.before.split(">")            # test prompt1
        prompt2 = cct.before.split(\n)           # test prompt2
        prompt3 = cct.before.split(\n)[-1]       # test prompt3

        print "prompt is", prompt
        print "prompt0 is", prompt0
        print "prompt1 is", prompt1
        print "prompt2 is", prompt2
        print "prompt3 is", prompt3
    except:
        time.sleep(5)
        cct =  pexpect.spawn("ssh labroot@%s" % routername)
#        cct.expect("login: ")
#        cct.sendline("labroot")
        cct.expect("assword:")
        cct.sendline("lab123")
        cct.expect("> ")
        print "on router Iqbal-RE0, 2nd try ok!"
        prompt = cct.before.split(\n)[-1]+">"
        print "prompt is", prompt

    cct.sendline(set cli screen-width 300)
    cct.expect(prompt)
    cct.sendline(set cli screen-length 0)
    cct.expect(prompt)
    cct.sendline(set cli timestamp)
    cct.expect(prompt)
    f = open(%s_%d.txt % (routername,i), w)

    # open with mode w for write, a for append

    # commands
    cct.sendline(show system uptime | no-more)
    cct.expect(prompt)
    print show system uptime | no-more
#    print cct.before            # test what‘s cct.before is, also the syntax for print
    f.write(cct.before)

    cct.sendline(show bgp summary | no-more)
    cct.expect(prompt)
    print show bgp summary | no-more
#    print(cct.before)          # test what‘s cct.before is, , also the syntax for print
    f.write(cct.before)

    cct.sendline(show chassis routing-engine | no-more)
    cct.expect(prompt)
    print show chassis routing-engine | no-more
#    print cct.before          # test what‘s cct.before is
    f.write(cct.before)

    cct.sendline(show system core-dumps | no-more )
    cct.expect(prompt)
    print show system core-dumps | no-more 
    f.write(cct.before)

    cct.timeout = 30
    cct.sendline(show krt queue | no-more)
    cct.expect(prompt)
    print show krt queue | no-more
    f.write(cct.before)

    cct.sendline(show system storage | no-more)
    cct.expect(prompt)
    print show system storage | no-more
    f.write(cct.before)

    cct.sendline(show system core-dumps | match "sep " | no-more)
    cct.expect(prompt)
    print show system core-dumps | match "sep " | no-more
    f.write(cct.before)

    cct.sendline(show krt table )
    cct.expect(prompt)
    print show krt table 
    f.write(cct.before)

    # check if new core dump on backup RE
    def extract_nbr(str):
        [int(s) for s in str.split() if s.isdigit()]  # extract all numbers from the string "str"

    cct.sendline(show system core-dumps | match ksync | count)
    cct.expect(prompt)
    f.write(cct.before)
    str1 = cct.before                            # print out should be <x> lines
    str2 = cct.before.split(count)[-1]
    str3 = cct.before.split(Count)[-1]         # print out should be : #n lines ( of ksyncd cores )
    str4 = test1 1909 test2 3030 test3 -55 test4 -1001 test5 2002 test6 6000
    print "string1 is : ", str1
    print "string2 is : %s " % str2
    print "string3 is : %s " % str3
    k2 = 1* [int(s) for s in str3.split() if s.isdigit()]   # output should be [n]
    print k2
    k3 = k2[0]                                               # output should be number n now, #n lines of ksyncd there :-)
    print "k3=",k3
    list = [int(s) for s in str4.split() if s.isdigit()]     # output should be a list of numbers [ n1 n2 n3 n4] for positive numbers
    k5 = list[0]                                             # negative numbers can‘t be extracted from this function!
    k6 = list[1]
    k7 = list[2]
    k8 = list[3]
#    k9 = list[4]
#    k10 = list[5]
#    k11 = list[6]
    print (k5,k6,k7,k8)

    cct.sendline(show system core-dumps | match ksync)
    cct.expect(prompt)
    f.write(cct.before)

    res = cct.before
    print res
    if (ksyncd in res) and k3 > 20 :
        print "Found new core dump!!!"
        f.write(New ksyncd core dump on backup\n)
        break
    else:
        f.write(no new ksyncd core dump on backup\n)
        print no new ksyncd core dump on backup


    cct.sendline(re-request chassis routing-engine master switch no-confirm | no-more)
    cct.expect(prompt)
    f.write(cct.before)
    print switchover just happened and will sleep %d seconds % cct.timeout

    # close the file
    f.close()

    cct.sendline(exit)

    time.sleep(cct.timeout)


[sli ~/my-test]$ 


test Python source code plugin with Windows live writter 2012–

标签:

原文地址:http://www.cnblogs.com/sli6000cn/p/4802371.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!