Revision b064bda7 snf-app/setup.py

b/snf-app/setup.py
2 2
distribute_setup.use_setuptools()
3 3

  
4 4
import os
5

  
6
from distutils.util import convert_path
7
from fnmatch import fnmatchcase
5 8
from setuptools import setup, find_packages
6 9
from synnefo import get_version
7 10

  
......
42 45
TESTS_REQUIRES = [
43 46
]
44 47

  
45
PACKAGE_DATA = {
46
    '': ['templates/*.html', 'fixtures/*.json',
47
         'templates/*.xml', 'templates/partials/*.html',
48
         'templates/*.txt', 'templates/userdata/*.html'],
49 48

  
50
    'synnefo': ['settings.d/*.conf']
51
}
49
# Provided as an attribute, so you can append to these instead
50
# of replicating them:
51
standard_exclude = ["*.py", "*.pyc", "*$py.class", "*~", ".*", "*.bak"]
52
standard_exclude_directories = [
53
    ".*", "CVS", "_darcs", "./build", "./dist", "EGG-INFO", "*.egg-info", "snf-0.7"
54
]
55

  
56
# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
57
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
58
# Note: you may want to copy this into your setup.py file verbatim, as
59
# you can't import this from another package, when you don't know if
60
# that package is installed yet.
61
def find_package_data(
62
    where=".",
63
    package="",
64
    exclude=standard_exclude,
65
    exclude_directories=standard_exclude_directories,
66
    only_in_packages=True,
67
    show_ignored=False):
68
    """
69
    Return a dictionary suitable for use in ``package_data``
70
    in a distutils ``setup.py`` file.
71

  
72
    The dictionary looks like::
73

  
74
        {"package": [files]}
75

  
76
    Where ``files`` is a list of all the files in that package that
77
    don"t match anything in ``exclude``.
78

  
79
    If ``only_in_packages`` is true, then top-level directories that
80
    are not packages won"t be included (but directories under packages
81
    will).
82

  
83
    Directories matching any pattern in ``exclude_directories`` will
84
    be ignored; by default directories with leading ``.``, ``CVS``,
85
    and ``_darcs`` will be ignored.
86

  
87
    If ``show_ignored`` is true, then all the files that aren"t
88
    included in package data are shown on stderr (for debugging
89
    purposes).
90

  
91
    Note patterns use wildcards, or can be exact paths (including
92
    leading ``./``), and all searching is case-insensitive.
93
    """
94
    out = {}
95
    stack = [(convert_path(where), "", package, only_in_packages)]
96
    while stack:
97
        where, prefix, package, only_in_packages = stack.pop(0)
98
        for name in os.listdir(where):
99
            fn = os.path.join(where, name)
100
            if os.path.isdir(fn):
101
                bad_name = False
102
                for pattern in exclude_directories:
103
                    if (fnmatchcase(name, pattern)
104
                        or fn.lower() == pattern.lower()):
105
                        bad_name = True
106
                        if show_ignored:
107
                            print >> sys.stderr, (
108
                                "Directory %s ignored by pattern %s"
109
                                % (fn, pattern))
110
                        break
111
                if bad_name:
112
                    continue
113
                if (os.path.isfile(os.path.join(fn, "__init__.py"))
114
                    and not prefix):
115
                    if not package:
116
                        new_package = name
117
                    else:
118
                        new_package = package + "." + name
119
                    stack.append((fn, "", new_package, False))
120
                else:
121
                    stack.append((fn, prefix + name + "/", package, only_in_packages))
122
            elif package or not only_in_packages:
123
                # is a file
124
                bad_name = False
125
                for pattern in exclude:
126
                    if (fnmatchcase(name, pattern)
127
                        or fn.lower() == pattern.lower()):
128
                        bad_name = True
129
                        if show_ignored:
130
                            print >> sys.stderr, (
131
                                "File %s ignored by pattern %s"
132
                                % (fn, pattern))
133
                        break
134
                if bad_name:
135
                    continue
136
                out.setdefault(package, []).append(prefix+name)
137
    return out
52 138

  
53 139
setup(
54 140
    name = 'synnefo',
......
67 153
    packages = PACKAGES,
68 154
    package_dir= {'': PACKAGES_ROOT},
69 155
    include_package_data = True,
70
    package_data = PACKAGE_DATA,
156
    package_data = find_package_data('.'),
71 157
    zip_safe = False,
72 158

  
73 159
    install_requires = INSTALL_REQUIRES,

Also available in: Unified diff