Wednesday, May 14, 2008

pydoc

今天玩了下pydoc,还挺爽的,记录一下.

pydoc 是python的内建文档工具(貌似是利用python的反射弄的,爽是爽,不过好像对zope等库会有点问题啊)

pydoc的用法

pydoc - the Python documentation tool

pydoc.py <name> ...

    Show text documentation on something.  <name> may be the name of a  Python keyword, topic, function, module, or package, or a dotted  reference to a class or function within a module or module in a  package.  If <name> contains a '\', it is used as the path to a  Python source file to document. If name is 'keywords', 'topics',  or 'modules', a listing of these things is displayed.

    比如 :

    pydoc __builtin__.str.find 会显示str.find的文档,不过比较郁闷的是直接 pydoc str.find 是不行的...

pydoc.py -k <keyword>

    Search for a keyword in the synopsis lines of all available modules.

pydoc.py -p <port>

    Start an HTTP server on the given port on the local machine.

   在对应port开一个能返回文档的http server,用浏览器访问就可以了

pydoc.py -g

    Pop up a graphical interface for finding and serving documentation.

    超推荐,除了开http server外,还会打开一个小小的图形化搜索工具, 搜索的结果多于一项时,会显示为一个列表,双击列表的一项就会打开浏览器来访问http server来显示相关的文档

  不过貌似搜索功能不怎么样啊,只能直接搜索到module

pydoc.py -w <name> ...

    Write out the HTML documentation for a module to a file in the current

    directory.  If <name> contains a '\', it is treated as a filename; if

    it names a directory, documentation is written for all the contents.

   把生成的Html保存成文件而已



pydoc 生成的html的颜色挺不错,就是缺少一些导航的功能,比方说它把一个Module的文档分成Modules,Classes,Functions, Data,几大块,但没有对应的导航链接或锚点,想快速切换很麻烦.看了下源码,发现想改变输出的格式还是比较简单的,为了添加锚点,这样改了一下:

class HTMLDoc(Doc):

......

def bigsection(self, title, *args):

        """Format a section with a big heading."""

#        title = '<big><strong>%s</strong></big>' % title

       title = '<big><strong><a name="%s">%s</a></strong></big>' % (title,title)

        return self.section(title, *args)


这样想快速的跳到Functions部分只需要在浏览器的地址栏里的url后面加上#Functions ,然后按回车就可以了,以后有时间还可以继续优化 :)



另外vim上的pydoc.vim插件也很爽,因为它会直接调用pydoc命令,而我安装的python2.5没有附带它的命令行程序,自己弄了一个放到 python_root:

pydoc.bat:

  d:\%python_root%\Lib\pydoc.py  %*

这样就可以用 PyDocSearch或PyDoc 命令或直接把光标移动到想查询的字符串上按  \pw 来查询了

Thursday, May 08, 2008

整合

上次提到的项目告吹,又开始准备另一个.完完整整的把ppt看完,文档还行.总而言之,就是整合,胶水是jms,soap(web service),snmp.这样的项目做到第三个,实在是泄气.今天看一个篇文章,讲windows和mac OS,里面把程序员分3等,但无论是哪等,都难免靠enterprise吃饭,就那样了.
刚刚做完uml培训,挑了3种图和一个由需求到详细设计的思路来讲了一下,15分钟左右,大家的反映似乎是觉得太短(又或者太简单?).不晓得有没有人觉得我很儿戏,不过无论如何都与我无关.我讲的是思路不是无趣的条条框框的规范,同时也表达了一种对待UML的态度.UML只是一种语言而已,不是软件架构和设计本身.就算你把英语所有的语法和单词都搞懂,也不能帮你写出一句有意义的话,不是吗?
最近一个周左右在琢磨一个android上的book reader,要有书库管理功能,要能方便的与pc同步,能higlight文字,添加书签和批注,支持的格式当然也是越多越好.由于不熟悉android的lib,先自己实现了一个可以滚屏的,显示高亮文字的view控件.后来上网查了下才知道用editText就可以了,白忙了几天(一边看<律政英雄>一边忙,呵呵).最近3天在弄chm文件格式.微软重来没公开过它的格式标准,找到的就只有逆向工程出来的2分文档,一边对着包含有这样那样的问题的文档一边对着一个有bug的开源项目的代码来研究,热情都快要浇熄了...
最近精神不怎么样,每次想到数学方面的东西就头疼(特别是建模方面的),以后一定要好好休息+规律生活+找本书修炼修炼,今天就这样吧,明天继续..