Statistics
| Branch: | Tag: | Revision:

root / snf-pithos-web-client / setup.py @ a577f110

History | View | Annotate | Download (9.6 kB)

1
#!/usr/bin/env python
2

    
3
# Copyright 2011-2012 GRNET S.A. All rights reserved.
4
#
5
# Redistribution and use in source and binary forms, with or
6
# without modification, are permitted provided that the following
7
# conditions are met:
8
#
9
#   1. Redistributions of source code must retain the above
10
#      copyright notice, this list of conditions and the following
11
#      disclaimer.
12
#
13
#   2. Redistributions in binary form must reproduce the above
14
#      copyright notice, this list of conditions and the following
15
#      disclaimer in the documentation and/or other materials
16
#      provided with the distribution.
17
#
18
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
19
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
22
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
25
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
# POSSIBILITY OF SUCH DAMAGE.
30
#
31
# The views and conclusions contained in the software and
32
# documentation are those of the authors and should not be
33
# interpreted as representing official policies, either expressed
34
# or implied, of GRNET S.A.
35
import distribute_setup
36
distribute_setup.use_setuptools()
37

    
38
import os
39
import sys
40

    
41
from fnmatch import fnmatchcase
42
from distutils.util import convert_path
43

    
44
from setuptools import setup, find_packages
45

    
46

    
47
HERE = os.path.abspath(os.path.normpath(os.path.dirname(__file__)))
48
try:
49
    # try to update the version file
50
    from synnefo.util import version
51
    version.update_version('pithos_web_client', 'version', HERE)
52
except ImportError:
53
    pass
54

    
55
from pithos_web_client.version import __version__
56

    
57
# Package info
58
VERSION = __version__
59
README = open(os.path.join(HERE, 'README')).read()
60
CHANGES = open(os.path.join(HERE, 'Changelog')).read()
61
SHORT_DESCRIPTION = 'Package short description'
62

    
63
PACKAGES_ROOT = '.'
64
PACKAGES = find_packages(PACKAGES_ROOT)
65

    
66
# Package meta
67
CLASSIFIERS = [
68
        'Development Status :: 3 - Alpha',
69
        'Operating System :: OS Independent',
70
        'Programming Language :: Python',
71
        'Topic :: Utilities',
72
        'License :: OSI Approved :: BSD License',
73
]
74

    
75
# Package requirements
76
INSTALL_REQUIRES = [
77
    'Django>=1.2, <1.3',
78
    'snf-common>=0.9.0rc'
79
]
80

    
81
EXTRAS_REQUIRES = {
82
}
83

    
84
TESTS_REQUIRES = [
85
]
86

    
87
# Provided as an attribute, so you can append to these instead
88
# of replicating them:
89
standard_exclude = ["*.py", "*.pyc", "*$py.class", "*~", ".*", "*.bak"]
90
standard_exclude_directories = [
91
    ".*", "CVS", "_darcs", "./build", "./dist", "EGG-INFO", "*.egg-info", "snf-0.7"
92
]
93

    
94
# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
95
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
96
# Note: you may want to copy this into your setup.py file verbatim, as
97
# you can't import this from another package, when you don't know if
98
# that package is installed yet.
99
def find_package_data(
100
    where=".",
101
    package="",
102
    exclude=standard_exclude,
103
    exclude_directories=standard_exclude_directories,
104
    only_in_packages=True,
105
    show_ignored=False):
106
    """
107
    Return a dictionary suitable for use in ``package_data``
108
    in a distutils ``setup.py`` file.
109

110
    The dictionary looks like::
111

112
        {"package": [files]}
113

114
    Where ``files`` is a list of all the files in that package that
115
    don"t match anything in ``exclude``.
116

117
    If ``only_in_packages`` is true, then top-level directories that
118
    are not packages won"t be included (but directories under packages
119
    will).
120

121
    Directories matching any pattern in ``exclude_directories`` will
122
    be ignored; by default directories with leading ``.``, ``CVS``,
123
    and ``_darcs`` will be ignored.
124

125
    If ``show_ignored`` is true, then all the files that aren"t
126
    included in package data are shown on stderr (for debugging
127
    purposes).
128

129
    Note patterns use wildcards, or can be exact paths (including
130
    leading ``./``), and all searching is case-insensitive.
131
    """
132
    out = {}
133
    stack = [(convert_path(where), "", package, only_in_packages)]
134
    while stack:
135
        where, prefix, package, only_in_packages = stack.pop(0)
136
        for name in os.listdir(where):
137
            fn = os.path.join(where, name)
138
            if os.path.isdir(fn):
139
                bad_name = False
140
                for pattern in exclude_directories:
141
                    if (fnmatchcase(name, pattern)
142
                        or fn.lower() == pattern.lower()):
143
                        bad_name = True
144
                        if show_ignored:
145
                            print >> sys.stderr, (
146
                                "Directory %s ignored by pattern %s"
147
                                % (fn, pattern))
148
                        break
149
                if bad_name:
150
                    continue
151
                if (os.path.isfile(os.path.join(fn, "__init__.py"))
152
                    and not prefix):
153
                    if not package:
154
                        new_package = name
155
                    else:
156
                        new_package = package + "." + name
157
                    stack.append((fn, "", new_package, False))
158
                else:
159
                    stack.append((fn, prefix + name + "/", package, only_in_packages))
160
            elif package or not only_in_packages:
161
                # is a file
162
                bad_name = False
163
                for pattern in exclude:
164
                    if (fnmatchcase(name, pattern)
165
                        or fn.lower() == pattern.lower()):
166
                        bad_name = True
167
                        if show_ignored:
168
                            print >> sys.stderr, (
169
                                "File %s ignored by pattern %s"
170
                                % (fn, pattern))
171
                        break
172
                if bad_name:
173
                    continue
174
                out.setdefault(package, []).append(prefix+name)
175
    return out
176

    
177

    
178
"""
179
Gwt clea/build helpers
180
"""
181
import subprocess as sp
182
import glob
183

    
184
def clean_gwt(root="../", public_dir="bin/www/gr.grnet.pithos.web.Pithos/"):
185
    curdir = os.getcwd()
186
    os.chdir(root)
187
    rcode = sp.call(["ant", "clean"])
188
    if rcode == 1:
189
        raise Exception("GWT clean failed")
190
    os.chdir(curdir)
191
    pub_dir = os.path.abspath(os.path.join(root, public_dir))
192
    static_dir = os.path.abspath(os.path.join("pithos_web_client", "static", \
193
        "pithos_web_client"))
194
    templates_dir = os.path.abspath(os.path.join("pithos_web_client", \
195
        "templates", "pithos_web_client"))
196
    clean_static = ["rm", "-r"] + glob.glob(os.path.join(static_dir, "*"))
197
    clean_templates = ["rm", "-r"] + glob.glob(os.path.join(templates_dir, "*"))
198

    
199
    # clean dirs
200
    if len(clean_static) > 2:
201
        sp.call(clean_static)
202
    if len(clean_static) > 2:
203
        sp.call(clean_templates)
204

    
205

    
206
def build_gwt(root="../", public_dir="bin/www/gr.grnet.pithos.web.Pithos/"):
207
    curdir = os.getcwd()
208
    os.chdir(root)
209
    # run ant on root dir
210
    rcode = sp.call(["ant"])
211
    if rcode == 1:
212
        raise Exception("GWT build failed")
213
    os.chdir(curdir)
214

    
215

    
216
    pub_dir = os.path.abspath(os.path.join(root, public_dir))
217
    static_dir = os.path.abspath(os.path.join("pithos_web_client", "static", \
218
        "pithos_web_client"))
219
    templates_dir = os.path.abspath(os.path.join("pithos_web_client", \
220
        "templates", "pithos_web_client"))
221

    
222
    clean_static = ["rm", "-r"] + glob.glob(os.path.join(static_dir, "*"))
223
    clean_templates = ["rm", "-r"] + glob.glob(os.path.join(templates_dir, "*"))
224

    
225
    # clean dirs
226
    if len(clean_static) > 2:
227
        sp.call(clean_static)
228
    if len(clean_static) > 2:
229
        sp.call(clean_templates)
230

    
231
    copy_static = ["cp", "-r"] + glob.glob(os.path.join(pub_dir, "*")) + [static_dir]
232
    copy_index = ["cp", os.path.join(pub_dir, "index.html"), templates_dir]
233
    sp.call(copy_static)
234
    sp.call(copy_index)
235

    
236
    index = os.path.join(templates_dir, "index.html")
237
    index_data = file(index).read()
238
    index_data = index_data.replace('href="', 'href="{{ MEDIA_URL }}pithos_web_client/')
239
    index_data = index_data.replace('" src="', '" src="{{ MEDIA_URL }}pithos_web_client/')
240
    index_data = index_data.replace('\' src=\'', '" src="{{ MEDIA_URL }}pithos_web_client/')
241
    index_data = index_data.replace('url(', 'url({{ MEDIA_URL }}pithos_web_client/')
242

    
243
    ifile = file(index, "w+")
244
    ifile.write(index_data)
245
    ifile.close()
246

    
247

    
248
# do we need to run ant ???
249
if any(x in ''.join(sys.argv) for x in ["sdist", "build"]):
250
    build_gwt()
251

    
252
if any(x in ''.join(sys.argv) for x in ["clean"]):
253
    clean_gwt()
254

    
255

    
256
setup(
257
    name='snf-pithos-web-client',
258
    version=VERSION,
259
    license='BSD',
260
    url='http://code.grnet.gr/projects/pithos-web-client',
261
    description = SHORT_DESCRIPTION,
262
    long_description=README + '\n\n' +  CHANGES,
263
    classifiers = CLASSIFIERS,
264
    author='GRNET',
265
    author_email='pithos@grnet.gr',
266

    
267
    packages=find_packages(),
268
    include_package_data=True,
269
    package_data=find_package_data('.'),
270
    zip_safe=False,
271

    
272
    install_requires = INSTALL_REQUIRES,
273

    
274
    dependency_links = ['http://docs.dev.grnet.gr/pypi'],
275

    
276
    entry_points={
277
        'synnefo': [
278
             'web_apps = pithos_web_client.synnefo_settings:installed_apps',
279
             'urls = pithos_web_client.synnefo_settings:urlpatterns',
280
             'web_static = pithos_web_client.synnefo_settings:static_files'
281
        ]
282
    }
283
)
284