⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gui.py

📁 Harvestman-最新版本
💻 PY
📖 第 1 页 / 共 2 页
字号:
"""gui.py - Module which provides a browser based UImode to HarvestMan using web.py. This module is partof the HarvestMan program.Created Anand B Pillai <abpillai at gmail dot com> Jun 01 2008Copyright (C) 2008, Anand B Pillai."""import sys, osimport webimport webbrowserimport timefrom web import form, net, requestdef get_templates_location():    # Templates are located at harvestman/ui/templates folder...    top = os.path.dirname(os.path.dirname(os.path.abspath(globals()['__file__'])))    template_dir = os.path.join(top, 'ui','templates')    return template_dir# Global render objectg_render = web.template.render(get_templates_location())PLUG_TEMPLATE="""\       <plugin name="%s" enable="1" />"""PLUGINS_TEMPLATE="""\    <plugins>        %s    </plugins>"""CONFIG_XML_TEMPLATE="""\<?xml version="1.0" encoding="utf-8"?><HarvestMan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"            xsi:schemaLocation="http://harvestmanontheweb.com/schemas/HarvestMan.xsd">   <!--- Configuration file generated by HarvestMan Config Generator %(TIMESTAMP)s -->   <config version="3.0" xmlversion="1.0">     <projects>            <project skip="0">        <url>%(url)s</url>        <name>%(projname)s</name>        <basedir>%(basedir)s</basedir>        <verbosity value="%(verbosity)s"/>      </project>           </projects>     <network>      <proxy>        <proxyserver>%(proxy)s</proxyserver>        <proxyuser>%(puser)s</proxyuser>        <proxypasswd>%(ppasswd)s</proxypasswd>        <proxyport value="%(proxyport)s"/>      </proxy>    </network>        <download>      <types>        <html value="%(html)s"/>        <images value="%(images)s"/>        <movies value="%(movies)s"/>        <flash value="%(flash)s"/>                <sounds value="%(sounds)s"/>        <documents value="%(documents)s"/>                <javascript value="%(javascript)s"/>        <javaapplet value="%(javaapplet)s"/>        <querylinks value="%(getquerylinks)s"/>      </types>       <cache status="%(pagecache)s">        <datacache value="%(datacache)s"/>      </cache>      <protocol>        <http compress="%(httpcompress)s" />      </protocol>      <misc>        <retries value="%(retryfailed)s"/>      </misc>    </download>        <control>      <links>        <imagelinks value="%(getimagelinks)s" />        <stylesheetlinks value="%(getstylesheets)s"/>        <offset start="%(linksoffsetstart)s" end="%(linksoffsetend)s" />      </links>      <extent>        <fetchlevel value="%(fetchlevel)s"/>        <depth value="%(depth)s"/>        <extdepth value="%(extdepth)s"/>        <subdomain value="%(subdomain)s"/>        <ignoretlds value="%(ignoretlds)s"/>      </extent>      <limits>        <maxfiles value="%(maxfiles)s"/>        <maxfilesize value="%(maxfilesize)s"/>        <maxbandwidth value="%(maxbandwidth)s"/>        <connections value="%(connections)s"/>        <timelimit value="%(timelimit)s"/>      </limits>      <rules>        <robots value="%(robots)s"/>        <urlpriority>%(urlpriority)s</urlpriority>        <serverpriority>%(serverpriority)s</serverpriority>      </rules>      <filters>        <urlfilter>%(urlfilter)s</urlfilter>        <serverfilter>%(serverfilter)s</serverfilter>        <wordfilter>%(wordfilter)s</wordfilter>        <junkfilter value="%(junkfilter)s"/>      </filters>      %(PLUGIN)s    </control>    <parser>      <feature name="a" enable="%(parser_enable_a)s" />      <feature name="base" enable="%(parser_enable_base)s" />      <feature name="frame" enable="%(parser_enable_frame)s" />      <feature name="img" enable="%(parser_enable_img)s" />      <feature name="form" enable="%(parser_enable_form)s" />      <feature name="link" enable="%(parser_enable_link)s" />      <feature name="body" enable="%(parser_enable_body)s" />      <feature name="script" enable="%(parser_enable_script)s" />      <feature name="applet" enable="%(parser_enable_applet)s" />      <feature name="area" enable="%(parser_enable_area)s" />      <feature name="meta" enable="%(parser_enable_meta)s" />      <feature name="embed" enable="%(parser_enable_embed)s" />      <feature name="object" enable="%(parser_enable_object)s" />      <feature name="option" enable="%(parser_enable_option)s" />    </parser>          <system>      <workers status="%(usethreads)s" size="%(threadpoolsize)s" timeout="%(timeout)s"/>      <trackers value="%(maxtrackers)s" timeout="%(fetchertimeout)s" />      <timegap value="%(sleeptime)s" random="%(randomsleep)s" />    </system>        <files>      <urltreefile>%(urltreefile)s</urltreefile>      <archive status="%(archive)s" format="%(archformat)s"/>      <urlheaders status="%(urlheaders)s" />      <localise value="%(localise)s"/>    </files>        <display>      <browsepage value="%(browsepage)s"/>    </display>      </config>  </HarvestMan>"""def render_stylesheet():    css = """\    <style>    body {           font-family: Arial;           font-size: 12px;         }    form th {           text-align: right;           vertical-align:top;         }    .description {       font-style: italic;     }    .help {       font-style: italic;       font-size: 12px;       color: #343434;     }    </style>    """    return cssdef render_tabs():    content ="""\    <html><head><title>HarvestMan Web Console</title>    <head>    <script type="text/javascript" src="content/tabberjs"></script>    <link rel="stylesheet" href="content/example_css" TYPE="text/css" MEDIA="screen">    <link rel="stylesheet" href="content/example_print_css" TYPE="text/css" MEDIA="print">    <script type="text/javascript">    /* Optional: Temporarily hide the "tabber" class so it does not "flash"       on the page as plain HTML. After tabber runs, the class is changed       to "tabberlive" and it will appear. */       document.write('<style type="text/css">.tabber{display:none;}<\/style>');     </script>     </head>    <body>    <h1>HarvestMan Web Console</h1>    <div class="tabber">     <div class="tabbertab">          <h2>Settings</h2>          <p>Settings stuff goes here</p>     </div>     <div class="tabbertab">          <h2>Crawls(Projects)</h2>          <p>Projects stuff goes here</p>     </div>     <div class="tabbertab">          <h2>Files</h2>          <p>Files stuff goes here</p>     </div>     <div class="tabbertab">          <h2>Documentation</h2>          <p>Documentation goes here</p>     </div>          <div class="tabbertab">          <h2>About</h2>          <p>HarvestMan - Web crawling application/framework written in pure Python.</p>          <p>WWW: <a href="http://www.harvestmanontheweb.com">HarvestMan on the Web</a></p>     </div>         </div>    </body>    </html>    """    return content                  ############## Start web.py custom widgets ####################################################      class SizedTextbox(form.Textbox):    """ A GUI class for a textbox which accepts an argument for    its size """        def __init__(self, name, size, title='', *validators, **attrs):        super(SizedTextbox, self).__init__(name, *validators, **attrs)        self.size = size        self.val = self.value        self.title = title            def render(self):        x = '<input type="text" name="%s" size="%d" title="%s"' % (net.websafe(self.name),                                                                   self.size,                                                                   net.websafe(self.title))        if self.val !=None: x += ' value="%s"' % net.websafe(self.val)        x += self.addatts()        x += ' />'        return xclass MyDropbox(form.Dropdown):    """ A modified Dropdown class """        def __init__(self, name, title='', args=None, *validators, **attrs):        super(MyDropbox, self).__init__(name, args, *validators, **attrs)        self.val = self.value        self.title = title    def render(self):        x = '<select name="%s"%s title="%s">\n' % (net.websafe(self.name),                                                   self.addatts(),                                                   net.websafe(self.title))        for arg in self.args:            if type(arg) == tuple:                value, desc= arg            else:                value, desc = arg, arg             if self.val == value: select_p = 'selected'            else: select_p = ''            x += '  <option %s>%s</option>\n' % (select_p, net.websafe(desc))        x += '</select>\n'        return x        class Label(form.Input):    """ A class which provides a Label widget """        def __init__(self, text,bold=False,italic=False,underlined=False, *validators, **attrs):        self.name = ''        self.text = text        self.bold = bold        self.italic = italic        self.underlined = underlined        super(Label, self).__init__('', *validators, **attrs)            def render(self):        text = '<p>%s</p>' % self.text        if self.bold:            text = '<b>%s</b>' % text        if self.italic:            text = '<i>%s</i>' % text        if self.underlined:            text = '<u>%s</u>' % text        return text    def validate(self, v):        return True############## End web.py custom widgets ####################################################

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -