Revision 00326543

b/snf-branding/setup.py
38 38
import os
39 39

  
40 40
from setuptools import setup, find_packages
41
from fnmatch import fnmatchcase
42
from distutils.util import convert_path
41 43

  
42 44
HERE = os.path.abspath(os.path.normpath(os.path.dirname(__file__)))
43 45

  
......
59 61
INSTALL_REQUIRES = [
60 62
]
61 63

  
64
# Provided as an attribute, so you can append to these instead
65
# of replicating them:
66
standard_exclude = ["*.py", "*.pyc", "*$py.class", "*~", ".*", "*.bak"]
67
standard_exclude_directories = [
68
    ".*", "CVS", "_darcs", "./build", "./dist", "EGG-INFO", "*.egg-info", "snf-0.7"
69
]
70

  
71
# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
72
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
73
# Note: you may want to copy this into your setup.py file verbatim, as
74
# you can't import this from another package, when you don't know if
75
# that package is installed yet.
76
def find_package_data(
77
    where=".",
78
    package="",
79
    exclude=standard_exclude,
80
    exclude_directories=standard_exclude_directories,
81
    only_in_packages=True,
82
    show_ignored=False):
83
    """
84
    Return a dictionary suitable for use in ``package_data``
85
    in a distutils ``setup.py`` file.
86

  
87
    The dictionary looks like::
88

  
89
        {"package": [files]}
90

  
91
    Where ``files`` is a list of all the files in that package that
92
    don"t match anything in ``exclude``.
93

  
94
    If ``only_in_packages`` is true, then top-level directories that
95
    are not packages won"t be included (but directories under packages
96
    will).
97

  
98
    Directories matching any pattern in ``exclude_directories`` will
99
    be ignored; by default directories with leading ``.``, ``CVS``,
100
    and ``_darcs`` will be ignored.
101

  
102
    If ``show_ignored`` is true, then all the files that aren"t
103
    included in package data are shown on stderr (for debugging
104
    purposes).
105

  
106
    Note patterns use wildcards, or can be exact paths (including
107
    leading ``./``), and all searching is case-insensitive.
108
    """
109
    out = {}
110
    stack = [(convert_path(where), "", package, only_in_packages)]
111
    while stack:
112
        where, prefix, package, only_in_packages = stack.pop(0)
113
        for name in os.listdir(where):
114
            fn = os.path.join(where, name)
115
            if os.path.isdir(fn):
116
                bad_name = False
117
                for pattern in exclude_directories:
118
                    if (fnmatchcase(name, pattern)
119
                        or fn.lower() == pattern.lower()):
120
                        bad_name = True
121
                        if show_ignored:
122
                            print >> sys.stderr, (
123
                                "Directory %s ignored by pattern %s"
124
                                % (fn, pattern))
125
                        break
126
                if bad_name:
127
                    continue
128
                if (os.path.isfile(os.path.join(fn, "__init__.py"))
129
                    and not prefix):
130
                    if not package:
131
                        new_package = name
132
                    else:
133
                        new_package = package + "." + name
134
                    stack.append((fn, "", new_package, False))
135
                else:
136
                    stack.append((fn, prefix + name + "/", package, only_in_packages))
137
            elif package or not only_in_packages:
138
                # is a file
139
                bad_name = False
140
                for pattern in exclude:
141
                    if (fnmatchcase(name, pattern)
142
                        or fn.lower() == pattern.lower()):
143
                        bad_name = True
144
                        if show_ignored:
145
                            print >> sys.stderr, (
146
                                "File %s ignored by pattern %s"
147
                                % (fn, pattern))
148
                        break
149
                if bad_name:
150
                    continue
151
                out.setdefault(package, []).append(prefix+name)
152
    return out
62 153
setup(
63 154
    name='snf-branding-app',
64 155
    version=VERSION,
......
75 166

  
76 167
    packages=PACKAGES,
77 168
    package_dir={'': PACKAGES_ROOT},
169
    package_data=find_package_data('.'),
78 170
    include_package_data=True,
79 171
    zip_safe=False,
80 172

  

Also available in: Unified diff