1
0
mirror of https://github.com/scrapy/scrapy.git synced 2025-02-24 08:03:59 +00:00

add project name validation

This commit is contained in:
Nuno Maximiano 2013-10-18 14:46:55 +01:00 committed by nramirezuy
parent e2c1226838
commit 08224c92f4
2 changed files with 20 additions and 15 deletions

View File

@ -43,18 +43,22 @@ class Command(ScrapyCommand):
elif exists(project_name): elif exists(project_name):
print("Error: directory %r already exists" % project_name) print("Error: directory %r already exists" % project_name)
sys.exit(1) sys.exit(1)
try:
moduletpl = join(TEMPLATES_PATH, 'module') __import__(project_name, [], 0)
copytree(moduletpl, join(project_name, project_name), ignore=IGNORE) print('Error: Project name can\'t be %r, choose another project name' % project_name)
shutil.copy(join(TEMPLATES_PATH, 'scrapy.cfg'), project_name) sys.exit(1)
for paths in TEMPLATES_TO_RENDER: except ImportError:
path = join(*paths) moduletpl = join(TEMPLATES_PATH, 'module')
tplfile = join(project_name, copytree(moduletpl, join(project_name, project_name), ignore=IGNORE)
string.Template(path).substitute(project_name=project_name)) shutil.copy(join(TEMPLATES_PATH, 'scrapy.cfg'), project_name)
render_templatefile(tplfile, project_name=project_name, for paths in TEMPLATES_TO_RENDER:
ProjectName=string_camelcase(project_name)) path = join(*paths)
print("New Scrapy project %r created in:" % project_name) tplfile = join(project_name,
print(" %s\n" % abspath(project_name)) string.Template(path).substitute(project_name=project_name))
print("You can start your first spider with:") render_templatefile(tplfile, project_name=project_name,
print(" cd %s" % project_name) ProjectName=string_camelcase(project_name))
print(" scrapy genspider example example.com") 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")

View File

@ -64,6 +64,7 @@ class StartprojectTest(ProjectTest):
self.assertEqual(1, self.call('startproject', self.project_name)) self.assertEqual(1, self.call('startproject', self.project_name))
self.assertEqual(1, self.call('startproject', 'wrong---project---name')) self.assertEqual(1, self.call('startproject', 'wrong---project---name'))
self.assertEqual(1, self.call('startproject', 'sys'))
class CommandTest(ProjectTest): class CommandTest(ProjectTest):