@Lenciel

品味时尚

fashion

每年高考的时候,本座都特别期待江苏的作文题。因为传说中江苏的语文老师每年聚在一起都不骂国足是猪,而是骂作文命题老师是猪:对国足,他们还总是能猜中结果,而作文题,他们边都摸不着。

这次就果然又很特立独行的一猪哇:品味时尚

该作文题还有立意的提示信息:

人们追逐时尚,不是因为它适合自己的气质,而只是因为大家都是如此。

不知道这个老师是不是个反非主流斗士,出了这么个题目:说实话,现在的小孩子走出来,没有比非主流更主流的打扮了。

于是同学们为了中举,都会忽悠老师说,时尚应该是自信,又或者是绿色,又或者是环保,又或者是本真,于是就显得自己人生观世界观狂成熟狂完满,即使行走在物欲横流的今天,也能百毒不侵了。

只是无论如何,我们总还是有条件不好的孩子。他也许读书就是为了扔掉锄头,能让自己的家族到城市里,过体面的生活,却只好写,「我虽然无法上网,甚至看不到电视。除开读书,还要帮家里干农活,但是我觉得时尚其实是本真。我现在的生活就挺好的,那些人人都追求的东西,房子,金钱,并不适合我的气质」。

不知道这种话,如果叫命题老师自己去写,他会不会边写边吐。

其实,对本座来说,最近正好有一个有趣的新闻,非常的「时尚」。

大家都知道,《Kill Bill》里面的 Bill,最近挂了:是真的把自己挂起来了。不过,如果你用不同的关键字去搜索,会得出蛮有趣的结果。

心地纯良如偶像派的时尚品味者:click

心地不纯良如本座的时尚品味者:click

嗯哼……其实大家不要觉得从事「手工业」的时候出事有什么奇怪的。本座在以前看Chuck大叔1 那篇著名的Guts的时候(已经有人翻译,慎入!!)有读到过一段:

Looking back, kid-psych experts, school counselors now say that most of the last peak in teen suicide was kids trying to choke while they beat off. Their folks would find them, a towel twisted around the kid’s neck, the towel tied to the rod in their bedroom closet, the kid dead. Dead sperm everywhere. Of course the folks cleaned up. They put some pants on their kid. They made it look… better. Intentional at least. The regular kind of sad, teen suicide.

嗯哼……所以有的时候时尚人士莫名其妙的自缢,是没有那么悲情的。

这又让本座想起来,世界上有两种动物,因为特别重视配偶闻名。一种就是俺们国鸟丹顶鹤2 。诗经说丫们谈起恋爱「鹤鸣九皋,声闻于天」。而且一方去世,另一方一定会孤单终老(要知道丹顶鹤可以活 60 岁左右)。

甚至有一种颇有争论的说法是,只要双方有一个意外死去,另外一个不久就会把自己的脖子打一个结,跟着死去。

每次本座看到人们这样的议论时,总是会有一些心地不纯良的时尚品味在心头默默的泛起3

可惜啊,老师,您看我肚子里面这么有货,却没法跟您一起品味时尚。

  1. 这位大叔不是写黄书的,写的第一篇长篇小说叫做,《Fight Club》。 

  2. 还有一种是鸳鸯么? 

  3. 请问这样是不是比较隐晦一点… 

使用paramiko进行ssh工作

最近在单位写一个自动 build 的小工具。因为 clearcase 的setview命令实际上是激活一个新的shell,所以用简单的「串通」shell的脚本很难做到。

因为在邮件组里面看到有同样问题的 Matt 说用paramiko解决了问题,就试了试,过程还颇有点艰辛。

首先,paramiko没有直接的msi或者exe版本给Windows用户下载,而是需要在本地进行编译。而且pythoneasy_install工具在 Vista 下面会报错,所以至少花了十几分钟才算安装完毕。

结果在用 test.py 验证安装的时候就报错了,说什么:

paramiko.SSHException: No suitable address

安装是我自己一步步弄得,难道搞错了?只好照着 demo 写了一个 sftp 的脚本,发现是可以跑的,干。

只好丢了封信给邮件组,然后自己开始找是啥问题。丢给邮件组的信至今没有回音(人气不行啊,paramiko),问题还是找到了。原来是 1.7.5 的paramiko增加了对 ipv6 的支持,结果引入了错误。更新了client.py后重新编译就可以用了。

最后,虽然 demo 的例子也挺多,但是好像没有说清楚怎么用 invoke_shell 和 get_pty 以及照例奉上一段代码。

"""
This script is using for build the software package
"""

import sys
import time
import paramiko
import traceback
import ConfigParser

"""
The main class of the builder.
"""
class Builder:

    """Parses options from the ini file to create connection."""
    def __init__(self,inifile):
        try:
            config = ConfigParser.ConfigParser()
            config.readfp(open(inifile))

            self._ssh = paramiko.SSHClient()
            self._ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            self._ssh.connect(config.get('host','server'),
                              port=config.getint('host', 'port'),
                              username=config.get('host','user'),
                              password=config.get('host','password'))

            self._t = paramiko.Transport((config.get('host','server'), config.getint('host', 'port')))
            self._t.start_client()
            self._t.auth_password(config.get('host','user'),config.get('host','password'))
            self._sftp = paramiko.SFTPClient.from_transport(self._t)
        except Exception, e:
            print '*** Caught exception: %s: %s' % (e.__class__, e)
            traceback.print_exc()
            try:
                self.closeConn()
            except:
                pass
            sys.exit(1)

        self._fpga = config.get('fpga compress','fpga')
        self._lpath = config.get('fpga compress','local_fpga_path')
        self._rpath = config.get('fpga compress','remote_fpga_path')
        self._oab = config.get('fpga compress','oab')

        self._xlf = config.get('xlf build','xlf')
        self._lmid = config.get('xlf build','lmid')
        self._xpp = config.get('xlf build','xpp')
        self._xdp = config.get('xlf build','xdp')
        self._rru = config.get('xlf build','rru')
        self._rruswdb = config.get('xlf build','rru_sw_db')
        self._xpl = config.get('xlf build','xpl')
        print("Your input fpga file is:"+self._lpath+self._fpga+"\n")
        print("Your ouput xlf file will be:"+self._xlf+"\n")

    """Run command on the server"""
    def runCmd(self, command):
        """run <command>
        Execute this command on all hosts in the list"""
        if command:
            stdin, stdout, stderr = self._ssh.exec_command(command)
            stdin.close()
            for line in stdout.read().splitlines():
                print line
        else:
            print "usage: run <command>"

    """Upload the fpga and compress it to oab.bin"""
    def createOab(self):
        self._sftp.put(self._lpath+self._fpga,self._rpath+self._fpga)

        self.runCmd("hou_create_fpga -bf \"/home/ehholli/fpgainput/fpga.med\" -dn \"CXC 172 8213/1\" -of oab -dev \"XC2V6000,-4\" -dir /home/ehholli/fpgaoutput/")
        try:
            self._sftp.get(self._oab,'oab.bin')
            print("Fpga file compress successfully!")
        except Exception, e:
            print '*** Caught exception: %s: %s' % (e.__class__, e)
            traceback.print_exc()
            try:
                self.closeConn()
            except:
                pass
            sys.exit(1)

    """Make the tlf"""
    def genXlf(self):
        #open a interactive shell
        ct_chan = self._t.open_session()
        ct_chan.setblocking()
        ct_chan.get_pty()
        ct_chan.invoke_shell()
        #ct setview ehholli
        if(ct_chan.send_ready()):
            ct_chan.send("ct setview ehholli\r\n")
        time.sleep(10)

        #compile
        build_cmd="/vobs/rbs/hw/bcp/xp/deliv/solaris2/bin/xlf_gen -r "+self._xpp+" "+self._xdp+" "+self._rru \
                     +" -i "+self._oab+" "+self._rruswdb \
                     +" -o /home/ehholli/tmp/"+self._xlf \
                     +" -x "+self._xpl \
                     +" -lmid \""+self._lmid+"\"" \
                     +" -t \"au_applic\" -v \r\n"
        print(build_cmd)
        if(ct_chan.send_ready()):
            ct_chan.send(build_cmd)
        tCheck2 =
        while not ct_chan.recv_ready():
            time.sleep(5)
            tCheck2+=1
            if tCheck2 >= 6:
                print 'time out'#TODO: add exeption here
        print(ct_chan.recv(65536))
        ct_chan.close()
        time.sleep(10)
        #download the xlf file
        try:
            self._sftp.get("/home/ehholli/tmp/"+self._xlf,self._xlf)
            print("xlf file downloaded successfully!")
        except Exception, e:
            print '*** Caught exception: %s: %s' % (e.__class__, e)
            traceback.print_exc()
            try:
                self.closeConn()
            except:
                pass
            sys.exit(1)

    """Close everything we opened"""
    def closeConn(self):
        self._ssh.close()
        self._sftp.close()
        self._t.close()
if __name__=='__main__':
    # setup logging
    paramiko.util.log_to_file('demo_builder.log')
    b=Builder('cfg.ini')
    b.createOab()
    b.genXlf()
    #b.runCmd('ls')
    b.closeConn()