mirror of https://github.com/scrapy/scrapy.git
Amend "settings" command to output JSON for dict settings
This commit is contained in:
parent
aa78758bc7
commit
d843a0aae8
|
|
@ -1,5 +1,8 @@
|
|||
from __future__ import print_function
|
||||
import json
|
||||
|
||||
from scrapy.commands import ScrapyCommand
|
||||
from scrapy.settings import BaseSettings
|
||||
|
||||
class Command(ScrapyCommand):
|
||||
|
||||
|
|
@ -28,7 +31,11 @@ class Command(ScrapyCommand):
|
|||
def run(self, args, opts):
|
||||
settings = self.crawler_process.settings
|
||||
if opts.get:
|
||||
print(settings.get(opts.get))
|
||||
s = settings.get(opts.get)
|
||||
if isinstance(s, BaseSettings):
|
||||
print(json.dumps(s.copy_to_dict()))
|
||||
else:
|
||||
print(s)
|
||||
elif opts.getbool:
|
||||
print(settings.getbool(opts.getbool))
|
||||
elif opts.getint:
|
||||
|
|
|
|||
|
|
@ -68,4 +68,4 @@ class CmdlineTest(unittest.TestCase):
|
|||
settingsstr = settingsstr.replace(char, '"')
|
||||
settingsdict = json.loads(settingsstr)
|
||||
six.assertCountEqual(self, settingsdict.keys(), EXTENSIONS.keys())
|
||||
self.assertIn('value=200', settingsdict[EXT_PATH])
|
||||
self.assertEquals(200, settingsdict[EXT_PATH])
|
||||
|
|
|
|||
Loading…
Reference in New Issue