scrapyd: do not set SCRAPY_FEED_URI/SCRAPY_LOG_FILE if items_dir/logs_dir settings are not set

This commit is contained in:
Pablo Hoffman 2012-05-08 17:43:00 -03:00
parent 43732e5042
commit 58e88ed246
3 changed files with 19 additions and 3 deletions

View File

@ -192,7 +192,10 @@ spider queues).
logs_dir
--------
The directory where the Scrapy processes logs will be stored.
The directory where the Scrapy logs will be stored. If you want to disable
storing logs set this option empty, like this::
logs_dir =
items_dir
---------

View File

@ -28,8 +28,10 @@ class Environment(object):
env['SCRAPY_JOB'] = message['_job']
if project in self.settings:
env['SCRAPY_SETTINGS_MODULE'] = self.settings[project]
env['SCRAPY_LOG_FILE'] = self._get_file(message, self.logs_dir, 'log')
env['SCRAPY_FEED_URI'] = self._get_file(message, self.items_dir, 'jl')
if self.logs_dir:
env['SCRAPY_LOG_FILE'] = self._get_file(message, self.logs_dir, 'log')
if self.items_dir:
env['SCRAPY_FEED_URI'] = self._get_file(message, self.items_dir, 'jl')
return env
def _get_file(self, message, dir, ext):

View File

@ -32,3 +32,14 @@ class EnvironmentTest(unittest.TestCase):
self.assert_(env['SCRAPY_LOG_FILE'].endswith(os.path.join('mybot', 'myspider', 'ID.log')))
self.assert_(env['SCRAPY_FEED_URI'].endswith(os.path.join('mybot', 'myspider', 'ID.jl')))
self.failIf('SCRAPY_SETTINGS_MODULE' in env)
def test_get_environment_with_no_items_dir(self):
config = Config(values={'items_dir': '', 'logs_dir': ''})
config.cp.add_section('settings')
config.cp.set('settings', 'newbot', 'newbot.settings')
msg = {'_project': 'mybot', '_spider': 'myspider', '_job': 'ID'}
slot = 3
environ = Environment(config, initenv={})
env = environ.get_environment(msg, slot)
self.failUnless('SCRAPY_FEED_URI' not in env)
self.failUnless('SCRAPY_LOG_FILE' not in env)