From 9cd649b3a04e5eed2acaca9af17d735de55adee7 Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Sun, 26 Dec 2010 19:32:56 -0200 Subject: [PATCH] scrapyd: populate SCRAPY_SPIDER and SCRAPY_JOB environment variables --- scrapyd/environ.py | 2 ++ scrapyd/tests/test_environ.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/scrapyd/environ.py b/scrapyd/environ.py index a41e6abb9..5854bcd02 100644 --- a/scrapyd/environ.py +++ b/scrapyd/environ.py @@ -23,6 +23,8 @@ class Environment(object): env = self.initenv.copy() env['SCRAPY_SLOT'] = str(slot) env['SCRAPY_PROJECT'] = project + env['SCRAPY_SPIDER'] = message['_spider'] + env['SCRAPY_JOB'] = message['_job'] if eggpath: env['SCRAPY_EGGFILE'] = eggpath elif project in self.settings: diff --git a/scrapyd/tests/test_environ.py b/scrapyd/tests/test_environ.py index 09cac50ae..172c28543 100644 --- a/scrapyd/tests/test_environ.py +++ b/scrapyd/tests/test_environ.py @@ -27,6 +27,8 @@ class EggStorageTest(unittest.TestCase): env = self.environ.get_environment(msg, slot, '/path/to/file.egg') self.assertEqual(env['SCRAPY_PROJECT'], 'mybot') self.assertEqual(env['SCRAPY_SLOT'], '3') + self.assertEqual(env['SCRAPY_SPIDER'], 'myspider') + self.assertEqual(env['SCRAPY_JOB'], 'ID') self.assert_(env['SCRAPY_SQLITE_DB'].endswith('mybot.db')) self.assert_(env['SCRAPY_LOG_FILE'].endswith('/mybot/myspider/ID.log')) self.assert_(env['SCRAPY_EGGFILE'].endswith('/path/to/file.egg')) @@ -38,6 +40,8 @@ class EggStorageTest(unittest.TestCase): env = self.environ.get_environment(msg, slot, None) self.assertEqual(env['SCRAPY_PROJECT'], 'newbot') self.assertEqual(env['SCRAPY_SLOT'], '3') + self.assertEqual(env['SCRAPY_SPIDER'], 'myspider') + self.assertEqual(env['SCRAPY_JOB'], 'ID') self.assert_(env['SCRAPY_SQLITE_DB'].endswith('newbot.db')) self.assert_(env['SCRAPY_LOG_FILE'].endswith('/newbot/myspider/ID.log')) self.assertEqual(env['SCRAPY_SETTINGS_MODULE'], 'newbot.settings')