cubicweb/skeleton/setup.py
changeset 11071 fdadf59be612
parent 11057 0b59724cb3f2
child 11085 2c0541b6803f
equal deleted inserted replaced
11070:1d115904f1ef 11071:fdadf59be612
    23 __docformat__ = "restructuredtext en"
    23 __docformat__ = "restructuredtext en"
    24 
    24 
    25 import os
    25 import os
    26 import sys
    26 import sys
    27 import shutil
    27 import shutil
    28 from os.path import exists, join, walk
    28 from os.path import exists, join
    29 
    29 
    30 try:
    30 try:
    31     if os.environ.get('NO_SETUPTOOLS'):
    31     if os.environ.get('NO_SETUPTOOLS'):
    32         raise ImportError()  # do as there is no setuptools
    32         raise ImportError()  # do as there is no setuptools
    33     from setuptools import setup
    33     from setuptools import setup
    85 
    85 
    86 def export(from_dir, to_dir,
    86 def export(from_dir, to_dir,
    87            blacklist=BASE_BLACKLIST,
    87            blacklist=BASE_BLACKLIST,
    88            ignore_ext=IGNORED_EXTENSIONS,
    88            ignore_ext=IGNORED_EXTENSIONS,
    89            verbose=True):
    89            verbose=True):
    90     """make a mirror of from_dir in to_dir, omitting directories and files
       
    91     listed in the black list
       
    92     """
       
    93     def make_mirror(arg, directory, fnames):
       
    94         """walk handler"""
       
    95         for norecurs in blacklist:
       
    96             try:
       
    97                 fnames.remove(norecurs)
       
    98             except ValueError:
       
    99                 pass
       
   100         for filename in fnames:
       
   101             # don't include binary files
       
   102             if filename[-4:] in ignore_ext:
       
   103                 continue
       
   104             if filename[-1] == '~':
       
   105                 continue
       
   106             src = join(directory, filename)
       
   107             dest = to_dir + src[len(from_dir):]
       
   108             if verbose:
       
   109                 sys.stderr.write('%s -> %s\n' % (src, dest))
       
   110             if os.path.isdir(src):
       
   111                 if not exists(dest):
       
   112                     os.mkdir(dest)
       
   113             else:
       
   114                 if exists(dest):
       
   115                     os.remove(dest)
       
   116                 shutil.copy2(src, dest)
       
   117     try:
    90     try:
   118         os.mkdir(to_dir)
    91         os.mkdir(to_dir)
   119     except OSError as ex:
    92     except OSError as ex:
   120         # file exists ?
    93         # file exists ?
   121         import errno
    94         import errno
   122         if ex.errno != errno.EEXIST:
    95         if ex.errno != errno.EEXIST:
   123             raise
    96             raise
   124     walk(from_dir, make_mirror, None)
    97     for dirpath, dirnames, filenames in os.walk(from_dir):
       
    98         for norecurs in blacklist:
       
    99             try:
       
   100                 dirnames.remove(norecurs)
       
   101             except ValueError:
       
   102                 pass
       
   103         for dirname in dirnames:
       
   104             dest = join(to_dir, dirname)
       
   105             if not exists(dest):
       
   106                 os.mkdir(dest)
       
   107         for filename in filenames:
       
   108             # don't include binary files
       
   109             src = join(dirpath, filename)
       
   110             dest = to_dir + src[len(from_dir):]
       
   111             if filename[-4:] in ignore_ext:
       
   112                 continue
       
   113             if filename[-1] == '~':
       
   114                 continue
       
   115             if exists(dest):
       
   116                 os.remove(dest)
       
   117             shutil.copy2(src, dest)
   125 
   118 
   126 
   119 
   127 class MyInstallLib(install_lib.install_lib):
   120 class MyInstallLib(install_lib.install_lib):
   128     """extend install_lib command to handle  package __init__.py and
   121     """extend install_lib command to handle  package __init__.py and
   129     include_dirs variable if necessary
   122     include_dirs variable if necessary