From 75e2c3eb338ea03e487907fa8c99bb12317e9435 Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Tue, 19 Jul 2011 19:39:27 -0300 Subject: [PATCH] moved spider queues to scrapyd --HG-- rename : scrapy/spiderqueue.py => scrapyd/spiderqueue.py rename : scrapy/tests/test_spiderqueue.py => scrapyd/tests/test_spiderqueue.py --- scrapy/interfaces.py | 34 ------------------ scrapy/settings/default_settings.py | 2 -- scrapyd/interfaces.py | 35 +++++++++++++++++++ {scrapy => scrapyd}/spiderqueue.py | 2 +- {scrapy => scrapyd}/tests/test_spiderqueue.py | 4 +-- scrapyd/utils.py | 2 +- 6 files changed, 39 insertions(+), 40 deletions(-) rename {scrapy => scrapyd}/spiderqueue.py (94%) rename {scrapy => scrapyd}/tests/test_spiderqueue.py (95%) diff --git a/scrapy/interfaces.py b/scrapy/interfaces.py index 43d373359..a5442a40d 100644 --- a/scrapy/interfaces.py +++ b/scrapy/interfaces.py @@ -1,39 +1,5 @@ from zope.interface import Interface -class ISpiderQueue(Interface): - - def from_settings(settings): - """Class method to instantiate from settings""" - - def add(name, **spider_args): - """Add a spider to the queue given its name a some spider arguments. - - This method can return a deferred. """ - - def pop(): - """Pop the next mesasge from the queue. The messages is a dict - conaining a key 'name' with the spider name and other keys as spider - attributes. - - This method can return a deferred. """ - - def list(): - """Return a list with the messages in the queue. Each message is a dict - which must have a 'name' key (with the spider name), and other optional - keys that will be used as spider arguments, to create the spider. - - This method can return a deferred. """ - - def count(): - """Return the number of spiders in the queue. - - This method can return a deferred. """ - - def clear(): - """Clear the queue. - - This method can return a deferred. """ - class ISpiderManager(Interface): def from_settings(settings): diff --git a/scrapy/settings/default_settings.py b/scrapy/settings/default_settings.py index 6aec8827f..9eb8eb03b 100644 --- a/scrapy/settings/default_settings.py +++ b/scrapy/settings/default_settings.py @@ -237,8 +237,6 @@ SPIDER_MIDDLEWARES_BASE = { SPIDER_MODULES = [] -SPIDER_QUEUE_CLASS = 'scrapy.spiderqueue.SqliteSpiderQueue' - SPIDER_CONTEXT_ENABLED = True SPIDER_CONTEXT_STORAGE_CLASS = 'scrapy.contrib.spidercontext.SqliteSpiderContextStorage' diff --git a/scrapyd/interfaces.py b/scrapyd/interfaces.py index 1e9514269..018da5d08 100644 --- a/scrapyd/interfaces.py +++ b/scrapyd/interfaces.py @@ -47,6 +47,41 @@ class IPoller(Interface): projects""" +class ISpiderQueue(Interface): + + def from_settings(settings): + """Class method to instantiate from settings""" + + def add(name, **spider_args): + """Add a spider to the queue given its name a some spider arguments. + + This method can return a deferred. """ + + def pop(): + """Pop the next mesasge from the queue. The messages is a dict + conaining a key 'name' with the spider name and other keys as spider + attributes. + + This method can return a deferred. """ + + def list(): + """Return a list with the messages in the queue. Each message is a dict + which must have a 'name' key (with the spider name), and other optional + keys that will be used as spider arguments, to create the spider. + + This method can return a deferred. """ + + def count(): + """Return the number of spiders in the queue. + + This method can return a deferred. """ + + def clear(): + """Clear the queue. + + This method can return a deferred. """ + + class ISpiderScheduler(Interface): """A component to schedule spider runs""" diff --git a/scrapy/spiderqueue.py b/scrapyd/spiderqueue.py similarity index 94% rename from scrapy/spiderqueue.py rename to scrapyd/spiderqueue.py index e19d10fc9..4f3000b84 100644 --- a/scrapy/spiderqueue.py +++ b/scrapyd/spiderqueue.py @@ -1,6 +1,6 @@ from zope.interface import implements -from scrapy.interfaces import ISpiderQueue +from scrapyd.interfaces import ISpiderQueue from scrapy.utils.sqlite import JsonSqlitePriorityQueue from scrapy.utils.project import sqlite_db diff --git a/scrapy/tests/test_spiderqueue.py b/scrapyd/tests/test_spiderqueue.py similarity index 95% rename from scrapy/tests/test_spiderqueue.py rename to scrapyd/tests/test_spiderqueue.py index 574211bae..8a400a0e9 100644 --- a/scrapy/tests/test_spiderqueue.py +++ b/scrapyd/tests/test_spiderqueue.py @@ -3,8 +3,8 @@ from twisted.trial import unittest from zope.interface.verify import verifyObject -from scrapy.interfaces import ISpiderQueue -from scrapy.spiderqueue import SqliteSpiderQueue +from scrapyd.interfaces import ISpiderQueue +from scrapyd.spiderqueue import SqliteSpiderQueue class SpiderQueueTest(unittest.TestCase): """This test case can be used easily for testing other SpiderQueue's by diff --git a/scrapyd/utils.py b/scrapyd/utils.py index c100d9833..e18226072 100644 --- a/scrapyd/utils.py +++ b/scrapyd/utils.py @@ -3,7 +3,7 @@ import os from subprocess import Popen, PIPE from ConfigParser import NoSectionError -from scrapy.spiderqueue import SqliteSpiderQueue +from scrapyd.spiderqueue import SqliteSpiderQueue from scrapy.utils.python import stringify_dict, unicode_to_str from scrapyd.config import Config