mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-26 14:44:08 +00:00
added copytree from python 2.6 to utils.misc and make startproject use it to ignore .svn and .pyc files
--HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40857
This commit is contained in:
parent
522fe78c2b
commit
3e8bcafd8b
@ -2,12 +2,12 @@
|
||||
"""Scrapy admin script is used to create new scrapy projects and similar
|
||||
tasks"""
|
||||
import os
|
||||
import shutil
|
||||
import string
|
||||
from optparse import OptionParser
|
||||
|
||||
import scrapy
|
||||
from scrapy.utils.misc import render_templatefile, string_camelcase
|
||||
from scrapy.utils.misc import ignore_patterns, copytree
|
||||
|
||||
usage = """
|
||||
scrapy-admin.py [options] [command]
|
||||
@ -29,6 +29,8 @@ TEMPLATES = (
|
||||
'${project_name}/pipelines.py',
|
||||
)
|
||||
|
||||
IGNORE = ignore_patterns('*.pyc', '.svn')
|
||||
|
||||
def main():
|
||||
parser = OptionParser(usage=usage)
|
||||
opts, args = parser.parse_args()
|
||||
@ -45,10 +47,11 @@ def main():
|
||||
project_module_path = '%s/%s' % (project_name, project_name)
|
||||
|
||||
roottpl = os.path.join(PROJECT_TEMPLATES_PATH, 'root')
|
||||
shutil.copytree(roottpl, project_name)
|
||||
copytree(roottpl, project_name, ignore=IGNORE)
|
||||
|
||||
moduletpl = os.path.join(PROJECT_TEMPLATES_PATH, 'module')
|
||||
shutil.copytree(moduletpl, '%s/%s' % (project_name, project_name))
|
||||
copytree(moduletpl, '%s/%s' % (project_name, project_name),
|
||||
ignore=IGNORE)
|
||||
|
||||
for path in TEMPLATES:
|
||||
tplfile = os.path.join(project_root_path,
|
||||
|
@ -174,3 +174,60 @@ def string_camelcase(string):
|
||||
|
||||
"""
|
||||
return CAMELCASE_INVALID_CHARS.sub('', string.title())
|
||||
|
||||
|
||||
# shutil.copytree from Python 2.6 (for backwards compatibility)
|
||||
import fnmatch
|
||||
import os
|
||||
from shutil import copy2, copystat, WindowsError
|
||||
|
||||
|
||||
def ignore_patterns(*patterns):
|
||||
def _ignore_patterns(path, names):
|
||||
ignored_names = []
|
||||
for pattern in patterns:
|
||||
ignored_names.extend(fnmatch.filter(names, pattern))
|
||||
return set(ignored_names)
|
||||
return _ignore_patterns
|
||||
|
||||
|
||||
def copytree(src, dst, symlinks=False, ignore=None):
|
||||
names = os.listdir(src)
|
||||
if ignore is not None:
|
||||
ignored_names = ignore(src, names)
|
||||
else:
|
||||
ignored_names = set()
|
||||
|
||||
os.makedirs(dst)
|
||||
errors = []
|
||||
for name in names:
|
||||
if name in ignored_names:
|
||||
continue
|
||||
srcname = os.path.join(src, name)
|
||||
dstname = os.path.join(dst, name)
|
||||
try:
|
||||
if symlinks and os.path.islink(srcname):
|
||||
linkto = os.readlink(srcname)
|
||||
os.symlink(linkto, dstname)
|
||||
elif os.path.isdir(srcname):
|
||||
copytree(srcname, dstname, symlinks, ignore)
|
||||
else:
|
||||
copy2(srcname, dstname)
|
||||
# XXX What about devices, sockets etc.?
|
||||
except (IOError, os.error), why:
|
||||
errors.append((srcname, dstname, str(why)))
|
||||
# catch the Error from the recursive copytree so that we can
|
||||
# continue with other files
|
||||
except Error, err:
|
||||
errors.extend(err.args[0])
|
||||
try:
|
||||
copystat(src, dst)
|
||||
except OSError, why:
|
||||
if WindowsError is not None and isinstance(why, WindowsError):
|
||||
# Copying file access times may fail on Windows
|
||||
pass
|
||||
else:
|
||||
errors.extend((src, dst, str(why)))
|
||||
if errors:
|
||||
raise Error, errors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user