From fc9a45ee9129912e4ee138b0a17d8ed8a27a0c9e Mon Sep 17 00:00:00 2001 From: Felipe Ruhland Date: Tue, 24 May 2016 11:57:56 -0300 Subject: [PATCH] Simplified copytree function --- scrapy/commands/startproject.py | 40 ++++++++------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/scrapy/commands/startproject.py b/scrapy/commands/startproject.py index 4da129865..c0e7af88a 100644 --- a/scrapy/commands/startproject.py +++ b/scrapy/commands/startproject.py @@ -52,47 +52,25 @@ class Command(ScrapyCommand): return True return False - def _copytree(self, src, dst, symlinks=False, ignore=None): + def _copytree(self, src, dst): + ignore = IGNORE names = os.listdir(src) - if ignore is not None: - ignored_names = ignore(src, names) - else: - ignored_names = set() + ignored_names = ignore(src, names) if not os.path.exists(dst): 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): - self._copytree(srcname, dstname, symlinks, ignore) - else: - # Will raise a SpecialFileError for unsupported file types - copy2(srcname, dstname) - # catch the Error from the recursive copytree so that we can - # continue with other files - except EnvironmentError as err: - errors.extend(err.args[0]) - except EnvironmentError as why: - errors.append((srcname, dstname, str(why))) - try: - copystat(src, dst) - except OSError as why: - if WindowsError is not None and isinstance(why, WindowsError): - # Copying file access times may fail on Windows - pass + if os.path.isdir(srcname): + self._copytree(srcname, dstname) else: - errors.append((src, dst, str(why))) - if errors: - raise EnvironmentError(errors) + copy2(srcname, dstname) + copystat(src, dst) def run(self, args, opts): if len(args) not in (1, 2): @@ -112,7 +90,7 @@ class Command(ScrapyCommand): self.exitcode = 1 return - self._copytree(self.templates_dir, abspath(project_dir), ignore=IGNORE) + self._copytree(self.templates_dir, abspath(project_dir)) move(join(project_dir, 'module'), join(project_dir, project_name)) for paths in TEMPLATES_TO_RENDER: path = join(*paths)