forked from scrapy/scrapy
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added "scrapy" command with project settings auto-discovery. Refs scr…
- Loading branch information
1 parent
b563e56
commit d17695e
Showing
5 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env python | ||
|
||
from scrapy.tool import main | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[default] | ||
settings = ${project_name}.settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters