From 2efd85952591de5dd8ff0666a82533bcdb7d0d3d Mon Sep 17 00:00:00 2001 From: Tom Mortimer-Jones Date: Tue, 12 Feb 2013 12:26:38 +0000 Subject: [PATCH] Added check so that genspider cannot create a spider with the same name as the project. --- scrapy/commands/genspider.py | 5 +++++ scrapy/tests/test_commands.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/scrapy/commands/genspider.py b/scrapy/commands/genspider.py index 39ee01367..79deb3ffb 100644 --- a/scrapy/commands/genspider.py +++ b/scrapy/commands/genspider.py @@ -56,6 +56,11 @@ class Command(ScrapyCommand): name, domain = args[0:2] module = sanitize_module_name(name) + + if self.settings.get('BOT_NAME') == module: + print "Cannot create a spider with the same name as your project" + return + try: spider = self.crawler.spiders.create(name) except KeyError: diff --git a/scrapy/tests/test_commands.py b/scrapy/tests/test_commands.py index 24fa072cc..205ebe8d1 100644 --- a/scrapy/tests/test_commands.py +++ b/scrapy/tests/test_commands.py @@ -112,6 +112,10 @@ class GenspiderCommandTest(CommandTest): self.assertEqual(0, self.call('genspider', '--dump=basic')) self.assertEqual(0, self.call('genspider', '-d', 'basic')) + def test_same_name_as_project(self): + self.assertEqual(2, self.call('genspider', self.project_name)) + assert not exists(join(self.proj_mod_path, 'spiders', '%s.py' % self.project_name)) + class MiscCommandsTest(CommandTest):