免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5150 | 回复: 8
打印 上一主题 下一主题

python-sidebar安装问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-01-25 22:18 |只看该作者 |倒序浏览

我这里有一个python-sidebar,它可以查看python-API文档,但在安装时却没能装上,我的系统配置如下:
MS windows xp sp2,python-2.4.2。现将这个软件和我安装时的提示文件传上来, 请大家看看,能给点建议的也可以。

python-sidebar.result.zip

504 Bytes, 下载次数: 29

安装提示文件

python-sidebar.tar.gz

17.97 KB, 下载次数: 21

python-sidebar

论坛徽章:
0
2 [报告]
发表于 2006-01-26 10:29 |只看该作者
你是怎么装的?直接点击网站链接就可以直接安装。

论坛徽章:
0
3 [报告]
发表于 2006-01-26 13:33 |只看该作者
原帖由 unixer2i 于 2006-1-25 22:18 发表
我这里有一个python-sidebar,它可以查看python-API文档,但在安装时却没能装上,我的系统配置如下:
MS windows xp sp2,python-2.4.2。现将这个软件和我安装时的提示文件传 ...

我运行里面的update.py没有报错,看你的错误信息好像是网络的问题

但这个不是这么安装的,你要做的只是用mozilla或firefox浏览器,访问
http://projects.edgewall.com/python-sidebar/
点页面上的“install”链接就行了

论坛徽章:
0
4 [报告]
发表于 2006-01-26 15:59 |只看该作者
原帖由 wolfg 于 2006-1-26 13:33 发表

我运行里面的update.py没有报错,看你的错误信息好像是网络的问题

但这个不是这么安装的,你要做的只是用mozilla或firefox浏览器,访问
http://projects.edgewall.com/python-sidebar/
点页面上 ...


不是,我是直接安装这个软件的。是在下线[即下网后]单独安装的,可还是报错。究竟是什么原因呢?

论坛徽章:
0
5 [报告]
发表于 2006-01-26 16:29 |只看该作者
原帖由 unixer2i 于 2006-1-26 15:59 发表


不是,我是直接安装这个软件的。是在下线[即下网后]单独安装的,可还是报错。究竟是什么原因呢?

你要做的只是用mozilla或firefox浏览器,访问
http://projects.edgewall.com/python-sidebar/
点页面上的“install”链接就行了

论坛徽章:
0
6 [报告]
发表于 2006-01-26 17:48 |只看该作者
原帖由 unixer2i 于 2006-1-26 15:59 发表


不是,我是直接安装这个软件的。是在下线[即下网后]单独安装的,可还是报错。究竟是什么原因呢?


这个是用来浏览在线文档的

论坛徽章:
0
7 [报告]
发表于 2006-01-26 20:38 |只看该作者
原帖由 wolfg 于 2006-1-26 17:48 发表


这个是用来浏览在线文档的


我就想用python-sidebar来浏览python本地文档,尤其是它的API文档。

论坛徽章:
0
8 [报告]
发表于 2006-01-26 20:57 |只看该作者
原帖由 unixer2i 于 2006-1-26 20:38 发表
我就想用python-sidebar来浏览python本地文档,尤其是它的API文档。


你看看解开后的modindex.html和search.html,里面的链接都是在线文档,也就是python官方网站python.org的页面,怎么可能浏览本地文档?除非你自己改一改!

下面是你附件里的出错信息
  1. Traceback (most recent call last):
  2.   File "update.py", line 264, in ?
  3.     build_all(out_dir)
  4.   File "update.py", line 260, in build_all
  5.     p(out_dir)
  6.   File "update.py", line 101, in __init__
  7.     data = self.get_rawdata(self.url)
  8.   File "update.py", line 144, in get_rawdata
  9.     f = urlopen(url)
  10.   File "D:\apptools\Python\lib\urllib2.py", line 130, in urlopen
  11.     return _opener.open(url, data)
  12.   File "D:\apptools\Python\lib\urllib2.py", line 358, in open
  13.     response = self._open(req, data)
  14.   File "D:\apptools\Python\lib\urllib2.py", line 376, in _open
  15.     '_open', req)
  16.   File "D:\apptools\Python\lib\urllib2.py", line 337, in _call_chain
  17.     result = func(*args)
  18.   File "D:\apptools\Python\lib\urllib2.py", line 1021, in http_open
  19.     return self.do_open(httplib.HTTPConnection, req)
  20.   File "D:\apptools\Python\lib\urllib2.py", line 996, in do_open
  21.     raise URLError(err)
  22. urllib2.URLError: <urlopen error (11001, 'getaddrinfo failed')>
复制代码

注意到最后一行没有!你一定是在断网的情况下执行update.py的吧。打开update.py,看看是怎么写的

[ 本帖最后由 wolfg 于 2006-1-26 21:03 编辑 ]

论坛徽章:
0
9 [报告]
发表于 2006-01-27 20:33 |只看该作者

这是python-sidebar中update.py的源代码,



  1. # -*- coding: iso8859-1 -*-
  2. """
  3. @Author: Daniel Lundin <daniel@edgewall.com>
  4. @Contact: daniel@edgewall.com
  5. @Organization: Edgewall Software
  6. @Copyright: Copyright (C) 2004 Edgewall Software. All Rights Reserved.

  7. The Python Sidebar is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License as
  9. published by the Free Software Foundation; either version 2 of the
  10. License, or (at your option) any later version.

  11. The Python Sidebar is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14. General Public License for more details.

  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

  18. Changelog
  19. ---------
  20.   -  1.0.2 (Oct 11, 2004)
  21.      - Scraping the modules index missed modules with comments, like
  22.      windows/mac-only modules.

  23.   -  1.0.1 (Jul 29, 2004)
  24.      - Added target="_content" to all links to make the sidebar work better in
  25.        other browsers. Thanks to Jarkko Laiho for the suggestion and patch.

  26. Todo
  27. ----
  28.   * Wrap sidebar in XUL to make it appear in the panel menu (thanks to Chris
  29.     Green for the idea).

  30. """

  31. __version__ = '1.0.2'

  32. import re
  33. import os.path
  34. import time
  35. from urllib2 import urlopen

  36. html_template = """
  37. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  38.        "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd">
  39. <html>
  40. <head>
  41.   <title>Python Sidebar %(ver)s</title>
  42.    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15" />
  43.    <meta name="author" content="Daniel Lundin &lt;daniel@edgewall.com&gt;" />
  44.    <meta name="description" content="A nifty Python documentation sidebar for Mozilla" />
  45.    <meta name="keywords" content="python sidebar,python,documentation,reference,mozilla,firefox,edgewall,edgewall software" />
  46.    <script type="text/javascript" src="cm.js"></script>
  47.    <style type="text/css">
  48.     @import url(sidebar.css);
  49.    </style>
  50. </head>

  51. <body onload="cm()">
  52. <div id="top">
  53.   <div id="menu">%(menu)s</div>
  54.   <h1>%(title)s</h1>
  55. </div>
  56. <div id="toc">
  57. %(content)s

  58.     <div id="lastmod">
  59.     Last modified:<br />
  60.     %(timestamp)s
  61.     </div>
  62. </div>



  63. <div id="bottom">
  64.   <div id="footer">
  65.     <address>
  66.     <a href="http://www.edgewall.com/">Edgewall Software</a> -
  67.     Expert Linux & Software Development Services.
  68.      <a href="mailto:info@edgewall.com">info@edgewall.com</a>
  69.     </address>
  70.   </div>

  71. <a href="http://www.python.org/"><img src="python.gif" /></a>
  72. </div>

  73. </body></html>
  74. """

  75. class BuildPage:
  76.     url = ''
  77.     title = ''
  78.     menutxt = ''
  79.     outfile = ''

  80.     def __init__(self, out_dir):
  81.         self.outfile = os.path.join(out_dir, self.outfile)
  82.         data = self.get_rawdata(self.url)
  83.         if data is None:
  84.             raise ValueError, 'Error loading data'
  85.         content = self.scrape(data)
  86.         if not content:
  87.             raise ValueError, 'Error scraping data'

  88.         html = self.to_html(content)
  89.         if not html:
  90.             raise ValueError, 'Error creating HTML'
  91.         self.save_html(self.outfile, html)

  92.     def save_html(self, outfile, html):
  93.         f = open(outfile, 'w')
  94.         f.write(html)
  95.         f.close()

  96.     def make_menu(self):
  97.         html = '<ul>'
  98.         for p in all_pages:
  99.             html += '<li><a href="javascript:goSidebar(\'%s\')"' % p.outfile
  100.             html += ' title="%s"' % p.title
  101.             if self.__class__ == p:
  102.                 html += ' class="current"'
  103.             html += ' target="_self">%s</a></li>' % getattr(p, 'menutxt',
  104.                                                                self.title)

  105.         html += '</ul>'
  106.         return html

  107.     def to_html(self, content):
  108.         tmpl = {}
  109.         tmpl['timestamp'] = time.strftime('%c', time.localtime())
  110.         tmpl['title'] = self.title
  111.         tmpl['content'] = content
  112.         tmpl['menu'] = self.make_menu()
  113.         tmpl['ver'] = __version__
  114.         return html_template % tmpl

  115.     def scrape(self, data):
  116.         return data

  117.     def get_rawdata(self, url):
  118.         f = urlopen(url)
  119.         data = f.read()
  120.         f.close()
  121.         return data

  122. class BuildTutorial(BuildPage):
  123.     url = 'http://www.python.org/doc/current/tut/tut.html'
  124.     baseref = 'http://www.python.org/doc/current/tut/'
  125.     outfile = 'toc-tutorial.html'
  126.     title = 'Python Tutorial'
  127.     menutxt = 'tut'

  128.     def scrape(self, data):
  129.         beg = data.find('<UL CLASS="ChildLinks">')
  130.         end = data.find('<!--End of Table of Child-Links-->')
  131.         if beg == -1 or end == -1:
  132.             raise ValueError, 'Unable to scrape data.'
  133.         return data[beg:end].replace('href="','target="_content" href="%s' % self.baseref)

  134. class BuildLibRef(BuildTutorial):
  135.     baseref = 'http://www.python.org/doc/current/lib/'
  136.     url = 'http://www.python.org/doc/current/lib/lib.html'
  137.     outfile = 'toc-libref.html'
  138.     menutxt = 'lib'

  139.     title = 'Python Library Reference'

  140. class BuildLangRef(BuildTutorial):
  141.     baseref = 'http://www.python.org/doc/current/ref/'
  142.     url = 'http://www.python.org/doc/current/ref/ref.html'
  143.     outfile = 'toc-ref.html'
  144.     title = 'Python Language Reference'
  145.     menutxt = 'ref'

  146. class BuildAPIRef(BuildTutorial):
  147.     baseref = 'http://www.python.org/doc/current/api/'
  148.     url = 'http://www.python.org/doc/current/api/api.html'
  149.     outfile = 'toc-api.html'
  150.     title = 'Python/C API Reference'
  151.     menutxt = 'api'

  152. class BuildExtEmb(BuildTutorial):
  153.     baseref = 'http://www.python.org/doc/current/ext/'
  154.     url = 'http://www.python.org/doc/current/ext/ext.html'
  155.     outfile = 'toc-ext.html'
  156.     title = 'Extending and Embedding Python'
  157.     menutxt = 'ext'

  158. class BuildMods(BuildPage):
  159.     baseref = 'http://www.python.org/doc/current/'
  160.     url = 'http://www.python.org/doc/current/modindex.html'
  161.     outfile = 'modindex.html'
  162.     title = 'Module Index'
  163.     menutxt = 'mod'

  164.     def scrape(self, data):
  165.         r = re.compile(r'<dt><a href="(.*)"><tt class="module">(.*)</tt>.*</a>')
  166.         beg = data.find('<dl compact>')
  167.         items = ['<li><a href="%s%s" target="_content">%s</a></li>' % \
  168.                  (self.baseref, m.group(1), m.group(2))
  169.                  for m in re.finditer(r, data)]
  170.         half = len(items) / 2
  171.         html = '<div class="left">%s</div><div class="right">%s</div>' % \
  172.                ('\n'.join(items[:half]), '\n'.join(items[half:]))
  173.         return html

  174. class BuildSearch(BuildPage):
  175.     title = 'Search'
  176.     menutxt = '<img src="search.gif"/>'
  177.     outfile = 'search.html'

  178.     search_html ="""
  179.     <h2>Python Website</h2>
  180.     <form method="get" action="http://www.google.com/search" target="_content">
  181.     <input type="hidden" name="sourceid" value="python-sidebar">
  182. <input name="q" size="30" value="">
  183. <input type="submit" name="submit" value="Search"><br>
  184. <input type="radio" name="q" value="site:python.org" checked="checked">All of python.org
  185. <br />
  186. <input type="radio" name="q" value="site:www.python.org">www.python.org
  187. <br />
  188. <input type="radio" name="q" value="site:mail.python.org">python.org mailling lists
  189. <br />
  190. <input type="radio" name="q" value="site:ftp.python.org">ftp.python.org
  191.     </form>

  192. <h2>Python Newsgroups</h2>
  193. <form action="http://groups.google.com/groups" method="get" target="_content">
  194. <input type="hidden" name="group" value="comp.lang.python.*">
  195. <input type="text" name="q" value="" size="30">
  196. <input type="submit" value="Search">
  197. <a href="http://groups.google.com/advanced_group_search">(advanced
  198. search)</a>

  199. </form>
  200.     """


  201.     def get_rawdata(self, url):
  202.         return ''

  203.     def scrape(self, data):
  204.         return self.search_html


  205. all_pages = [BuildTutorial,
  206.              BuildLangRef,
  207.              BuildLibRef,
  208.              BuildAPIRef,
  209.              BuildExtEmb,
  210.              BuildMods,
  211.              BuildSearch]


  212. def build_all(out_dir):
  213.     for p in all_pages:
  214.         p(out_dir)

  215. if __name__ == '__main__':
  216.     out_dir = './html'
  217.     build_all(out_dir)

复制代码


我应该如何修改才能浏览本地文档呢?我试过modindex.html和search.html,看了下链接,全是在网上直接浏览的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP