setup.py: use os.walk instead of os.path.walk

The latter doesn't exist in python3

authorJulien Cristau <julien.cristau@logilab.fr>
changeset4d2fdd33452a
branchdefault
phasedraft
hiddenyes
parent revision#e6e5be118978 pkginfo: adjust for python3
child revision#28f9f9e63606 gecode_solver: fix build for python3
files modified by this revision
setup.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1406314915 -7200
# Fri Jul 25 21:01:55 2014 +0200
# Node ID 4d2fdd33452a43fab5ce01b2dd4283f958878c68
# Parent e6e5be118978ab654c0ce07a729daa03cefa0f7a
setup.py: use os.walk instead of os.path.walk

The latter doesn't exist in python3

diff --git a/setup.py b/setup.py
@@ -22,11 +22,11 @@
1  __docformat__ = "restructuredtext en"
2 
3  import os
4  import sys
5  import shutil
6 -from os.path import isdir, exists, join, walk
7 +from os.path import isdir, exists, join
8 
9  try:
10      if os.environ.get('NO_SETUPTOOLS'):
11          raise ImportError()
12      from setuptools import setup
@@ -93,42 +93,50 @@
13             ignore_ext=IGNORED_EXTENSIONS,
14             verbose=True):
15      """make a mirror of from_dir in to_dir, omitting directories and files
16      listed in the black list
17      """
18 -    def make_mirror(arg, directory, fnames):
19 +    def make_mirror(dirpath, dirnames, fnames):
20          """walk handler"""
21          for norecurs in blacklist:
22              try:
23                  fnames.remove(norecurs)
24              except ValueError:
25                  pass
26 +            try:
27 +                dirnames.remove(norecurs)
28 +            except ValueError:
29 +                pass
30 +        for dirname in dirnames:
31 +            src = join(dirpath, dirname)
32 +            dest = to_dir + src[len(from_dir):]
33 +            if verbose:
34 +                print >> sys.stderr, src, '->', dest
35 +            if not exists(dest):
36 +                os.mkdir(dest)
37          for filename in fnames:
38              # don't include binary files
39              if filename[-4:] in ignore_ext:
40                  continue
41              if filename[-1] == '~':
42                  continue
43 -            src = join(directory, filename)
44 +            src = join(dirpath, filename)
45              dest = to_dir + src[len(from_dir):]
46              if verbose:
47                  print >> sys.stderr, src, '->', dest
48 -            if os.path.isdir(src):
49 -                if not exists(dest):
50 -                    os.mkdir(dest)
51 -            else:
52 -                if exists(dest):
53 -                    os.remove(dest)
54 -                shutil.copy2(src, dest)
55 +            if exists(dest):
56 +                os.remove(dest)
57 +            shutil.copy2(src, dest)
58      try:
59          os.mkdir(to_dir)
60      except OSError as ex:
61          # file exists ?
62          import errno
63          if ex.errno != errno.EEXIST:
64              raise
65 -    walk(from_dir, make_mirror, None)
66 +    for root, dirnames, fnames in os.walk(from_dir):
67 +        make_mirror(root, dirnames, fnames)
68 
69 
70  EMPTY_FILE = '''"""generated file, don\'t modify or your data will be lost"""
71  try:
72      __import__('pkg_resources').declare_namespace(__name__)