mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-23 12:43:57 +00:00
Added "scrapy" command with project settings auto-discovery. Refs #199
This commit is contained in:
parent
b563e56363
commit
d17695ee4b
4
bin/scrapy
Executable file
4
bin/scrapy
Executable file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from scrapy.tool import main
|
||||
main()
|
@ -12,6 +12,7 @@ from scrapy.utils.py26 import ignore_patterns, copytree
|
||||
TEMPLATES_PATH = join(scrapy.__path__[0], 'templates', 'project')
|
||||
|
||||
TEMPLATES_TO_RENDER = (
|
||||
('scrapy.cfg',),
|
||||
('scrapy-ctl.py',),
|
||||
('${project_name}', 'settings.py.tmpl'),
|
||||
('${project_name}', 'items.py.tmpl'),
|
||||
@ -44,6 +45,7 @@ class Command(ScrapyCommand):
|
||||
|
||||
moduletpl = join(TEMPLATES_PATH, 'module')
|
||||
copytree(moduletpl, join(project_name, project_name), ignore=IGNORE)
|
||||
shutil.copy(join(TEMPLATES_PATH, 'scrapy.cfg'), project_name)
|
||||
shutil.copy(join(TEMPLATES_PATH, 'scrapy-ctl.py'), project_name)
|
||||
for paths in TEMPLATES_TO_RENDER:
|
||||
path = join(*paths)
|
||||
|
2
scrapy/templates/project/scrapy.cfg
Normal file
2
scrapy/templates/project/scrapy.cfg
Normal file
@ -0,0 +1,2 @@
|
||||
[default]
|
||||
settings = ${project_name}.settings
|
32
scrapy/tool.py
Normal file
32
scrapy/tool.py
Normal file
@ -0,0 +1,32 @@
|
||||
"""
|
||||
Scrapy command-line tool
|
||||
"""
|
||||
|
||||
import sys, os
|
||||
from ConfigParser import RawConfigParser
|
||||
|
||||
def closest_scrapy_cfg(path='.', prevpath=None):
|
||||
if path == prevpath:
|
||||
return ''
|
||||
path = os.path.abspath(path)
|
||||
cfgfile = os.path.join(path, 'scrapy.cfg')
|
||||
if os.path.exists(cfgfile):
|
||||
return cfgfile
|
||||
return closest_scrapy_cfg(os.path.dirname(path), path)
|
||||
|
||||
def main():
|
||||
scrapy_cfg = closest_scrapy_cfg()
|
||||
cfg_sources = [scrapy_cfg, os.path.expanduser('~/.scrapy.cfg'), '/etc/scrapy.cfg']
|
||||
cfg = RawConfigParser()
|
||||
cfg.read(cfg_sources)
|
||||
if cfg.has_option('default', 'settings'):
|
||||
os.environ['SCRAPY_SETTINGS_MODULE'] = cfg.get('default', 'settings')
|
||||
projdir = os.path.dirname(scrapy_cfg)
|
||||
if projdir not in sys.path:
|
||||
sys.path.append(projdir)
|
||||
|
||||
from scrapy.cmdline import execute
|
||||
execute()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
2
setup.py
2
setup.py
@ -90,7 +90,7 @@ setup_args = {
|
||||
'packages': packages,
|
||||
'cmdclass': cmdclasses,
|
||||
'data_files': data_files,
|
||||
'scripts': ['bin/scrapy-ctl.py', 'bin/scrapy-ws.py', 'bin/scrapy-sqs.py'],
|
||||
'scripts': ['bin/scrapy', 'bin/scrapy-ctl.py', 'bin/scrapy-ws.py', 'bin/scrapy-sqs.py'],
|
||||
'classifiers': [
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 2.5',
|
||||
|
Loading…
x
Reference in New Issue
Block a user