﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-yunshichen</title><link>http://www.cnitblog.com/yunshichen/</link><description>我相信人生是值得活的,尽管人在一生中必须遭受痛苦,卑劣,残酷,不幸和死亡的折磨,我依然深信如此.但我认为人生不一定要有意义,只是对一些人而言,他们可以使人生有意义.  ---J 赫胥黎</description><language>zh-cn</language><lastBuildDate>Wed, 29 Apr 2026 06:00:51 GMT</lastBuildDate><pubDate>Wed, 29 Apr 2026 06:00:51 GMT</pubDate><ttl>60</ttl><item><title>Python 应用X: 工具集合</title><link>http://www.cnitblog.com/yunshichen/archive/2011/04/28/73428.html</link><dc:creator>Chenyunshi</dc:creator><author>Chenyunshi</author><pubDate>Wed, 27 Apr 2011 18:08:00 GMT</pubDate><guid>http://www.cnitblog.com/yunshichen/archive/2011/04/28/73428.html</guid><wfw:comment>http://www.cnitblog.com/yunshichen/comments/73428.html</wfw:comment><comments>http://www.cnitblog.com/yunshichen/archive/2011/04/28/73428.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cnitblog.com/yunshichen/comments/commentRss/73428.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yunshichen/services/trackbacks/73428.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 简介						记录自己做的一些稀奇古怪的程序. 工具一: 查找单词解释原理: http://dict.cn/ 提供了查词的引擎, 输入单词即可以得到解释. 所以这个程序只是做一些体力活. 代码如下: (有朋友反映复制之后出错. 若如此请移步到这里下载这个脚本: http://www.uudisc.com/user/diegoyun/file/4131948Code highlig...&nbsp;&nbsp;<a href='http://www.cnitblog.com/yunshichen/archive/2011/04/28/73428.html'>阅读全文</a><img src ="http://www.cnitblog.com/yunshichen/aggbug/73428.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yunshichen/" target="_blank">Chenyunshi</a> 2011-04-28 02:08 <a href="http://www.cnitblog.com/yunshichen/archive/2011/04/28/73428.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Subprocess 操作, 如 Linux 下的shell 和 Windows 下的批处理</title><link>http://www.cnitblog.com/yunshichen/archive/2011/04/28/73427.html</link><dc:creator>Chenyunshi</dc:creator><author>Chenyunshi</author><pubDate>Wed, 27 Apr 2011 16:24:00 GMT</pubDate><guid>http://www.cnitblog.com/yunshichen/archive/2011/04/28/73427.html</guid><wfw:comment>http://www.cnitblog.com/yunshichen/comments/73427.html</wfw:comment><comments>http://www.cnitblog.com/yunshichen/archive/2011/04/28/73427.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/yunshichen/comments/commentRss/73427.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yunshichen/services/trackbacks/73427.html</trackback:ping><description><![CDATA[
		<br />
		<h2>
				<font color="#006600" size="5">
						<b>基本命令</b>
				</font>
				<br />
		</h2>东拼西凑查了好久, 才总算把这个命令补完全. 不废话, 直接上代码. <br /><br /><div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> exec_command(cmdlist,working_dir,view_result</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">False):<br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> isinstance(cmdlist, str):<br />        cmdlist </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> [cmdlist]<br />        <br />    cmd_seperator </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">;</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> platform<br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> platform.system() </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">Windows</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">:<br />        cmd_seperator </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">&amp;&amp;</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />    <br />    runCmd</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(128, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">    <br />    </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> cmd </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> cmdlist:<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> runCmd</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(128, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">:<br />            runCmd </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> runCmd </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> cmd<br />        </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);">:<br />            runCmd </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> runCmd </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> cmd_seperator </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> cmd<br />    <br />    p</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">subprocess.Popen(runCmd,shell</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">True,stdout</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">subprocess.PIPE,stdin</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">subprocess.PIPE,stderr</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">subprocess.PIPE,cwd</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">working_dir)<br />    out,err </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> p.communicate()<br />    result </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> {</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">out</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">:out,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">err</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">:err,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">returncode</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">:str(p.returncode),</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">pid</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">:str(p.pid)}<br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> view_result:<br />        </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">===== Printed result: </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">--&gt; Run cmd: </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> runCmd<br />        </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">--&gt; returncode: </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> result[</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">returncode</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">]<br />        </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">--&gt; out: </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> result[</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">out</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">]<br />        </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">--&gt; err: </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> result[</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">err</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">]<br />        <br />    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> result<br /><br />exec_command(["ls -l","uname -a"],".",True)<br /></span></div><br /><hr size="2" width="100%" /><h2><font color="#006600">扩展功能1: CVS 操作</font><br /></h2>这个功能无甚神秘. 首先要安装有cvs, 其次要设置cvsroot. 最后, 你要时不时查查cvs的命令. <br /><br />我承认拼凑这个程序还是费了不少时间, 所以有记下来的必要. <br /><br /><div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">!/usr/bin/python</span><span style="color: rgb(0, 128, 0);"><br />#</span><span style="color: rgb(0, 128, 0);"> -*- coding: utf-8 -*- </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(128, 0, 0);">'''</span><span style="color: rgb(128, 0, 0);"><br />Created on Apr 28, 2011<br /><br />@author: yunshichen@gmail.com<br /></span><span style="color: rgb(128, 0, 0);">'''</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> string<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> subprocess<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> platform<br /><br /></span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> exec_command(cmdlist,working_dir,view_result</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">False):<br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> isinstance(cmdlist, str):<br />        cmdlist </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> [cmdlist]<br />        <br />    cmd_seperator </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">;</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> platform.system() </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">Windows</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">:<br />        cmd_seperator </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">&amp;&amp;</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />    <br />    runCmd</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(128, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">    <br />    </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> cmd </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> cmdlist:<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> runCmd</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(128, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">:<br />            runCmd </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> runCmd </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> cmd<br />        </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);">:<br />            runCmd </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> runCmd </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> cmd_seperator </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> cmd<br />    <br />    p</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">subprocess.Popen(runCmd,shell</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">True,stdout</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">subprocess.PIPE,stdin</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">subprocess.PIPE,stderr</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">subprocess.PIPE,cwd</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">working_dir)<br />    out,err </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> p.communicate()<br />    result </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> {</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">out</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">:out,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">err</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">:err,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">returncode</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">:str(p.returncode),</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">pid</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">:str(p.pid)}<br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> view_result:<br />        </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">===== Printed result: </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">--&gt; Run cmd: </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> runCmd<br />        </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">--&gt; returncode: </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> result[</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">returncode</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">]<br />        </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">--&gt; out: </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> result[</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">out</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">]<br />        </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">--&gt; err: </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> result[</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">err</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">]<br />        <br />    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> result<br /><br /></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> DPY_CVS():<br />    </span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 128);">__init__</span><span style="color: rgb(0, 0, 0);">(self,cvs_cmd,cvs_root,is_debug</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">True):<br />        self.cvs_cmd </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> cvs_cmd<br />        self.cvs_root </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> cvs_root<br />    <br />    </span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> checkout(self,working_dir,proj,opts</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">None):<br />        </span><span style="color: rgb(128, 0, 0);">'''</span><span style="color: rgb(128, 0, 0);"><br />        opts holds optional for checkout command. For example:<br />        <br />        {'r': diego_test_tag,'d':my_local_path}<br />        </span><span style="color: rgb(128, 0, 0);">'''</span><span style="color: rgb(0, 0, 0);"><br />        cmd_set_cvs_root </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">set CVSROOT=</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> self.cvs_root<br />        cmd_checkout </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> self.cvs_cmd </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);"> -q checkout ${optional_str} -P </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">proj<br />        <br />        str</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(128, 0, 0);">""</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(opts </span><span style="color: rgb(0, 0, 0);">&lt;&gt;</span><span style="color: rgb(0, 0, 0);"> None):<br />            </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> key </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> opts:<br />                str </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> str </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);"> -</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">key </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> opts[key]<br />        <br />        cmd_checkout </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> string.Template(cmd_checkout).substitute({</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">optional_str</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">:str})<br />        <br />        self.result </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> exec_command([cmd_set_cvs_root,cmd_checkout],working_dir)<br />        <br />    </span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> tagFiles(self,working_dir,tagName,pathlist):<br />        <br />        cmd_set_cvs_root </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">set CVSROOT=</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> self.cvs_root<br />        cmd_tag_a_file </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> self.cvs_cmd </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);"> tag </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">tagName</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);"> ${cvs_file}</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />        <br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> isinstance(pathlist, str):<br />            pathlist </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> [pathlist]<br />            <br />        cmdlist </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> [cmd_set_cvs_root]<br />        </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> fpath </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> pathlist:<br />            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> fpath.startswith(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">/</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">):<br />                fpath </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> fpath[</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">:]<br />            cmd_tag </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> string.Template(cmd_tag_a_file).substitute({</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">cvs_file</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">:fpath})<br />            cmdlist.append(cmd_tag)<br />        <br />        self.result </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> exec_command(cmdlist,working_dir)<br />        <br />    </span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> viewResult(self):<br />        r </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> self.result<br />        </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">\n\n\n------------------ CVS run result: -----------</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">---&gt;returncode: </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> r[</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">returncode</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">]<br />        </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">out:\n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> r[</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">out</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">]<br />        </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">err:\n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> r[</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">err</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">]<br />        </span></div><br /><br /><br /><br /><br /><img src ="http://www.cnitblog.com/yunshichen/aggbug/73427.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yunshichen/" target="_blank">Chenyunshi</a> 2011-04-28 00:24 <a href="http://www.cnitblog.com/yunshichen/archive/2011/04/28/73427.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Python 数据库操作</title><link>http://www.cnitblog.com/yunshichen/archive/2011/02/14/72790.html</link><dc:creator>Chenyunshi</dc:creator><author>Chenyunshi</author><pubDate>Sun, 13 Feb 2011 16:02:00 GMT</pubDate><guid>http://www.cnitblog.com/yunshichen/archive/2011/02/14/72790.html</guid><wfw:comment>http://www.cnitblog.com/yunshichen/comments/72790.html</wfw:comment><comments>http://www.cnitblog.com/yunshichen/archive/2011/02/14/72790.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yunshichen/comments/commentRss/72790.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yunshichen/services/trackbacks/72790.html</trackback:ping><description><![CDATA[
		<br />打算把python连接db的例子都总结下来. <br /><br /><font color="#006600"><b><font size="5">python连接sqllite</font></b></font><br /><br /><div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">!/usr/bin/python</span><span style="color: rgb(0, 128, 0);"><br />#</span><span style="color: rgb(0, 128, 0);"> -*- coding: utf-8 -*- </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(128, 0, 0);">'''</span><span style="color: rgb(128, 0, 0);"><br />Created on 2/13/2011<br /><br />@author: yunshichen@gmail.com<br /></span><span style="color: rgb(128, 0, 0);">'''</span><span style="color: rgb(0, 0, 0);"><br /><br /></span><span style="color: rgb(128, 0, 0);">'''</span><span style="color: rgb(128, 0, 0);"><br /><br />tutorial link: http://docs.python.org/py3k/library/sqlite3.html<br /><br />SQLite is a C library that provides a lightweight disk-based database that doesn’t require a separate server process and allows accessing the database using a nonstandard variant of the SQL query language. Some applications can use SQLite for internal data storage. It’s also possible to prototype an application using SQLite and then port the code to a larger database such as PostgreSQL or Oracle.<br /><br />sqlite3 was written by Gerhard Häring and provides a SQL interface compliant with the DB-API 2.0 specification described by PEP 249.<br /><br />To use the module, you must first create a Connection object that represents the database. Here the data will be stored in the /tmp/example file:<br /><br /></span><span style="color: rgb(128, 0, 0);">'''</span><span style="color: rgb(0, 0, 0);"><br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> sqlite3<br /><br />DB_FILE </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">/tmp/example</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br /><br /></span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> listData():<br />    conn </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sqlite3.connect(DB_FILE)<br />    c </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> conn.cursor()<br />    <br />    </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">Lists data<img src="http://www.cnitblog.com/images/dot.gif" />.\n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />    sql </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">select * from stocks order by price</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />    c.execute(sql)<br />    </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> row </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> c:<br />        </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);">(row)<br />        <br />    conn.commit()<br />    c.close()<br />    <br /><br /></span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> clearTableData():<br />    conn </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sqlite3.connect(DB_FILE)<br />    c </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> conn.cursor()<br />    <br />    sql </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">delete from stocks</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />    c.execute(sql)<br />    <br />    </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">All data are deleted<img src="http://www.cnitblog.com/images/dot.gif" />.\n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />    conn.commit()<br />    c.close()<br /><br /></span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> insertData():<br />    conn </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sqlite3.connect(DB_FILE)<br />    c </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> conn.cursor()<br />    <br />    insertData </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">insert into stocks values ('2006-01-05','BUY','RHAT',100,35.14)</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />    c.execute(insertData)<br />    <br />    </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);"> Never do this -- insecure!</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">    symbol = 'IBM'</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">    c.execute("<img src="http://www.cnitblog.com/images/dot.gif" /> where symbol = '%s'" % symbol)</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);"> Do this instead</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">    t = (symbol,)</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">    c.execute('select * from stocks where symbol=?', t)</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);"><br />    insertSql </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">insert into stocks values (?,?,?,?,?)</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> t </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> [(</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">2006-03-28</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">BUY</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">IBM</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">1000</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">45.00</span><span style="color: rgb(0, 0, 0);">),<br />              (</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">2006-04-05</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">BUY</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">MSOFT</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">1000</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">72.00</span><span style="color: rgb(0, 0, 0);">),<br />              (</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">2006-04-06</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">SELL</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">IBM</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">500</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">53.00</span><span style="color: rgb(0, 0, 0);">),<br />             ]:<br />        c.execute(insertSql, t)<br /><br />    </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">Set data into table stocks<img src="http://www.cnitblog.com/images/dot.gif" />.\n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />    conn.commit()<br />    c.close()    <br /><br /></span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> initTable():<br />    conn </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sqlite3.connect(DB_FILE)<br />    c </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> conn.cursor()<br />    <br />    createTable </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">create table stocks (date text, trans text, symbol text, qty real, price real)</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />    c.execute(createTable)<br />    </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">Created table stocks<img src="http://www.cnitblog.com/images/dot.gif" />.\n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />    <br />    conn.commit()<br />    c.close()<br />    <br /><br /></span><span style="color: rgb(128, 0, 0);">'''</span><span style="color: rgb(128, 0, 0);"><br />    运行例子:   ./sqllitetest.py -c init<br /></span><span style="color: rgb(128, 0, 0);">'''</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 128);">__name__</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">__main__</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">:<br />    <br />    </span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> optparse </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> OptionParser<br />    parser </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> OptionParser()<br />    <br />    parser.add_option(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">-c</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">--command</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, action</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">store</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />                  dest</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">cmd</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />                  default</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">init</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />                  type</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">string</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />                  help</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">Runs functions based on commands. Available commands are init,list,data,deleteAll </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">) <br />    <br />    options, args </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> parser.parse_args()<br />    <br />    cmd </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> options.cmd<br />    <br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(cmd</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">init</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">):<br />        initTable()<br />        <br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(cmd</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">deleteAll</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">):<br />        clearTableData()<br />        <br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(cmd</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">data</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">):<br />        insertData()<br />        <br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(cmd</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">list</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">):<br />        listData()<br />        <br />    <br />    <br />    <br />    <br />    <br />    </span></div><br /><img src ="http://www.cnitblog.com/yunshichen/aggbug/72790.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yunshichen/" target="_blank">Chenyunshi</a> 2011-02-14 00:02 <a href="http://www.cnitblog.com/yunshichen/archive/2011/02/14/72790.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>python 小程序, 查找todo选项, 促进自己更好的管理时间</title><link>http://www.cnitblog.com/yunshichen/archive/2011/02/06/72760.html</link><dc:creator>Chenyunshi</dc:creator><author>Chenyunshi</author><pubDate>Sun, 06 Feb 2011 13:42:00 GMT</pubDate><guid>http://www.cnitblog.com/yunshichen/archive/2011/02/06/72760.html</guid><wfw:comment>http://www.cnitblog.com/yunshichen/comments/72760.html</wfw:comment><comments>http://www.cnitblog.com/yunshichen/archive/2011/02/06/72760.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cnitblog.com/yunshichen/comments/commentRss/72760.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yunshichen/services/trackbacks/72760.html</trackback:ping><description><![CDATA[
		<b>想法&amp;需求</b>
		<br />
		<br />1&gt;在看代码的时候, 总会想: 这个api很好, 这段代码用法很好. 总结下来. 但当看完书的时候就忘了.<br />2&gt;有时候会无聊, 无所事事. 浪费了一段时间后才想起, 其实可以做XX, YY. <br /><br />解决办法<br /><br />1&gt;在看代码的时候用注释方式做标记, 记录下来. <br />2&gt;用小程序遍历这些代码, 找出这些标记. <br />3&gt;将这些项记录到excel里. 无聊的时候就打开这个excel看看有什么东西做. <br /><br />todo的例子(用一些ide可以方便生成大部分注释)<br /><br />------------------------------<div id=":5q"><wbr>-------------------------- todo sample begin<br />
#todo_begin:<br />
#item: 配置一个方便的调试 spring3 + hibernate 3 的教程<br />
#estimate: 4-8h<br />
#file: /media/dev/utopism2008/<wbr>projects/python/dpytools/src/<wbr>findtodo/FindToDo.py<br />
#todo_end:<br /><br />
#todo_begin:<br />
#item: 总结xlrt 和 xlwt 用法. 特别是 nrows 和 写已有的excel<br />
#estimate: 4h<br />
#file: /media/dev/utopism2008/<wbr>projects/python/dpytools/src/<wbr>findtodo/FindToDo.py<br />
#todo_end:<br />
------------------------------<wbr>-------------------------- todo sample end<br /><br />程序源码:<br /><br /><div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);">  1</span> <span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">! /usr/bin/python</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">  2</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(128, 0, 0);">'''</span><span style="color: rgb(128, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">  3</span> <span style="color: rgb(128, 0, 0);">Created on Feb 6, 2011<br /></span><span style="color: rgb(0, 128, 128);">  4</span> <span style="color: rgb(128, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">  5</span> <span style="color: rgb(128, 0, 0);">1&gt;Find todo string in every file read. <br /></span><span style="color: rgb(0, 128, 128);">  6</span> <span style="color: rgb(128, 0, 0);">2&gt;Set this content into excel file. Every weekend I can check this file and make next plan based on these items. <br /></span><span style="color: rgb(0, 128, 128);">  7</span> <span style="color: rgb(128, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">  8</span> <span style="color: rgb(128, 0, 0);">@author: yunshichen@gamil.com<br /></span><span style="color: rgb(0, 128, 128);">  9</span> <span style="color: rgb(128, 0, 0);"></span><span style="color: rgb(128, 0, 0);">'''</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 10</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);"> -*- coding: utf8 -*- </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 11</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 12</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> os<br /></span><span style="color: rgb(0, 128, 128);"> 13</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> ConfigParser<br /></span><span style="color: rgb(0, 128, 128);"> 14</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 15</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> xlrd <br /></span><span style="color: rgb(0, 128, 128);"> 16</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> xlutils.copy<br /></span><span style="color: rgb(0, 128, 128);"> 17</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> xlwt<br /></span><span style="color: rgb(0, 128, 128);"> 18</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 19</span> <span style="color: rgb(0, 0, 0);">ITEM_KEY </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">#item:</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 20</span> <span style="color: rgb(0, 0, 0);">EST_KEY </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">#estimate:</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 21</span> <span style="color: rgb(0, 0, 0);">FILE_PATH_KEY </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">#file:</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 22</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 23</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(128, 0, 0);">'''</span><span style="color: rgb(128, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 24</span> <span style="color: rgb(128, 0, 0);">A typical sample of todo item in file:<br /></span><span style="color: rgb(0, 128, 128);"> 25</span> <span style="color: rgb(128, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 26</span> <span style="color: rgb(128, 0, 0);">#todo_begin:<br /></span><span style="color: rgb(0, 128, 128);"> 27</span> <span style="color: rgb(128, 0, 0);">#item: To summarize usage of Qt4 widget<br /></span><span style="color: rgb(0, 128, 128);"> 28</span> <span style="color: rgb(128, 0, 0);">#estimate: 5m<br /></span><span style="color: rgb(0, 128, 128);"> 29</span> <span style="color: rgb(128, 0, 0);">#file: /media/dev/utopism2008/projects/python/dpytools/src/findtodo/FindToDo.py<br /></span><span style="color: rgb(0, 128, 128);"> 30</span> <span style="color: rgb(128, 0, 0);">#todo_end:<br /></span><span style="color: rgb(0, 128, 128);"> 31</span> <span style="color: rgb(128, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 32</span> <span style="color: rgb(128, 0, 0);"></span><span style="color: rgb(128, 0, 0);">'''</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 33</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> findTodo(fpath,alist):<br /></span><span style="color: rgb(0, 128, 128);"> 34</span> <span style="color: rgb(0, 0, 0);">    todo_begin </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">todo_begin</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 35</span> <span style="color: rgb(0, 0, 0);">    todo_end </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">todo_end</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 36</span> <span style="color: rgb(0, 0, 0);">    isFinding </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> False<br /></span><span style="color: rgb(0, 128, 128);"> 37</span> <span style="color: rgb(0, 0, 0);">    fread </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> open(fpath,</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">r</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br /></span><span style="color: rgb(0, 128, 128);"> 38</span> <span style="color: rgb(0, 0, 0);">    aitem </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> None<br /></span><span style="color: rgb(0, 128, 128);"> 39</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> line </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> fread:<br /></span><span style="color: rgb(0, 128, 128);"> 40</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);"> 41</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> todo_begin </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> line:<br /></span><span style="color: rgb(0, 128, 128);"> 42</span> <span style="color: rgb(0, 0, 0);">            isFinding </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> True<br /></span><span style="color: rgb(0, 128, 128);"> 43</span> <span style="color: rgb(0, 0, 0);">            aitem </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> {}<br /></span><span style="color: rgb(0, 128, 128);"> 44</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">continue</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 45</span> <span style="color: rgb(0, 0, 0);">                <br /></span><span style="color: rgb(0, 128, 128);"> 46</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> todo_end </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> line:<br /></span><span style="color: rgb(0, 128, 128);"> 47</span> <span style="color: rgb(0, 0, 0);">            isFinding </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> False<br /></span><span style="color: rgb(0, 128, 128);"> 48</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">continue</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 49</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);"> 50</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">( isFinding </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> False):<br /></span><span style="color: rgb(0, 128, 128);"> 51</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">continue</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 52</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);"> 53</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> mapKeyValue(aitem,ITEM_KEY,line):<br /></span><span style="color: rgb(0, 128, 128);"> 54</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">continue</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 55</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);"> 56</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> mapKeyValue(aitem,EST_KEY,line):<br /></span><span style="color: rgb(0, 128, 128);"> 57</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">continue</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 58</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);"> 59</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> mapKeyValue(aitem,FILE_PATH_KEY,line):<br /></span><span style="color: rgb(0, 128, 128);"> 60</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> FILE_PATH_KEY </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> line:<br /></span><span style="color: rgb(0, 128, 128);"> 61</span> <span style="color: rgb(0, 0, 0);">                alist.append(aitem)<br /></span><span style="color: rgb(0, 128, 128);"> 62</span> <span style="color: rgb(0, 0, 0);">                aitem </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> None<br /></span><span style="color: rgb(0, 128, 128);"> 63</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">--Find todo item in </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> fpath </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">\n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 64</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">continue</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 65</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);"> 66</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);"> 67</span> <span style="color: rgb(0, 0, 0);">    fread.close()<br /></span><span style="color: rgb(0, 128, 128);"> 68</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);"> 69</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);"> 70</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> mapKeyValue(item,key,line):<br /></span><span style="color: rgb(0, 128, 128);"> 71</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> key </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> line:        <br /></span><span style="color: rgb(0, 128, 128);"> 72</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">test</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 73</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">key is:</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> key </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">\n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 74</span> <span style="color: rgb(0, 0, 0);">        item[key] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> line[len(key):]<br /></span><span style="color: rgb(0, 128, 128);"> 75</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> True<br /></span><span style="color: rgb(0, 128, 128);"> 76</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);"> 77</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> False<br /></span><span style="color: rgb(0, 128, 128);"> 78</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);"> 79</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 80</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> findTodoFromFolder(alist,folder):<br /></span><span style="color: rgb(0, 128, 128);"> 81</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">  parent, dirnames, filenames  </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">  os.walk(folder):<br /></span><span style="color: rgb(0, 128, 128);"> 82</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> fname </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> filenames:<br /></span><span style="color: rgb(0, 128, 128);"> 83</span> <span style="color: rgb(0, 0, 0);">            findTodo(os.path.join(parent, fname),alist)<br /></span><span style="color: rgb(0, 128, 128);"> 84</span> <span style="color: rgb(0, 0, 0);">            <br /></span><span style="color: rgb(0, 128, 128);"> 85</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);"> 86</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> mainLogic():<br /></span><span style="color: rgb(0, 128, 128);"> 87</span> <span style="color: rgb(0, 0, 0);">    configFileName </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">config.txt</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 88</span> <span style="color: rgb(0, 0, 0);">    cf </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ConfigParser.ConfigParser();<br /></span><span style="color: rgb(0, 128, 128);"> 89</span> <span style="color: rgb(0, 0, 0);">    cf.read(configFileName)<br /></span><span style="color: rgb(0, 128, 128);"> 90</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);"> 91</span> <span style="color: rgb(0, 0, 0);">    flist </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> cf.get(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">path</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">folder_list</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).split(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br /></span><span style="color: rgb(0, 128, 128);"> 92</span> <span style="color: rgb(0, 0, 0);">    itemlist </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> []<br /></span><span style="color: rgb(0, 128, 128);"> 93</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> folder  </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> flist:<br /></span><span style="color: rgb(0, 128, 128);"> 94</span> <span style="color: rgb(0, 0, 0);">        findTodoFromFolder(itemlist,folder)<br /></span><span style="color: rgb(0, 128, 128);"> 95</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);"> 96</span> <span style="color: rgb(0, 0, 0);">    excelPath </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> cf.get(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">path</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">excel_path</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br /></span><span style="color: rgb(0, 128, 128);"> 97</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);"> 98</span> <span style="color: rgb(0, 0, 0);">    mapItemIntoExcel(itemlist,excelPath)<br /></span><span style="color: rgb(0, 128, 128);"> 99</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);">100</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">\n---- OK -------- \n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">101</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">102</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> createCellStype():<br /></span><span style="color: rgb(0, 128, 128);">103</span> <span style="color: rgb(0, 0, 0);">    font </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> xlwt.Font()<br /></span><span style="color: rgb(0, 128, 128);">104</span> <span style="color: rgb(0, 0, 0);">    font.wrap </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> xlwt.Alignment.WRAP_AT_RIGHT<br /></span><span style="color: rgb(0, 128, 128);">105</span> <span style="color: rgb(0, 0, 0);">    style </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> xlwt.XFStyle()<br /></span><span style="color: rgb(0, 128, 128);">106</span> <span style="color: rgb(0, 0, 0);">    style.font </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> font<br /></span><span style="color: rgb(0, 128, 128);">107</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> style<br /></span><span style="color: rgb(0, 128, 128);">108</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);">109</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">110</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> mapItemIntoExcel(itemlist,excelPath):<br /></span><span style="color: rgb(0, 128, 128);">111</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);">:<br /></span><span style="color: rgb(0, 128, 128);">112</span> <span style="color: rgb(0, 0, 0);">                <br /></span><span style="color: rgb(0, 128, 128);">113</span> <span style="color: rgb(0, 0, 0);">        rb </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> xlrd.open_workbook(excelPath,formatting_info</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">True,on_demand</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">True)<br /></span><span style="color: rgb(0, 128, 128);">114</span> <span style="color: rgb(0, 0, 0);">        wb </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> xlutils.copy.copy(rb)<br /></span><span style="color: rgb(0, 128, 128);">115</span> <span style="color: rgb(0, 0, 0);">        sheet </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> wb.get_sheet(</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">)<br /></span><span style="color: rgb(0, 128, 128);">116</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);">117</span> <span style="color: rgb(0, 0, 0);">        row_index </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> len(sheet.rows)<br /></span><span style="color: rgb(0, 128, 128);">118</span> <span style="color: rgb(0, 0, 0);">        row_index </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">119</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);">120</span> <span style="color: rgb(0, 0, 0);">        cellStyle </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> createCellStype()<br /></span><span style="color: rgb(0, 128, 128);">121</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> item </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> itemlist:<br /></span><span style="color: rgb(0, 128, 128);">122</span> <span style="color: rgb(0, 0, 0);">            sheet.row(row_index).write(xlwt.Utils.col_by_name(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">A</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">),unicode(item[ITEM_KEY]),cellStyle )<br /></span><span style="color: rgb(0, 128, 128);">123</span> <span style="color: rgb(0, 0, 0);">            sheet.row(row_index).write(xlwt.Utils.col_by_name(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">D</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">),item[EST_KEY] ,cellStyle)<br /></span><span style="color: rgb(0, 128, 128);">124</span> <span style="color: rgb(0, 0, 0);">            sheet.row(row_index).write(xlwt.Utils.col_by_name(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">F</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">),</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">N</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">  ,cellStyle)<br /></span><span style="color: rgb(0, 128, 128);">125</span> <span style="color: rgb(0, 0, 0);">            sheet.row(row_index).write(xlwt.Utils.col_by_name(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">H</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">),item[FILE_PATH_KEY]  ,cellStyle)<br /></span><span style="color: rgb(0, 128, 128);">126</span> <span style="color: rgb(0, 0, 0);">            row_index </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">127</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);">128</span> <span style="color: rgb(0, 0, 0);">        wb.save(excelPath)<br /></span><span style="color: rgb(0, 128, 128);">129</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);">130</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">finally</span><span style="color: rgb(0, 0, 0);">:<br /></span><span style="color: rgb(0, 128, 128);">131</span> <span style="color: rgb(0, 0, 0);">        rb.release_resources    <br /></span><span style="color: rgb(0, 128, 128);">132</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);">133</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 128);">__name__</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">__main__</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">:<br /></span><span style="color: rgb(0, 128, 128);">134</span> <span style="color: rgb(0, 0, 0);">    mainLogic();<br /></span><span style="color: rgb(0, 128, 128);">135</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">136</span> <span style="color: rgb(0, 0, 0);"></span></div><br /><br />程序和配置文件请在这里下载:  <a target="_blank" title="http://www.uudisc.com/user/diegoyun/file/3880743" href="http://www.uudisc.com/user/diegoyun/file/3880743">http://www.uudisc.com/user/diegoyun/file/3880743</a><br /><br /></wbr></wbr></wbr></wbr></wbr></wbr></div><br />如何运行<br />
1&gt; sudo apt-get install python-xlrt python-xlwt<br />
2&gt; 到这个页面下载 xlutis : <a href="http://pypi.python.org/pypi/xlutils#downloads" target="_blank">http://pypi.python.org/pypi/<wbr>xlutils#downloads</wbr></a>   .<br />
然后 sudo easy_install xlutils   该功能需要安装python 的 setuptools 功能. 如果没装,<br />
ubuntu 会提示你安装.<br />
3&gt; 配置config.txt, 指定目录和excel路径<br />
4&gt; 运行 FindToDo.py<br /><br /><br /><br /><br /><img src ="http://www.cnitblog.com/yunshichen/aggbug/72760.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yunshichen/" target="_blank">Chenyunshi</a> 2011-02-06 21:42 <a href="http://www.cnitblog.com/yunshichen/archive/2011/02/06/72760.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ZT: Ubuntu find 命令</title><link>http://www.cnitblog.com/yunshichen/archive/2011/02/04/72756.html</link><dc:creator>Chenyunshi</dc:creator><author>Chenyunshi</author><pubDate>Fri, 04 Feb 2011 10:21:00 GMT</pubDate><guid>http://www.cnitblog.com/yunshichen/archive/2011/02/04/72756.html</guid><wfw:comment>http://www.cnitblog.com/yunshichen/comments/72756.html</wfw:comment><comments>http://www.cnitblog.com/yunshichen/archive/2011/02/04/72756.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yunshichen/comments/commentRss/72756.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yunshichen/services/trackbacks/72756.html</trackback:ping><description><![CDATA[原帖地址: http://blog.csdn.net/evane1890/archive/2007/04/10/1559465.aspx<br /><br />通用格式:find pathname -options [-print -exec -ok]<br />例子:<br />find / -name filename 再根目录里面搜索文件名为filename的文件<br />find /etc -name *s*在目录里面搜索带有s的文件<br />find /etc -name *S 在目录里面搜索以s结尾的文件<br />find /etc -name s*在目录里面搜索以s开头的文件<br />find / -amin -10在系统中搜索最后１０分钟访问的文件<br />find / -atime -2查找在系统中最后４８小时访问的文件<br />find / -empty 查找在系统中为空的文件或者是文件夹<br />find / -group groupname 查找在系统中属于groupname的文件<br />find / -mmin -5查找在系统中最后５分钟修改过的文件<br />find / -mtime -1查找在系统中最后２４小时修改过的文件<br />find /－nouser查找在系统中属于费用户的文件<br />find / -user username 查找在系统中属于username的文件<br />find / -ctime -1查找在系统中最后２４小时被改变状态的文件<br />find / -fstype type查找在系统中文件类型为？的文件<br />find / -user user１name -or -user user２name查找在系统中属于user1name或着属于user2name的文件<br />find / -user user1name -and -user2name在系统中查找既属于user1name又属于user2name用户的文件． <br /><br />一、find 命令格式<br /><br /><br />1、find命令的一般形式为；<br /><br />find pathname -options [-print -exec -ok ...]<br /><br /><br />2、find命令的参数；<br /><br />pathname: find命令所查找的目录路径。例如用.来表示当前目录，用/来表示系统根目录。<br />-print： find命令将匹配的文件输出到标准输出。<br />-exec： find命令对匹配的文件执行该参数所给出的shell命令。相应命令的形式为'command' { } \;，注意{ }和\；之间的空格。<br />-ok： 和-exec的作用相同，只不过以一种更为安全的模式来执行该参数所给出的shell命令，在执行每一个命令之前，都会给出提示，让用户来确定是否执行。<br /><br /><br />3、find命令选项<br /><br />-name<br />按照文件名查找文件。<br />-perm<br />按照文件权限来查找文件。<br />-prune<br />使用这一选项可以使find命令不在当前指定的目录中查找，如果同时使用-depth选项，那么-prune将被find命令忽略。<br />-user<br />按照文件属主来查找文件。<br />-group<br />按照文件所属的组来查找文件。<br />-mtime -n +n<br />按照文件的更改时间来查找文件， - n表示文件更改时间距现在n天以内，+ n表示文件更改时间距现在n天以前。find命令还有-atime和-ctime 选项，但它们都和-m time选项。<br />-nogroup<br />查找无有效所属组的文件，即该文件所属的组在/etc/groups中不存在。<br />-nouser<br />查找无有效属主的文件，即该文件的属主在/etc/passwd中不存在。<br />-newer file1 ! file2<br />查找更改时间比文件file1新但比文件file2旧的文件。<br />-type<br />查找某一类型的文件，诸如：<br />b - 块设备文件。<br />d - 目录。<br />c - 字符设备文件。<br />p - 管道文件。<br />l - 符号链接文件。<br />f - 普通文件。<br />-size n：[c] 查找文件长度为n块的文件，带有c时表示文件长度以字节计。<br />-depth：在查找文件时，首先查找当前目录中的文件，然后再在其子目录中查找。<br />-fstype：查找位于某一类型文件系统中的文件，这些文件系统类型通常可以在配置文件/etc/fstab中找到，该配置文件中包含了本系统中有关文件系统的信息。<br />-mount：在查找文件时不跨越文件系统mount点。<br />-follow：如果find命令遇到符号链接文件，就跟踪至链接所指向的文件。<br />-cpio：对匹配的文件使用cpio命令，将这些文件备份到磁带设备中。<br /><br />另外,下面三个的区别:<br />  -amin n<br />　　查找系统中最后N分钟访问的文件<br />　　-atime n<br />　　查找系统中最后n*24小时访问的文件<br />　　-cmin n<br />　　查找系统中最后N分钟被改变文件状态的文件<br />　　-ctime n<br />　　查找系统中最后n*24小时被改变文件状态的文件<br />  　-mmin n<br />　　查找系统中最后N分钟被改变文件数据的文件<br />　　-mtime n<br />　　查找系统中最后n*24小时被改变文件数据的文件<br /><br /><br />4、使用exec或ok来执行shell命令<br /><br />使用find时，只要把想要的操作写在一个文件里，就可以用exec来配合find查找，很方便的<br /><br />在有些操作系统中只允许-exec选项执行诸如l s或ls -l这样的命令。大多数用户使用这一选项是为了查找旧文件并删除它们。建议在真正执行rm命令删除文件之前，最好先用ls命令看一下，确认它们是所要删除的文件。<br /><br />exec选项后面跟随着所要执行的命令或脚本，然后是一对儿{ }，一个空格和一个\，最后是一个分号。为了使用exec选项，必须要同时使用print选项。如果验证一下find命令，会发现该命令只输出从当前路径起的相对路径及文件名。<br /><br />例如：为了用ls -l命令列出所匹配到的文件，可以把ls -l命令放在find命令的-exec选项中<br /><br /># find . -type f -exec ls -l { } \;<br />-rw-r--r-- 1 root root 34928 2003-02-25 ./conf/httpd.conf<br />-rw-r--r-- 1 root root 12959 2003-02-25 ./conf/magic<br />-rw-r--r-- 1 root root 180 2003-02-25 ./conf.d/README<br /><br />上面的例子中，find命令匹配到了当前目录下的所有普通文件，并在-exec选项中使用ls -l命令将它们列出。<br />在/logs目录中查找更改时间在5日以前的文件并删除它们：<br /><br />$ find logs -type f -mtime +5 -exec rm { } \;<br /><br />记住：在shell中用任何方式删除文件之前，应当先查看相应的文件，一定要小心！当使用诸如mv或rm命令时，可以使用-exec选项的安全模式。它将在对每个匹配到的文件进行操作之前提示你。<br /><br />在下面的例子中， find命令在当前目录中查找所有文件名以.LOG结尾、更改时间在5日以上的文件，并删除它们，只不过在删除之前先给出提示。<br /><br />$ find . -name "*.conf" -mtime +5 -ok rm { } \;<br />&lt; rm ... ./conf/httpd.conf &gt; ? n<br /><br />按y键删除文件，按n键不删除。<br /><br />任何形式的命令都可以在-exec选项中使用。<br /><br />在下面的例子中我们使用grep命令。find命令首先匹配所有文件名为“ passwd*”的文件，例如passwd、passwd.old、passwd.bak，然后执行grep命令看看在这些文件中是否存在一个sam用户。<br /><br /># find /etc -name "passwd*" -exec grep "sam" { } \;<br />sam:x:501:501::/usr/sam:/bin/bash
					<br /><br />find . -name       "*.svn" -atime -7  -ok rm -rf {  } \;<br />
在当前文件夹下查找以.svn的文件(7天以内访问过的) <br />
- ok 表示询问<br /><br /><br />
find /home/log/ -ctime 3-name bbslog\* -exec rm {} \;  ＃＃查找前第三天的bbslog文件，并删除<br />
find /tmp/log/ -ctime ＋4 -name mail\* -exec rm {} \;           ＃＃查找4天前的所有mail日志文件，并全部删除<br /><br /><br />
原文地址：<a href="http://www.zhenyusc.cn/" target="_blank">http://www.zhenyusc.cn/</a><br /><img src ="http://www.cnitblog.com/yunshichen/aggbug/72756.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yunshichen/" target="_blank">Chenyunshi</a> 2011-02-04 18:21 <a href="http://www.cnitblog.com/yunshichen/archive/2011/02/04/72756.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Groovy 教程: 入门</title><link>http://www.cnitblog.com/yunshichen/archive/2010/06/05/66498.html</link><dc:creator>Chenyunshi</dc:creator><author>Chenyunshi</author><pubDate>Sat, 05 Jun 2010 07:03:00 GMT</pubDate><guid>http://www.cnitblog.com/yunshichen/archive/2010/06/05/66498.html</guid><wfw:comment>http://www.cnitblog.com/yunshichen/comments/66498.html</wfw:comment><comments>http://www.cnitblog.com/yunshichen/archive/2010/06/05/66498.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cnitblog.com/yunshichen/comments/commentRss/66498.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yunshichen/services/trackbacks/66498.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 前言		某年某月某日,正式从python转移到groovy.关于python和groovy的比较,网上已经有许多文章了.我的理由是, 作为一个上了年纪的java程序员,groovy的学习曲线要比python低.毕竟,我只是想用groovy写一些小程序.而这些小程序用java做又太耗时间.希望这篇文章能够帮助java程序员尽快进入groovy世界.预备知识,安装学习groovy最好能熟练用jav...&nbsp;&nbsp;<a href='http://www.cnitblog.com/yunshichen/archive/2010/06/05/66498.html'>阅读全文</a><img src ="http://www.cnitblog.com/yunshichen/aggbug/66498.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yunshichen/" target="_blank">Chenyunshi</a> 2010-06-05 15:03 <a href="http://www.cnitblog.com/yunshichen/archive/2010/06/05/66498.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ubuntu 10.04 基本安装配置</title><link>http://www.cnitblog.com/yunshichen/archive/2010/05/02/65738.html</link><dc:creator>Chenyunshi</dc:creator><author>Chenyunshi</author><pubDate>Sun, 02 May 2010 06:16:00 GMT</pubDate><guid>http://www.cnitblog.com/yunshichen/archive/2010/05/02/65738.html</guid><wfw:comment>http://www.cnitblog.com/yunshichen/comments/65738.html</wfw:comment><comments>http://www.cnitblog.com/yunshichen/archive/2010/05/02/65738.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cnitblog.com/yunshichen/comments/commentRss/65738.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yunshichen/services/trackbacks/65738.html</trackback:ping><description><![CDATA[
		<br />
		<h2>
				<b>
						<font color="#336600">前言</font>
				</b>
		</h2>如果你是单硬盘光盘引导安装, 那就好了, 什么麻烦事都没有, 装完就行. (建议你刻盘安装, 不建议硬盘安装). 你可以忽略下面的文字.<br /><br />ubuntu 10.04 正式版终于发布了, 我第一时间下载,刻盘, 安装, 却遇到了一点小麻烦. 简言之, 我pc有两块硬盘, 一块装windows一块装ubuntu, ubuntu的引导程序不装在mbr.  这样在安装完10.04之后, 麻烦来了. 即使我在grub4dos的menu.list里正确指定了ubuntu的分区, 启动仍然失败, log的信息说我root的分区不对. 但我明明是设对的啊. 尝试找10.04的grub menu.lst, 找不到. 查了官方的release note, 原来从ubuntu910开始都使用grub2 而不是以前的grub, 所以没有了menu.lst. 那就好办, 肯定有个地方放置启动信息. 继续看文档, 原来是 /boot/grub/grub.cfg 文件. 里面的root信息不对. 修改之, 经grub4dos引导之后, 正确进入ubuntu.<br /><br />(如果你不明白上面说的信息, 你可以参考这篇文章: <a target="_blank" href="http://www.linuxidc.com/Linux/2008-01/10834.htm">双硬盘安装ubuntu和windows互不影响</a> )<br /><br /><br /><hr size="2" width="100%" /><h2><font color="#006600"><b>选择cn99源</b></font></h2>以前在804就一直用cn99, 现在依然用. 我是电信的宽带, 用cn99下载均速250k/s, 平时下载一些软件才不到200k. 用cn99真可谓感情深,速度快.<br /><br />打开administration--&gt;software source, 在download from下拉列表,选择 china, 选择ubuntu.cn99.com.  然后点close, 提示是否reload文件列表, 点之.<br /><br /><hr size="2" width="100%" /><br /><h2><font color="#006600"><b><font>安装常用工具</font></b></font></h2><br />打开accessories--&gt; terminal, 敲入:<br /><br /><div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">sudo apt-get install  python-mutagen mplayer  libxine1-ffmpeg libxine1-all-plugins libxine1-plugins    gstreamer0</span><span style="color: rgb(0, 0, 0);">.10</span><span style="color: rgb(0, 0, 0);">-ffmpeg  gstreamer0</span><span style="color: rgb(0, 0, 0);">.10</span><span style="color: rgb(0, 0, 0);">-plugins-bad gstreamer0</span><span style="color: rgb(0, 0, 0);">.10</span><span style="color: rgb(0, 0, 0);">-plugins-bad-multiverse gstreamer0</span><span style="color: rgb(0, 0, 0);">.10</span><span style="color: rgb(0, 0, 0);">-plugins-ugly gstreamer0</span><span style="color: rgb(0, 0, 0);">.10</span><span style="color: rgb(0, 0, 0);">-plugins-ugly-multiverse gstreamer0</span><span style="color: rgb(0, 0, 0);">.10</span><span style="color: rgb(0, 0, 0);">-esd   libdvdnav4  libdvdcss2 smplayer   recordmydesktop gtk-recordmydesktop filezilla  scrot  nautilus-open-terminal d4x amule  ntfs-config </span>ibus ibus-table ibus-pinyin</div><br />这个命令包括了屏幕录像工具(<span style="color: rgb(0, 0, 0);">recordmydesktop), ftp程序(</span><span style="color: rgb(0, 0, 0);">filezilla), 截屏工具(scrot)</span>, 断点续传下载工具(d4x), emule类工具(amule), 配置ntfs分区工具(ntfs-config),中文输入法(如果你用中文语言安装系统,那么默认已经装上中文输入法) 和一些多媒体库,工具.<br /><br />接下来做一些配置工作:<br /><br /><b><font color="#009900">配置ntfs共享分区</font></b><br /><br />
多数人都是用win和ubuntu双系统。如我
的设置如下： c：安装windows 。 e安装ubuntu，d作为共享盘。放置两个系统共用的文件。例如，我的程序代码就放在d盘。<br /><br />
但
实践中发现，如果d盘采用fat32分区，那么ubuntu创建大写文件夹的时候会出现问题。例如将我某个java应用程序的WEB-INF目录自动更改
为web-inf,害我为这个问题烦恼许久，并且该问题在ubuntu社区暂时没有解决办法。所以建议你的共享分区采用ntfs分区。<br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->sudo  ntfs-config</div><br />
然后选择你的ntfs分区挂载即可。<br /><br />
有时候你会发现当你选择某个分区之后勾选框处于disable状态，很
简单，在选分区之后，在后面的"mount point" 输入栏随便输个名字即可。例如 mywin ，那么这个分区就会挂载到 
/media/mywin 下。<br /><br /><b><font color="#009900">解决Gedit乱码问题<br /></font></b><br />
如
果不作设置,gedit修改过的文本文件在windows系统里是乱码,反之亦然.<br /><br />
修改办法如下:<br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->gconf-editor</div><br />
在
左边的树里,找到apps/gedit-2/preferences/encodings   ,在右侧可以看到两个项,分别是 
auto_detected 和 shown_in_menu,双击之,添加GBK 的值并将之遇到最上方,点击ok确认即可.<br /><br /><b><font color="#009900">配置截图软件scrot</font></b><br /><br />用"Add to panel" 添加一个新程序, 并将命令设置为 scrot -s -b<br /><br />以后每次截图时只需要鼠标点这个程序,并
拖动鼠标截取所需区域即可. <br /><br />默认截取的图片位于用户的home目录.<br /><br /><br /><hr size="2" width="100%" /><br /><h2><font><b><font><font color="#006600"><b><font>安装开发工具</font></b></font></font></b></font></h2>
这是给程序员用的, 包括了java,python和qt4<br /><br /><div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">sudo apt-get install build-essential autoconf  subversion sun-java6-jdk sun-java6-source ant idle  qt4-dev-tools qt4-doc qt4-qtconfig qt4-designer ctags </span></div><br /><hr size="2" width="100%" /><br /><h2><font><b><font><font color="#006600"><b><font>安装QQ</font></b></font></font></b></font></h2>到这个页面: <a target="_blank" href="http://im.qq.com/qq/linux/download.shtml">http://im.qq.com/qq/linux/download.shtml</a>  选择下载deb 包, 然后双击之. qq安装完成.<br /><br /><hr size="2" width="100%" /><br /><h2><font color="#006600"><b>还有什么?</b></font></h2>现在你的ubuntu已经能像windows一样满足日常大部分工作了. 当然, 你或许想上网上银行, 但很遗憾, 国内银行的网银都不支持linux系统. 所以你有两个办法继续使用网银, 一是用手机付款, 二是安装虚拟机用windows上网银. 安装虚拟机这个主题可以见我的这篇帖子: <br /><br /><a target="_blank" title="Ubuntu 安装 xp 要点" href="/yunshichen/archive/2008/09/02/48644.html">http://www.cnitblog.com/yunshichen/archive/2008/09/02/48644.html</a><br /><br />就这些了. ubuntu10.04 是目前为止我见到的用户体验最好的linux os. 遥想两年前装804, 虽然也号称LTS版本, 但装上后麻烦一直不断: 找不到显卡驱动, 分辨率不对, 中文输入法配置有问题... 两年过去了, ubuntu也成长了很多.衷心祝愿ubuntu能越来越强大.<br /><br /><br /><br /><br /><br /><img src ="http://www.cnitblog.com/yunshichen/aggbug/65738.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yunshichen/" target="_blank">Chenyunshi</a> 2010-05-02 14:16 <a href="http://www.cnitblog.com/yunshichen/archive/2010/05/02/65738.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>官方Hibernate tutorial 修正版</title><link>http://www.cnitblog.com/yunshichen/archive/2010/03/26/hibernate_tutorial_fix.html</link><dc:creator>Chenyunshi</dc:creator><author>Chenyunshi</author><pubDate>Fri, 26 Mar 2010 09:39:00 GMT</pubDate><guid>http://www.cnitblog.com/yunshichen/archive/2010/03/26/hibernate_tutorial_fix.html</guid><wfw:comment>http://www.cnitblog.com/yunshichen/comments/64834.html</wfw:comment><comments>http://www.cnitblog.com/yunshichen/archive/2010/03/26/hibernate_tutorial_fix.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yunshichen/comments/commentRss/64834.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yunshichen/services/trackbacks/64834.html</trackback:ping><description><![CDATA[
		<br />
		<h2>
				<font color="#006600">
						<b>官方版教程的问题</b>
				</font>
		</h2>    公司新同事比较多,为了让他们尽快熟悉Hibernate, 我打算做个系列教程. 于是边看官方教程边总结, 这样跟着做下来, 问题来了. <br /><br />    我看的是这个教程:  <a target="_blank" title="http://docs.jboss.org/hibernate/core/3.3/reference/en-US/html/tutorial.html#tutorial-firstapp" href="http://docs.jboss.org/hibernate/core/3.3/reference/en-US/html/tutorial.html#tutorial-firstapp">http://docs.jboss.org/hibernate/core/3.3/reference/en-US/html/tutorial.html#tutorial-firstapp</a>  边看边发疑问: 有人成功跑过这个教程不? 我估计是没有. 因为该教程的maven配置有问题,而且文中漏了一些方法说明.如果你真的完完全全照着官方教程跑, 是跑不出来的.<br /><br />    而且, 该教程用maven来打包. 对做了多年J2EE 开发的人来说, Maven和Ivy自然不是什么问题. 但指望刚走出学校的小伙子去了解它们,无疑不切实际. 培训有所谓"台阶式"教育一说, 这个台阶, 定得太高了. 或者Hibernate的作者都长于技术, 而不太关注教程这些东西吧.<br /><br />    我的这个程序包其实没什么技术含量, 就是把官方教程的文件都做好, 配置好, 写好测试类, 用ant来编译. 指望新手熟悉maven不现实, 但做java的人, ant是必须掌握的.<br /><br />    下载地址: <a target="_blank" title="http://www.uushare.com/user/diegoyun/file/2781837" href="http://www.uushare.com/user/diegoyun/file/2781837">http://www.uushare.com/user/diegoyun/file/2781837</a><br /><hr size="2" width="100%" /><br /><h2><font><b><font color="#006600"><b>如何运行</b></font></b></font></h2>    假设你已经配置好了ant,java<br /><br />    1&gt; 解压,然后用 ant compile-src 来编译程序<br />    2&gt; 将工程导入到Eclipse<br />    3&gt; 在文件夹里有个database目录, cd 到这个目录, 然后双击 start_server.bat . 这样, hsqldb 就启动起来了.<br />    4&gt; 在Eclipse里打开 EventManager.java, 在main方法里, 改变cmd的值, 即可以测试hibernate的多个方法.<br /><br />    Good luck.<br /><hr size="2" width="100%" /><br /><h2><font color="#006600"><b>已解决的问题</b></font></h2>    这是我跑官网例子时遇到的错误, 一并记下, 希望可以帮助到你.<br /><br />    <b>在Configuration().configure().buildSessionFactory() 时遇到:</b><b>Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.</b><br /><br />    导致这个错误的两个原因:<br />    1&gt;你的xml声明是utf-8字符集, 但实际上你用其他文本编辑器存xml的时候, 不是存成utf-8. 解决办法是把  &lt;?xml version='1.0' encoding='utf-8'?&gt; 改为 &lt;?xml version='1.0'?&gt;<br />    <br />    2&gt;你的hibernate.cfg.xml 路径不对. 很显然, hibernate的error信息误导了你. (不知道这算不算hibernate的一个bug)<br /><br /><br /><br /><img src ="http://www.cnitblog.com/yunshichen/aggbug/64834.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yunshichen/" target="_blank">Chenyunshi</a> 2010-03-26 17:39 <a href="http://www.cnitblog.com/yunshichen/archive/2010/03/26/hibernate_tutorial_fix.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Python 读写 Excel</title><link>http://www.cnitblog.com/yunshichen/archive/2010/03/16/64661.html</link><dc:creator>Chenyunshi</dc:creator><author>Chenyunshi</author><pubDate>Mon, 15 Mar 2010 17:20:00 GMT</pubDate><guid>http://www.cnitblog.com/yunshichen/archive/2010/03/16/64661.html</guid><wfw:comment>http://www.cnitblog.com/yunshichen/comments/64661.html</wfw:comment><comments>http://www.cnitblog.com/yunshichen/archive/2010/03/16/64661.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnitblog.com/yunshichen/comments/commentRss/64661.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yunshichen/services/trackbacks/64661.html</trackback:ping><description><![CDATA[
		<br />基本上, 这个网页已经说明一切了: <a target="_blank" title="http://pypi.python.org/pypi/xlrd" href="http://pypi.python.org/pypi/xlrd">http://pypi.python.org/pypi/xlrd</a><br /><br />等有时间再把这个页面写漂亮,现在先记一些代码.<br /><br /><h2><font color="#336600"><b>读Excel</b></font></h2>先建个simple.xls<br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> xlrd </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> open_workbook<br /><br />wb </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> open_workbook(</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">simple.xls</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">rb</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br /></span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> s </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> wb.sheets():<br />    </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Sheet:</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,s.name<br />    </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> row </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> range(s.nrows):<br />        values</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">[]<br />        </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> col </span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);"> range(s.ncols):<br />            values.append(s.cell(row,col).value)<br />        </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">.join(values)<br />    </span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);"><br /><br />        <br /></span></div><br /><hr size="2" width="100%" /><h2><font><b><font color="#336600"><b>写Excel</b></font></b></font></h2><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> tempfile </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> TemporaryFile<br /></span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> xlwt </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> Workbook<br /><br />book </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> Workbook()<br />sheet1 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> book.add_sheet(</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Sheet 1</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br />book.add_sheet(</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Sheet 2</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br />sheet1.write(0,0,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">A1</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br />sheet1.write(0,</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">B1</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br /><br />row1 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sheet1.row(</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">)<br />row1.write(0,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">A2</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br />row1.write(</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">B2</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br /><br />sheet1.col(0).width </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">10000</span><span style="color: rgb(0, 0, 0);"><br /><br />sheet2 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> book.get_sheet(</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">)<br />sheet2.row(0).write(0,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Sheet 2 A1</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br />sheet2.row(0).write(</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Sheet 2 B1</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br />sheet2.flush_row_data()<br /><br />sheet2.write(</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,0,</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">Sheet 2 A3</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br />sheet2.col(0).width </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">5000</span><span style="color: rgb(0, 0, 0);"><br />sheet2.col(0).hidden </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> True<br /><br />book.save(</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">simple2.xls</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br />book.save(TemporaryFile())<br /></span></div><br /><br /><br /><img src ="http://www.cnitblog.com/yunshichen/aggbug/64661.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yunshichen/" target="_blank">Chenyunshi</a> 2010-03-16 01:20 <a href="http://www.cnitblog.com/yunshichen/archive/2010/03/16/64661.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>python实用技巧 : Filtering os.walk</title><link>http://www.cnitblog.com/yunshichen/archive/2010/03/07/64528.html</link><dc:creator>Chenyunshi</dc:creator><author>Chenyunshi</author><pubDate>Sun, 07 Mar 2010 08:42:00 GMT</pubDate><guid>http://www.cnitblog.com/yunshichen/archive/2010/03/07/64528.html</guid><wfw:comment>http://www.cnitblog.com/yunshichen/comments/64528.html</wfw:comment><comments>http://www.cnitblog.com/yunshichen/archive/2010/03/07/64528.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yunshichen/comments/commentRss/64528.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yunshichen/services/trackbacks/64528.html</trackback:ping><description><![CDATA[
		<br />
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<span style="color: rgb(128, 0, 0);">'''</span>
				<span style="color: rgb(128, 0, 0);">
						<br />Created on Mar 7, 2010<br /><br />@author: Diego<br /><br />需求: 得到某个目录下, 符合过滤条件的文件夹/文件.<br />实现: 将os.walk再次包装.<br /><br />TODO: 不知道本程序的做法, 和传统的逐个目录列举的方法, 哪个效率更高. 待测试.<br /><br /></span>
				<span style="color: rgb(128, 0, 0);">'''</span>
				<span style="color: rgb(0, 0, 0);">
						<br />
				</span>
				<span style="color: rgb(0, 0, 255);">import</span>
				<span style="color: rgb(0, 0, 0);"> os<br /></span>
				<span style="color: rgb(0, 0, 255);">import</span>
				<span style="color: rgb(0, 0, 0);"> os.path<br /><br />os.path.sep</span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(128, 0, 0);">"</span>
				<span style="color: rgb(128, 0, 0);">/</span>
				<span style="color: rgb(128, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">
						<br />path </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> </span>
				<span style="color: rgb(128, 0, 0);">"</span>
				<span style="color: rgb(128, 0, 0);">/media/dev/project/google_codes/srgjs</span>
				<span style="color: rgb(128, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">
						<br />EXCLUDE_DIR_LIST </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> [</span>
				<span style="color: rgb(128, 0, 0);">"</span>
				<span style="color: rgb(128, 0, 0);">.SVN</span>
				<span style="color: rgb(128, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">,</span>
				<span style="color: rgb(128, 0, 0);">"</span>
				<span style="color: rgb(128, 0, 0);">CVS</span>
				<span style="color: rgb(128, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">]<br />EXCLUDE_FILE_LIST </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> [</span>
				<span style="color: rgb(128, 0, 0);">"</span>
				<span style="color: rgb(128, 0, 0);">.CVSIGNORE</span>
				<span style="color: rgb(128, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">]<br /><br /><br /></span>
				<span style="color: rgb(0, 0, 255);">def</span>
				<span style="color: rgb(0, 0, 0);"> is_parent_exclude(parentPath,excludeDirList):<br />    ss</span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);">parentPath.split(</span>
				<span style="color: rgb(128, 0, 0);">"</span>
				<span style="color: rgb(128, 0, 0);">/</span>
				<span style="color: rgb(128, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">);<br />    </span>
				<span style="color: rgb(0, 0, 255);">for</span>
				<span style="color: rgb(0, 0, 0);"> s </span>
				<span style="color: rgb(0, 0, 255);">in</span>
				<span style="color: rgb(0, 0, 0);"> ss:<br />        </span>
				<span style="color: rgb(0, 0, 255);">if</span>
				<span style="color: rgb(0, 0, 0);">(s.upper() </span>
				<span style="color: rgb(0, 0, 255);">in</span>
				<span style="color: rgb(0, 0, 0);"> excludeDirList):<br />            </span>
				<span style="color: rgb(0, 0, 255);">return</span>
				<span style="color: rgb(0, 0, 0);"> True<br />    <br />    </span>
				<span style="color: rgb(0, 0, 255);">return</span>
				<span style="color: rgb(0, 0, 0);"> False<br /><br /></span>
				<span style="color: rgb(0, 0, 255);">def</span>
				<span style="color: rgb(0, 0, 0);"> filter_walk(targetDirectory,excludeDirList,excludeFileExtList):<br />    dirList</span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);">[]<br />    fileList</span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);">[]<br />    </span>
				<span style="color: rgb(0, 0, 255);">for</span>
				<span style="color: rgb(0, 0, 0);"> (parent, dirs, files) </span>
				<span style="color: rgb(0, 0, 255);">in</span>
				<span style="color: rgb(0, 0, 0);"> os.walk(targetDirectory):<br />        <br />        </span>
				<span style="color: rgb(0, 0, 255);">for</span>
				<span style="color: rgb(0, 0, 0);"> d </span>
				<span style="color: rgb(0, 0, 255);">in</span>
				<span style="color: rgb(0, 0, 0);"> dirs:<br />            </span>
				<span style="color: rgb(0, 0, 255);">if</span>
				<span style="color: rgb(0, 0, 0);">(d.upper() </span>
				<span style="color: rgb(0, 0, 255);">in</span>
				<span style="color: rgb(0, 0, 0);"> excludeDirList):<br />                </span>
				<span style="color: rgb(0, 0, 255);">continue</span>
				<span style="color: rgb(0, 0, 0);">
						<br />            <br />            </span>
				<span style="color: rgb(0, 128, 0);">#</span>
				<span style="color: rgb(0, 128, 0);">To check if one of the parent dir should be excluded.</span>
				<span style="color: rgb(0, 128, 0);">
						<br />
				</span>
				<span style="color: rgb(0, 0, 0);">            </span>
				<span style="color: rgb(0, 0, 255);">if</span>
				<span style="color: rgb(0, 0, 0);">(is_parent_exclude(parent,excludeDirList)):<br />                </span>
				<span style="color: rgb(0, 0, 255);">continue</span>
				<span style="color: rgb(0, 0, 0);">
						<br />            <br />            dirList.append(parent</span>
				<span style="color: rgb(0, 0, 0);">+</span>
				<span style="color: rgb(128, 0, 0);">"</span>
				<span style="color: rgb(128, 0, 0);">/</span>
				<span style="color: rgb(128, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">+</span>
				<span style="color: rgb(0, 0, 0);">d)<br />            <br />        <br />        </span>
				<span style="color: rgb(0, 0, 255);">for</span>
				<span style="color: rgb(0, 0, 0);"> f </span>
				<span style="color: rgb(0, 0, 255);">in</span>
				<span style="color: rgb(0, 0, 0);"> files:<br />            </span>
				<span style="color: rgb(0, 0, 255);">if</span>
				<span style="color: rgb(0, 0, 0);">(f.upper() </span>
				<span style="color: rgb(0, 0, 255);">in</span>
				<span style="color: rgb(0, 0, 0);"> excludeFileExtList):<br />                </span>
				<span style="color: rgb(0, 0, 255);">continue</span>
				<span style="color: rgb(0, 0, 0);">
						<br />            </span>
				<span style="color: rgb(0, 128, 0);">#</span>
				<span style="color: rgb(0, 128, 0);">To check if one of the parent dir should be excluded.</span>
				<span style="color: rgb(0, 128, 0);">
						<br />
				</span>
				<span style="color: rgb(0, 0, 0);">            </span>
				<span style="color: rgb(0, 0, 255);">if</span>
				<span style="color: rgb(0, 0, 0);">(is_parent_exclude(parent,excludeDirList)):<br />                </span>
				<span style="color: rgb(0, 0, 255);">continue</span>
				<span style="color: rgb(0, 0, 0);">
						<br />            <br />            fileList.append(parent</span>
				<span style="color: rgb(0, 0, 0);">+</span>
				<span style="color: rgb(128, 0, 0);">"</span>
				<span style="color: rgb(128, 0, 0);">/</span>
				<span style="color: rgb(128, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">+</span>
				<span style="color: rgb(0, 0, 0);">f)<br />    <br />    </span>
				<span style="color: rgb(0, 0, 255);">return</span>
				<span style="color: rgb(0, 0, 0);"> (dirList,fileList)            <br /><br /></span>
				<span style="color: rgb(0, 128, 0);">#</span>
				<span style="color: rgb(0, 128, 0);">test</span>
				<span style="color: rgb(0, 128, 0);">
						<br />
				</span>
				<span style="color: rgb(0, 0, 0);">dirs,files </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> filter_walk(path,EXCLUDE_DIR_LIST,EXCLUDE_FILE_LIST)<br /><br /></span>
				<span style="color: rgb(0, 0, 255);">for</span>
				<span style="color: rgb(0, 0, 0);"> d </span>
				<span style="color: rgb(0, 0, 255);">in</span>
				<span style="color: rgb(0, 0, 0);"> dirs:<br />    </span>
				<span style="color: rgb(0, 0, 255);">print</span>
				<span style="color: rgb(0, 0, 0);"> d<br /><br /></span>
				<span style="color: rgb(0, 0, 255);">for</span>
				<span style="color: rgb(0, 0, 0);"> f </span>
				<span style="color: rgb(0, 0, 255);">in</span>
				<span style="color: rgb(0, 0, 0);"> files:<br />    </span>
				<span style="color: rgb(0, 0, 255);">print</span>
				<span style="color: rgb(0, 0, 0);"> f<br /><br /><br /></span>
		</div>
		<br />
<img src ="http://www.cnitblog.com/yunshichen/aggbug/64528.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yunshichen/" target="_blank">Chenyunshi</a> 2010-03-07 16:42 <a href="http://www.cnitblog.com/yunshichen/archive/2010/03/07/64528.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>