mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-23 21:24:20 +00:00
substitute scrapy_settings template variables on startproject
--HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40382
This commit is contained in:
parent
bddfbee0d4
commit
d6d32fa672
@ -1,9 +1,11 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
"""Scrapy admin script is used to create new scrapy projects and similar
|
"""Scrapy admin script is used to create new scrapy projects and similar
|
||||||
tasks"""
|
tasks"""
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import string
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
import scrapy
|
import scrapy
|
||||||
@ -17,12 +19,27 @@ Available commands:
|
|||||||
Starts a new project with name 'project_name'
|
Starts a new project with name 'project_name'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
TEMPLATES = (
|
||||||
|
'scrapy_settings.py',
|
||||||
|
)
|
||||||
|
|
||||||
|
def render_templatefile(path, **kwargs):
|
||||||
|
with open(path, 'rb') as file:
|
||||||
|
raw = file.read()
|
||||||
|
|
||||||
|
content = string.Template(raw).substitute(**kwargs)
|
||||||
|
|
||||||
|
with open(path, 'wb') as file:
|
||||||
|
file.write(content)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = OptionParser(usage=usage)
|
parser = OptionParser(usage=usage)
|
||||||
opts, args = parser.parse_args()
|
opts, args = parser.parse_args()
|
||||||
|
|
||||||
if not args:
|
if not args:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
return
|
||||||
|
|
||||||
cmd = args[0]
|
cmd = args[0]
|
||||||
if cmd == "startproject":
|
if cmd == "startproject":
|
||||||
@ -30,6 +47,8 @@ def main():
|
|||||||
project_name = args[1]
|
project_name = args[1]
|
||||||
project_tplpath = os.path.join(scrapy.__path__[0], "conf", "project_template")
|
project_tplpath = os.path.join(scrapy.__path__[0], "conf", "project_template")
|
||||||
shutil.copytree(project_tplpath, project_name)
|
shutil.copytree(project_tplpath, project_name)
|
||||||
|
for path in TEMPLATES:
|
||||||
|
render_templatefile(os.path.join(project_name, path), project_name=project_name)
|
||||||
else:
|
else:
|
||||||
print "scrapy-admin.py: missing project name"
|
print "scrapy-admin.py: missing project name"
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user