Scrapy, a fast high-level web crawling & scraping framework for Python.
add project name validation
Nuno Maximiano08224c92f4b1
diff --git a/scrapy/commands/startproject.py b/scrapy/commands/startproject.pyindex c266f75c4..a6d200607 100644--- a/scrapy/commands/startproject.py+++ b/scrapy/commands/startproject.py@@ -43,18 +43,22 @@ class Command(ScrapyCommand):elif exists(project_name):print("Error: directory %r already exists" % project_name)sys.exit(1)-- moduletpl = join(TEMPLATES_PATH, 'module')- copytree(moduletpl, join(project_name, project_name), ignore=IGNORE)- shutil.copy(join(TEMPLATES_PATH, 'scrapy.cfg'), project_name)- for paths in TEMPLATES_TO_RENDER:- path = join(*paths)- tplfile = join(project_name,- string.Template(path).substitute(project_name=project_name))- render_templatefile(tplfile, project_name=project_name,- ProjectName=string_camelcase(project_name))- print("New Scrapy project %r created in:" % project_name)- print(" %s\n" % abspath(project_name))- print("You can start your first spider with:")- print(" cd %s" % project_name)- print(" scrapy genspider example example.com")+ try:+ __import__(project_name, [], 0)+ print('Error: Project name can\'t be %r, choose another project name' % project_name)+ sys.exit(1)+ except ImportError:+ moduletpl = join(TEMPLATES_PATH, 'module')+ copytree(moduletpl, join(project_name, project_name), ignore=IGNORE)+ shutil.copy(join(TEMPLATES_PATH, 'scrapy.cfg'), project_name)+ for paths in TEMPLATES_TO_RENDER:+ path = join(*paths)+ tplfile = join(project_name,+ string.Template(path).substitute(project_name=project_name))+ render_templatefile(tplfile, project_name=project_name,+ ProjectName=string_camelcase(project_name))+ print("New Scrapy project %r created in:" % project_name)+ print(" %s\n" % abspath(project_name))+ print("You can start your first spider with:")+ print(" cd %s" % project_name)+ print(" scrapy genspider example example.com")diff --git a/tests/test_commands.py b/tests/test_commands.pyindex f7710f03b..eefda833e 100644--- a/tests/test_commands.py+++ b/tests/test_commands.py@@ -64,6 +64,7 @@ class StartprojectTest(ProjectTest):self.assertEqual(1, self.call('startproject', self.project_name))self.assertEqual(1, self.call('startproject', 'wrong---project---name'))+ self.assertEqual(1, self.call('startproject', 'sys'))class CommandTest(ProjectTest):