Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Default per-command settings are now specified in the default_settings attribute of the command object. Closes #201

Pablo Hoffmana71521bfba93
diff --git a/docs/topics/settings.rst b/docs/topics/settings.rst
index a7e957450..17c2a1140 100644
--- a/docs/topics/settings.rst
+++ b/docs/topics/settings.rst
@@ -91,11 +91,8 @@ It's where most of your custom settings will be populated.
-------------------------------
Each :doc:`/topics/scrapy-ctl` command can have its own default settings, which
-override the global default settings. Those custom command settings are located
-inside the ``scrapy.conf.commands`` module, or you can specify custom settings
-to override per-comand inside your project, by writing them in the module
-referenced by the :setting:`COMMANDS_SETTINGS_MODULE` setting. Those settings
-will take more
+override the global default settings. Those custom command settings are
+specified in the ``default_settings`` attribute of the command class.
5. Default global settings
--------------------------
@@ -254,19 +251,6 @@ Example::
COMMANDS_MODULE = 'mybot.commands'
-.. setting:: COMMANDS_SETTINGS_MODULE
-
-COMMANDS_SETTINGS_MODULE
-------------------------
-
-Default: ``''`` (empty string)
-
-A module to use for looking for custom Scrapy command settings.
-
-Example::
-
- COMMANDS_SETTINGS_MODULE = 'mybot.conf.commands'
-
.. setting:: CONCURRENT_ITEMS
CONCURRENT_ITEMS
diff --git a/scrapy/cmdline.py b/scrapy/cmdline.py
index 10179cef2..7ebce7bfc 100644
--- a/scrapy/cmdline.py
+++ b/scrapy/cmdline.py
@@ -68,18 +68,6 @@ def _print_usage(inside_project):
print " %s" % cmdclass.short_desc()
print
-def _update_default_settings(module, cmdname):
- if not module:
- return
- try:
- mod = __import__('%s.%s' % (module, cmdname), {}, {}, [''])
- except ImportError:
- return
- settingsdict = vars(mod)
- for k, v in settingsdict.iteritems():
- if not k.startswith("_"):
- settings.defaults[k] = v
-
def execute(argv=None):
if argv is None:
argv = sys.argv
@@ -87,8 +75,6 @@ def execute(argv=None):
cmds = _get_commands_dict()
cmdname = _get_command_name(argv)
- _update_default_settings('scrapy.conf.commands', cmdname)
- _update_default_settings(settings['COMMANDS_SETTINGS_MODULE'], cmdname)
parser = optparse.OptionParser(formatter=optparse.TitledHelpFormatter(), \
conflict_handler='resolve', add_help_option=False)
@@ -120,6 +106,7 @@ def execute(argv=None):
print 'Use "scrapy-ctl.py -h" for help'
sys.exit(2)
+ settings.defaults.update(cmd.default_settings)
del args[0] # remove command name from args
send_catch_log(signal=command_executed, cmdname=cmdname, cmdobj=cmd, \
args=args, opts=opts)
diff --git a/scrapy/command.py b/scrapy/command.py
index 591717276..ab357c08f 100644
--- a/scrapy/command.py
+++ b/scrapy/command.py
@@ -15,6 +15,9 @@ class ScrapyCommand(object):
requires_project = False
+ # default settings to be used for this command instead of global defaults
+ default_settings = {}
+
def syntax(self):
"""
Command syntax (preferably one-line). Do not include command name.
diff --git a/scrapy/commands/genspider.py b/scrapy/commands/genspider.py
index 2289fee1a..685541fa0 100644
--- a/scrapy/commands/genspider.py
+++ b/scrapy/commands/genspider.py
@@ -27,6 +27,7 @@ def sanitize_module_name(module_name):
class Command(ScrapyCommand):
requires_project = True
+ default_settings = {'LOG_ENABLED': False}
def syntax(self):
return "[options] <name> <domain>"
diff --git a/scrapy/commands/list.py b/scrapy/commands/list.py
index e1c4f440f..228874803 100644
--- a/scrapy/commands/list.py
+++ b/scrapy/commands/list.py
@@ -4,6 +4,7 @@ from scrapy.spider import spiders
class Command(ScrapyCommand):
requires_project = True
+ default_settings = {'LOG_ENABLED': False}
def short_desc(self):
return "List available spiders"
diff --git a/scrapy/commands/settings.py b/scrapy/commands/settings.py
index 43dd836cb..6861e1b3f 100644
--- a/scrapy/commands/settings.py
+++ b/scrapy/commands/settings.py
@@ -4,6 +4,7 @@ from scrapy.conf import settings as settings_
class Command(ScrapyCommand):
requires_project = False
+ default_settings = {'LOG_ENABLED': False}
def syntax(self):
return "[options]"
diff --git a/scrapy/commands/shell.py b/scrapy/commands/shell.py
index 364821a18..2d62e2e72 100644
--- a/scrapy/commands/shell.py
+++ b/scrapy/commands/shell.py
@@ -10,6 +10,7 @@ from scrapy.shell import Shell
class Command(ScrapyCommand):
requires_project = False
+ default_settings = {'LOG_LEVEL': 'WARNING'}
def syntax(self):
return "[url|file]"
diff --git a/scrapy/commands/startproject.py b/scrapy/commands/startproject.py
index 690b0b048..eac906138 100644
--- a/scrapy/commands/startproject.py
+++ b/scrapy/commands/startproject.py
@@ -24,6 +24,7 @@ IGNORE = ignore_patterns('*.pyc', '.svn')
class Command(ScrapyCommand):
requires_project = False
+ default_settings = {'LOG_ENABLED': False}
def syntax(self):
return "<project_name>"
diff --git a/scrapy/conf/commands/__init__.py b/scrapy/conf/commands/__init__.py
deleted file mode 100644
index e69de29bb..000000000
diff --git a/scrapy/conf/commands/genspider.py b/scrapy/conf/commands/genspider.py
deleted file mode 100644
index bcee80b55..000000000
--- a/scrapy/conf/commands/genspider.py
+++ /dev/null
@@ -1 +0,0 @@
-LOG_ENABLED = False
diff --git a/scrapy/conf/commands/help.py b/scrapy/conf/commands/help.py
deleted file mode 100644
index bcee80b55..000000000
--- a/scrapy/conf/commands/help.py
+++ /dev/null
@@ -1 +0,0 @@
-LOG_ENABLED = False
diff --git a/scrapy/conf/commands/list.py b/scrapy/conf/commands/list.py
deleted file mode 100644
index bcee80b55..000000000
--- a/scrapy/conf/commands/list.py
+++ /dev/null
@@ -1 +0,0 @@
-LOG_ENABLED = False
diff --git a/scrapy/conf/commands/settings.py b/scrapy/conf/commands/settings.py
deleted file mode 100644
index bcee80b55..000000000
--- a/scrapy/conf/commands/settings.py
+++ /dev/null
@@ -1 +0,0 @@
-LOG_ENABLED = False
diff --git a/scrapy/conf/commands/shell.py b/scrapy/conf/commands/shell.py
deleted file mode 100644
index 984173aae..000000000
--- a/scrapy/conf/commands/shell.py
+++ /dev/null
@@ -1 +0,0 @@
-LOG_LEVEL='WARNING'
diff --git a/scrapy/conf/commands/startproject.py b/scrapy/conf/commands/startproject.py
deleted file mode 100644
index bcee80b55..000000000
--- a/scrapy/conf/commands/startproject.py
+++ /dev/null
@@ -1 +0,0 @@
-LOG_ENABLED = False
diff --git a/scrapy/conf/default_settings.py b/scrapy/conf/default_settings.py
index 21720903d..5e7e4ed82 100644
--- a/scrapy/conf/default_settings.py
+++ b/scrapy/conf/default_settings.py
@@ -22,7 +22,6 @@ CLOSESPIDER_TIMEOUT = 0
CLOSESPIDER_ITEMPASSED = 0
COMMANDS_MODULE = ''
-COMMANDS_SETTINGS_MODULE = ''
CONCURRENT_ITEMS = 100
CONCURRENT_REQUESTS_PER_SPIDER = 8