Clean gwt project on python setup.py clean
[pithos-web-client] / snf-pithos-web-client / setup.py
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     # skip if no build.xml found (debian build process)
186     if not os.path.exists(os.path.join(root, "build.xml")):
187         return
188
189     curdir = os.getcwd()
190     os.chdir(root)
191     rcode = sp.call(["ant", "clean"])
192     if rcode == 1:
193         raise Exception("GWT clean failed")
194     os.chdir(curdir)
195     pub_dir = os.path.abspath(os.path.join(root, public_dir))
196     static_dir = os.path.abspath(os.path.join("pithos_web_client", "static", \
197         "pithos_web_client"))
198     templates_dir = os.path.abspath(os.path.join("pithos_web_client", \
199         "templates", "pithos_web_client"))
200     clean_static = ["rm", "-r"] + glob.glob(os.path.join(static_dir, "*"))
201     clean_templates = ["rm", "-r"] + glob.glob(os.path.join(templates_dir, "*"))
202
203     # clean dirs
204     if len(clean_static) > 2:
205         sp.call(clean_static)
206     if len(clean_static) > 2:
207         sp.call(clean_templates)
208
209
210 def build_gwt(root="../", public_dir="bin/www/gr.grnet.pithos.web.Pithos/"):
211     # skip if no build.xml found (debian build process)
212     if not os.path.exists(os.path.join(root, "build.xml")):
213         return
214
215     curdir = os.getcwd()
216     os.chdir(root)
217     # run ant on root dir
218     rcode = sp.call(["ant"])
219     if rcode == 1:
220         raise Exception("GWT build failed")
221     os.chdir(curdir)
222
223
224     pub_dir = os.path.abspath(os.path.join(root, public_dir))
225     static_dir = os.path.abspath(os.path.join("pithos_web_client", "static", \
226         "pithos_web_client"))
227     templates_dir = os.path.abspath(os.path.join("pithos_web_client", \
228         "templates", "pithos_web_client"))
229
230     clean_static = ["rm", "-r"] + glob.glob(os.path.join(static_dir, "*"))
231     clean_templates = ["rm", "-r"] + glob.glob(os.path.join(templates_dir, "*"))
232
233     # clean dirs
234     if len(clean_static) > 2:
235         sp.call(clean_static)
236     if len(clean_static) > 2:
237         sp.call(clean_templates)
238
239     copy_static = ["cp", "-r"] + glob.glob(os.path.join(pub_dir, "*")) + [static_dir]
240     copy_index = ["cp", os.path.join(pub_dir, "index.html"), templates_dir]
241     sp.call(copy_static)
242     sp.call(copy_index)
243
244     index = os.path.join(templates_dir, "index.html")
245     index_data = file(index).read()
246     index_data = index_data.replace('href="', 'href="{{ MEDIA_URL }}pithos_web_client/')
247     index_data = index_data.replace('" src="', '" src="{{ MEDIA_URL }}pithos_web_client/')
248     index_data = index_data.replace('\' src=\'', '\' src=\'{{ MEDIA_URL }}pithos_web_client/')
249     index_data = index_data.replace('url(', 'url({{ MEDIA_URL }}pithos_web_client/')
250
251     ifile = file(index, "w+")
252     ifile.write(index_data)
253     ifile.close()
254
255
256 # do we need to run ant ???
257 if any(x in ''.join(sys.argv) for x in ["sdist", "build", "develop", "install"]):
258     build_gwt()
259
260 if any(x in ''.join(sys.argv) for x in ["clean"]):
261     clean_gwt()
262
263
264 setup(
265     name='snf-pithos-web-client',
266     version=VERSION,
267     license='BSD',
268     url='http://code.grnet.gr/projects/pithos-web-client',
269     description = SHORT_DESCRIPTION,
270     long_description=README + '\n\n' +  CHANGES,
271     classifiers = CLASSIFIERS,
272     author='GRNET',
273     author_email='pithos@grnet.gr',
274
275     packages=find_packages(),
276     include_package_data=True,
277     package_data=find_package_data('.'),
278     zip_safe=False,
279
280     install_requires = INSTALL_REQUIRES,
281
282     dependency_links = ['http://docs.dev.grnet.gr/pypi'],
283
284     entry_points={
285         'synnefo': [
286              'web_apps = pithos_web_client.synnefo_settings:installed_apps',
287              'urls = pithos_web_client.synnefo_settings:urlpatterns',
288              'web_static = pithos_web_client.synnefo_settings:static_files',
289              'web_context_processors = pithos_web_client.synnefo_settings:context_processors'
290         ]
291     }
292 )
293