mirror of https://github.com/scrapy/scrapy.git
Default per-command settings are now specified in the default_settings attribute of the command object. Closes #201
This commit is contained in:
parent
76e19baa29
commit
a71521bfba
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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>"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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]"
|
||||
|
|
|
|||
|
|
@ -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]"
|
||||
|
|
|
|||
|
|
@ -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>"
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
LOG_ENABLED = False
|
||||
|
|
@ -1 +0,0 @@
|
|||
LOG_ENABLED = False
|
||||
|
|
@ -1 +0,0 @@
|
|||
LOG_ENABLED = False
|
||||
|
|
@ -1 +0,0 @@
|
|||
LOG_ENABLED = False
|
||||
|
|
@ -1 +0,0 @@
|
|||
LOG_LEVEL='WARNING'
|
||||
|
|
@ -1 +0,0 @@
|
|||
LOG_ENABLED = False
|
||||
|
|
@ -22,7 +22,6 @@ CLOSESPIDER_TIMEOUT = 0
|
|||
CLOSESPIDER_ITEMPASSED = 0
|
||||
|
||||
COMMANDS_MODULE = ''
|
||||
COMMANDS_SETTINGS_MODULE = ''
|
||||
|
||||
CONCURRENT_ITEMS = 100
|
||||
CONCURRENT_REQUESTS_PER_SPIDER = 8
|
||||
|
|
|
|||
Loading…
Reference in New Issue