Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

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

olveyra137ec64318c6
diff --git a/scrapy/trunk/scrapy/bin/scrapy-admin.py b/scrapy/trunk/scrapy/bin/scrapy-admin.py
new file mode 100755
index 000000000..daa731ecf
--- /dev/null
+++ b/scrapy/trunk/scrapy/bin/scrapy-admin.py
@@ -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()
\ No newline at end of file
diff --git a/scrapy/trunk/scrapy/templates/scrapy-ctl.tmpl b/scrapy/trunk/scrapy/templates/scrapy-ctl.tmpl
index 605ed892d..3eea158d3 100644
--- a/scrapy/trunk/scrapy/templates/scrapy-ctl.tmpl
+++ b/scrapy/trunk/scrapy/templates/scrapy-ctl.tmpl
@@ -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()
\ No newline at end of file