mirror of https://github.com/scrapy/scrapy.git
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
This commit is contained in:
parent
d6d32fa672
commit
862def2d73
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue