Statistics
| Branch: | Tag: | Revision:

root / snf-pithos-webclient / setup.py @ 862ad222

History | View | Annotate | Download (10 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

    
36
import distribute_setup
37
distribute_setup.use_setuptools()
38

    
39
import os
40
import sys
41

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

    
45
from setuptools import setup, find_packages
46

    
47

    
48
HERE = os.path.abspath(os.path.normpath(os.path.dirname(__file__)))
49

    
50
from pithos_webclient.version import __version__
51

    
52
# Package info
53
VERSION = __version__
54
README = open(os.path.join(HERE, 'README')).read()
55
CHANGES = open(os.path.join(HERE, 'Changelog')).read()
56
SHORT_DESCRIPTION = 'Package short description'
57

    
58
PACKAGES_ROOT = '.'
59
PACKAGES = find_packages(PACKAGES_ROOT)
60

    
61
# Package meta
62
CLASSIFIERS = [
63
    'Development Status :: 3 - Alpha',
64
    'Operating System :: OS Independent',
65
    'Programming Language :: Python',
66
    'Topic :: Utilities',
67
    'License :: OSI Approved :: BSD License',
68
]
69

    
70
# Package requirements
71
INSTALL_REQUIRES = [
72
    'Django>=1.2, <1.3',
73
    'snf-branding',
74
    'snf-common>=0.9.0rc'
75
]
76

    
77
EXTRAS_REQUIRES = {
78
}
79

    
80
TESTS_REQUIRES = [
81
]
82

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

    
91

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

109
    The dictionary looks like::
110

111
        {"package": [files]}
112

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

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

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

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

128
    Note patterns use wildcards, or can be exact paths (including
129
    leading ``./``), and all searching is case-insensitive.
130
    """
131
    out = {}
132
    stack = [(convert_path(where), "", package, only_in_packages)]
133
    while stack:
134
        where, prefix, package, only_in_packages = stack.pop(0)
135
        for name in os.listdir(where):
136
            fn = os.path.join(where, name)
137
            if os.path.isdir(fn):
138
                bad_name = False
139
                for pattern in exclude_directories:
140
                    if (fnmatchcase(name, pattern)
141
                            or fn.lower() == pattern.lower()):
142
                        bad_name = True
143
                        if show_ignored:
144
                            print >> sys.stderr, (
145
                                "Directory %s ignored by pattern %s"
146
                                % (fn, pattern))
147
                        break
148
                if bad_name:
149
                    continue
150
                if (os.path.isfile(os.path.join(fn, "__init__.py"))
151
                        and not prefix):
152
                    if not package:
153
                        new_package = name
154
                    else:
155
                        new_package = package + "." + name
156
                    stack.append((fn, "", new_package, False))
157
                else:
158
                    stack.append((fn, prefix + name + "/", package,
159
                                  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) or
165
                            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

    
185
def clean_gwt(root="../", public_dir="bin/www/gr.grnet.pithos.web.Pithos/"):
186
    # skip if no build.xml found (debian build process)
187
    if not os.path.exists(os.path.join(root, "build.xml")):
188
        return
189

    
190
    curdir = os.getcwd()
191
    os.chdir(root)
192
    rcode = sp.call(["ant", "clean"])
193
    if rcode == 1:
194
        raise Exception("GWT clean failed")
195
    os.chdir(curdir)
196
    #pub_dir = os.path.abspath(os.path.join(root, public_dir))
197
    static_dir = os.path.abspath(os.path.join("pithos_webclient", "static",
198
                                              "pithos_webclient"))
199
    #templates_dir = os.path.abspath(os.path.join("pithos_webclient",
200
                                                 #"templates",
201
                                                 #"pithos_webclient"))
202
    clean_static = ["rm", "-r"] + glob.glob(os.path.join(static_dir, "*"))
203

    
204
    # clean dirs
205
    if len(clean_static) > 2:
206
        sp.call(clean_static)
207

    
208

    
209
def build_gwt(root="../", public_dir="bin/www/gr.grnet.pithos.web.Pithos/"):
210
    # skip if no build.xml found (debian build process)
211
    if not os.path.exists(os.path.join(root, "build.xml")):
212
        return
213

    
214
    curdir = os.getcwd()
215
    os.chdir(root)
216
    # run ant on root dir
217
    rcode = sp.call(["ant"])
218
    if rcode == 1:
219
        raise Exception("GWT build failed")
220
    os.chdir(curdir)
221

    
222
    pub_dir = os.path.abspath(os.path.join(root, public_dir))
223
    static_dir = os.path.abspath(os.path.join("pithos_webclient", "static",
224
                                              "pithos_webclient"))
225
    templates_dir = os.path.abspath(os.path.join("pithos_webclient",
226
                                                 "templates",
227
                                                 "pithos_webclient"))
228

    
229
    clean_static = ["rm", "-r"] + glob.glob(os.path.join(static_dir, "*"))
230

    
231
    # clean dirs
232
    if len(clean_static) > 2:
233
        sp.call(clean_static)
234

    
235
    copy_static = ["cp", "-r"] + glob.glob(os.path.join(pub_dir, "*")) + \
236
                  [static_dir]
237
    copy_index = ["cp", os.path.join(pub_dir, "index.html"), templates_dir]
238
    sp.call(copy_static)
239
    sp.call(copy_index)
240

    
241
    index = os.path.join(templates_dir, "index.html")
242
    index_data = file(index).read()
243
    # fix locations of static files
244
    index_data = index_data.replace('href="',
245
                                    'href="{{ MEDIA_URL }}pithos_webclient/')
246
    index_data = index_data.replace('" src="',
247
                                    '" src="{{ MEDIA_URL }}pithos_webclient/')
248
    index_data = index_data.replace(
249
        '\' src=\'',
250
        '\' src=\'{{ MEDIA_URL }}pithos_webclient/')
251
    index_data = index_data.replace('url(',
252
                                    'url({{ MEDIA_URL }}pithos_webclient/')
253

    
254
    ifile = file(index, "w+")
255
    ifile.write(index_data)
256
    ifile.close()
257

    
258

    
259
# do we need to run ant ???
260
if any(x in ''.join(sys.argv) for x in ["sdist", "build", "develop",
261
                                        "install"]):
262
    build_gwt()
263

    
264
if any(x in ''.join(sys.argv) for x in ["clean"]):
265
    clean_gwt()
266

    
267

    
268
setup(
269
    name='snf-pithos-webclient',
270
    version=VERSION,
271
    license='BSD',
272
    url='http://code.grnet.gr/projects/pithos-web-client',
273
    description=SHORT_DESCRIPTION,
274
    long_description=README + '\n\n' + CHANGES,
275
    classifiers=CLASSIFIERS,
276
    author='GRNET',
277
    author_email='pithos@grnet.gr',
278

    
279
    packages=find_packages(),
280
    include_package_data=True,
281
    package_data=find_package_data('.'),
282
    zip_safe=False,
283

    
284
    install_requires=INSTALL_REQUIRES,
285

    
286
    dependency_links=['http://docs.dev.grnet.gr/pypi'],
287

    
288
    entry_points={
289
        'synnefo': [
290
            'web_apps = pithos_webclient.synnefo_settings:installed_apps',
291
            'urls = pithos_webclient.urls:urlpatterns',
292
            'web_static = pithos_webclient.synnefo_settings:static_files',
293
            'web_context_processors = '
294
            'pithos_webclient.synnefo_settings:context_processors'
295
        ]
296
    }
297
)