Scrapy, a fast high-level web crawling & scraping framework for Python.
moved copytree function to scrapy.utils.python (more appropiate location) and fixed minor bug ('Error' not defined). also removed unused var 'project_module_path'
Pablo Hoffman489e86bd16ab
diff --git a/scrapy/trunk/scrapy/bin/scrapy-admin.py b/scrapy/trunk/scrapy/bin/scrapy-admin.pyindex efbd61c0e..1dc1a6381 100755--- a/scrapy/trunk/scrapy/bin/scrapy-admin.py+++ b/scrapy/trunk/scrapy/bin/scrapy-admin.py@@ -7,7 +7,7 @@ from optparse import OptionParserimport scrapyfrom scrapy.utils.misc import render_templatefile, string_camelcase-from scrapy.utils.misc import ignore_patterns, copytree+from scrapy.utils.python import ignore_patterns, copytreeusage = """scrapy-admin.py [options] [command]@@ -44,7 +44,6 @@ def main():if len(args) >= 2:project_name = args[1]project_root_path = project_name- project_module_path = '%s/%s' % (project_name, project_name)roottpl = os.path.join(PROJECT_TEMPLATES_PATH, 'root')copytree(roottpl, project_name, ignore=IGNORE)diff --git a/scrapy/trunk/scrapy/utils/misc.py b/scrapy/trunk/scrapy/utils/misc.pyindex 7660b8673..a4deb8578 100644--- a/scrapy/trunk/scrapy/utils/misc.py+++ b/scrapy/trunk/scrapy/utils/misc.py@@ -175,65 +175,3 @@ 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---try:- WindowsError-except NameError:- WindowsError = None---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-diff --git a/scrapy/trunk/scrapy/utils/python.py b/scrapy/trunk/scrapy/utils/python.pyindex abbb81902..7589304df 100644--- a/scrapy/trunk/scrapy/utils/python.py+++ b/scrapy/trunk/scrapy/utils/python.py@@ -1,7 +1,14 @@"""This module contains essential stuff that should've come with Python itself ;)++It also contains functions (or functionality) which is in Python versions+higher than 2.5 which is the lower version support by Scrapy.+"""import re+import fnmatch+import os+from shutil import copy2, copystatfrom sgmllib import SGMLParserclass FixedSGMLParser(SGMLParser):@@ -165,3 +172,65 @@ def isbinarytext(text):"""assert isinstance(text, str), "text must be str, got '%s'" % type(text).__name__return any(c in _BINARYCHARS for c in text)+++# ----- shutil.copytree function from Python 2.6 adds ignore argument ---- #++try:+ WindowsError+except NameError:+ WindowsError = None++class Error(EnvironmentError):+ pass++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++# ----- end of shutil.copytree function from Python 2.6 ---- #+