Skip to content

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

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

Pablo Hoffman58e88ed2466b
diff --git a/docs/topics/scrapyd.rst b/docs/topics/scrapyd.rst
index 0fe2aa3a6..1a8519c71 100644
--- a/docs/topics/scrapyd.rst
+++ b/docs/topics/scrapyd.rst
@@ -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
---------
diff --git a/scrapyd/environ.py b/scrapyd/environ.py
index 10711d88f..cc52563c7 100644
--- a/scrapyd/environ.py
+++ b/scrapyd/environ.py
@@ -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):
diff --git a/scrapyd/tests/test_environ.py b/scrapyd/tests/test_environ.py
index c88b80fe5..25d81c0b0 100644
--- a/scrapyd/tests/test_environ.py
+++ b/scrapyd/tests/test_environ.py
@@ -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)