Skip to content

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

move teplate renderer function to utils package, it can be reused by genspider command

Daniel Grana862def2d7391
diff --git a/scrapy/trunk/scrapy/bin/scrapy-admin.py b/scrapy/trunk/scrapy/bin/scrapy-admin.py
index 8c9bd88e7..5804a0c63 100755
--- a/scrapy/trunk/scrapy/bin/scrapy-admin.py
+++ b/scrapy/trunk/scrapy/bin/scrapy-admin.py
@@ -1,14 +1,12 @@
#!/usr/bin/env python
"""Scrapy admin script is used to create new scrapy projects and similar
tasks"""
-from __future__ import with_statement
-
import os
import shutil
-import string
from optparse import OptionParser
import scrapy
+from scrapy.utils.misc import render_templatefile
usage = """
scrapy-admin.py [options] [command]
@@ -23,16 +21,6 @@ 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():
parser = OptionParser(usage=usage)
opts, args = parser.parse_args()
diff --git a/scrapy/trunk/scrapy/utils/misc.py b/scrapy/trunk/scrapy/utils/misc.py
index d69a028e1..39ddee5a7 100644
--- a/scrapy/trunk/scrapy/utils/misc.py
+++ b/scrapy/trunk/scrapy/utils/misc.py
@@ -1,7 +1,10 @@
"""
Auxiliary functions which doesn't fit anywhere else
"""
+from __future__ import with_statement
+
import re
+import string
import hashlib
from twisted.internet import defer
@@ -113,3 +116,14 @@ def hash_values(*values):
hash.update(value)
return hash.hexdigest()
+
+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)
+
+