mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-23 16:03:56 +00:00
add project name validation
This commit is contained in:
parent
e2c1226838
commit
08224c92f4
@ -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")
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user