mirror of https://github.com/scrapy/scrapy.git
Some changes to telnet console:
* moved module from scrapy.management.telnet to scrapy.telnet (to minimize nested modules) * added signal for updating telnet console variables (fixes #165) --HG-- rename : scrapy/management/telnet.py => scrapy/telnet.py
This commit is contained in:
parent
4595c92cc2
commit
38b5793152
|
|
@ -31,13 +31,13 @@ the console you need to type::
|
|||
You need the telnet program which comes installed by default in Windows, and
|
||||
most Linux distros.
|
||||
|
||||
Available aliases in the telnet console
|
||||
=======================================
|
||||
Available variables in the telnet console
|
||||
=========================================
|
||||
|
||||
The telnet console is like a regular Python shell running inside the Scrapy
|
||||
process, so you can do anything from it including imports, etc.
|
||||
process, so you can do anything from it including importing new modules, etc.
|
||||
|
||||
However, the telnet console comes with some default shortcuts defined for
|
||||
However, the telnet console comes with some default variables defined for
|
||||
convenience:
|
||||
|
||||
+----------------+-------------------------------------------------------------------+
|
||||
|
|
@ -126,3 +126,17 @@ To stop::
|
|||
>>> engine.stop()
|
||||
Connection closed by foreign host.
|
||||
|
||||
Telnet Console signals
|
||||
======================
|
||||
|
||||
.. signal:: update_telnet_vars
|
||||
.. function:: update_telnet_vars(telnet_vars)
|
||||
|
||||
Sent just before the telnet console is opened. You can hook up to this
|
||||
signal to add, remove or update the variables that will be available in the
|
||||
telnet local namespace. In order to do that, you need to update the
|
||||
``telnet_vars`` dict in your handler.
|
||||
|
||||
:param telnet_vars: the dict of telnet variables
|
||||
:type telnet_vars: dict
|
||||
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ EXTENSIONS = {}
|
|||
EXTENSIONS_BASE = {
|
||||
'scrapy.contrib.corestats.CoreStats': 0,
|
||||
'scrapy.management.web.WebConsole': 0,
|
||||
'scrapy.management.telnet.TelnetConsole': 0,
|
||||
'scrapy.telnet.TelnetConsole': 0,
|
||||
'scrapy.contrib.webconsole.scheduler.SchedulerQueue': 0,
|
||||
'scrapy.contrib.webconsole.livestats.LiveStats': 0,
|
||||
'scrapy.contrib.webconsole.spiderctl.Spiderctl': 0,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ from scrapy.core.exceptions import NotConfigured
|
|||
from scrapy.core.manager import scrapymanager
|
||||
from scrapy.spider import spiders
|
||||
from scrapy.stats import stats
|
||||
from scrapy.utils.signal import send_catch_log
|
||||
from scrapy.utils.trackref import print_live_refs
|
||||
from scrapy.utils.engine import print_engine_status
|
||||
from scrapy.conf import settings
|
||||
|
|
@ -25,30 +26,38 @@ try:
|
|||
except ImportError:
|
||||
hpy = None
|
||||
|
||||
# if you add entries here also update topics/telnetconsole.rst
|
||||
telnet_namespace = {
|
||||
'engine': scrapymanager.engine,
|
||||
'manager': scrapymanager,
|
||||
'extensions': extensions,
|
||||
'stats': stats,
|
||||
'spiders': spiders,
|
||||
'settings': settings,
|
||||
'est': print_engine_status,
|
||||
'p': pprint.pprint,
|
||||
'prefs': print_live_refs,
|
||||
'hpy': hpy,
|
||||
}
|
||||
# signal to update telnet variables
|
||||
# args: telnet_vars
|
||||
update_telnet_vars = object()
|
||||
|
||||
def makeProtocol():
|
||||
return telnet.TelnetTransport(telnet.TelnetBootstrapProtocol,
|
||||
insults.ServerProtocol, manhole.Manhole, telnet_namespace)
|
||||
|
||||
class TelnetConsole(protocol.ServerFactory):
|
||||
|
||||
def __init__(self):
|
||||
if not settings.getbool('TELNETCONSOLE_ENABLED'):
|
||||
raise NotConfigured
|
||||
self.protocol = makeProtocol
|
||||
self.noisy = False
|
||||
port = settings.getint('TELNETCONSOLE_PORT')
|
||||
reactor.callWhenRunning(reactor.listenTCP, port, self)
|
||||
|
||||
def protocol(self):
|
||||
telnet_vars = self._get_telnet_vars()
|
||||
return telnet.TelnetTransport(telnet.TelnetBootstrapProtocol,
|
||||
insults.ServerProtocol, manhole.Manhole, telnet_vars)
|
||||
|
||||
def _get_telnet_vars(self):
|
||||
# Note: if you add entries here also update topics/telnetconsole.rst
|
||||
telnet_vars = {
|
||||
'engine': scrapymanager.engine,
|
||||
'manager': scrapymanager,
|
||||
'extensions': extensions,
|
||||
'stats': stats,
|
||||
'spiders': spiders,
|
||||
'settings': settings,
|
||||
'est': print_engine_status,
|
||||
'p': pprint.pprint,
|
||||
'prefs': print_live_refs,
|
||||
'hpy': hpy,
|
||||
}
|
||||
send_catch_log(update_telnet_vars, telnet_vars=telnet_vars)
|
||||
return telnet_vars
|
||||
Loading…
Reference in New Issue