From 862def2d739194bc9cb572308fac5eafc5d23341 Mon Sep 17 00:00:00 2001 From: Daniel Grana Date: Mon, 17 Nov 2008 10:33:49 +0000 Subject: [PATCH] move teplate renderer function to utils package, it can be reused by genspider command --HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40383 --- scrapy/trunk/scrapy/bin/scrapy-admin.py | 14 +------------- scrapy/trunk/scrapy/utils/misc.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 13 deletions(-) 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) + +