minor adjustments and some fixes, readded scrapy-admin.py with

execution permission

--HG--
extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40124
This commit is contained in:
olveyra 2008-07-27 02:23:14 +00:00
parent b851ec5f10
commit 137ec64318
2 changed files with 54 additions and 3 deletions

View File

@ -0,0 +1,51 @@
#!/usr/bin/env python
"""Scrapy admin script"""
import os, stat
from optparse import OptionParser
import scrapy
usage = """
Usage: scrapy-admin.py [options] [command]
Available commands:
startproject <project_name>
Starts a new project with name 'project_name'
"""
def main():
parser = OptionParser(usage = usage)
opts, args = parser.parse_args()
if args:
if args[0] == "startproject":
try:
project_name = args[1]
except IndexError:
parser.print_help()
else:
os.mkdir(project_name)
os.mknod(os.path.join(project_name, "__init__.py"))
for subdir in ["spiders", "conf", "commands"]:
os.mkdir(os.path.join(project_name, subdir))
os.mknod(os.path.join(project_name, subdir, "__init__.py"))
settings_template = open(os.path.join(scrapy.__path__[0], "templates", "settings.tmpl"), "r").read()
settings = settings_template.replace("__project_name__", project_name)
open(os.path.join(project_name, "conf", "scrapy_settings.py"), "w").write(settings)
control_template = open(os.path.join(scrapy.__path__[0], "templates", "scrapy-ctl.tmpl"), "r").read()
control = control_template.replace("__project_name__", project_name)
open(os.path.join(project_name, "scrapy-ctl.py"), "w").write(control)
os.chmod(os.path.join(project_name, "scrapy-ctl.py"), stat.S_IRWXU)
return
parser.print_help()
if __name__ == '__main__':
main()

View File

@ -8,17 +8,17 @@ sys.modules['chardet'] = None
# to avoid (write) permission problems with images, cache, etc
#os.umask(0002)
SCRAPING_TRUNK = os.environ.get('SCRAPING_TRUNK', os.environ.get('PWD/..')).split(":")
SCRAPING_TRUNK = os.environ.get('SCRAPING_TRUNK', os.environ.get('PWD') + '/..')
try:
import __project_name__
except:
sys.path.extend(SCRAPING_TRUNK)
sys.path.append(SCRAPING_TRUNK)
try:
import scrapy_settings
except:
sys.path.extend(['%s/__project_name__/conf' % spath for spath in SCRAPING_TRUNK])
sys.path.append('%s/__project_name__/conf' % SCRAPING_TRUNK)
from scrapy.command.cmdline import execute
execute()