From: Kostas Papadimitriou Date: Fri, 31 May 2013 10:48:23 +0000 (+0300) Subject: Python packaging improvments X-Git-Tag: 0.14rc1~23 X-Git-Url: https://code.grnet.gr/git/pithos-web-client/commitdiff_plain/6157de5b9191596152504c72f22cd4a4a2a0de25?ds=sidebyside Python packaging improvments - Use {% include %} to extend index.html with appropriate django context - Introduce `urls_config` context variable. A dict that contains requred webapp endpoints. Keys are merged in otherProperties js object. --- diff --git a/snf-pithos-webclient/pithos_webclient/settings.py b/snf-pithos-webclient/pithos_webclient/settings.py index 683ccb6..c0f3208 100644 --- a/snf-pithos-webclient/pithos_webclient/settings.py +++ b/snf-pithos-webclient/pithos_webclient/settings.py @@ -1,13 +1,47 @@ +# Copyright 2013 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + from django.conf import settings # !!!!!ATTENTION!!!!! # loginUrl MUST end at "next=". You should not give the value of the next # parameter. It will be determined automatically LOGIN_URL = getattr(settings, 'PITHOS_UI_LOGIN_URL', - 'https://accounts.okeanos.grnet.gr/im/login?next=') + 'https://accounts.synnefo.org/astakos/im/login?next=') FEEDBACK_URL = getattr(settings, 'PITHOS_UI_FEEDBACK_URL', - 'https://accounts.okeanos.grnet.gr/im/feedback') + 'https://accounts.synnefo.org/astakos/im/feedback') AUTH_COOKIE_NAME = getattr(settings, 'PITHOS_UI_AUTH_COOKIE_NAME', - '_pithos2_a') -CLOUDBAR_ACTIVE_SERVICE = getattr(settings, 'PITHOS_UI_CLOUDBAR_ACTIVE_SERVICE', - 'pithos') + '_pithos2_a') +CLOUDBAR_ACTIVE_SERVICE = getattr(settings, + 'PITHOS_UI_CLOUDBAR_ACTIVE_SERVICE', + 'pithos') diff --git a/snf-pithos-webclient/pithos_webclient/synnefo_settings.py b/snf-pithos-webclient/pithos_webclient/synnefo_settings.py index 77c8ed0..e9997a4 100644 --- a/snf-pithos-webclient/pithos_webclient/synnefo_settings.py +++ b/snf-pithos-webclient/pithos_webclient/synnefo_settings.py @@ -51,6 +51,4 @@ from django.conf.urls.defaults import include, patterns urlpatterns = patterns('', (r'^ui/$', 'pithos_webclient.views.index'), (r'^ui/index.html$', 'pithos_webclient.views.index'), - (r'^pithos/ui/$', 'pithos_webclient.views.index'), - (r'^pithos/ui/index.html$', 'pithos_webclient.views.index') ) diff --git a/snf-pithos-webclient/pithos_webclient/templates/pithos_webclient/cloudbar.html b/snf-pithos-webclient/pithos_webclient/templates/pithos_webclient/cloudbar.html new file mode 100644 index 0000000..0449c46 --- /dev/null +++ b/snf-pithos-webclient/pithos_webclient/templates/pithos_webclient/cloudbar.html @@ -0,0 +1 @@ +{{ CLOUDBAR_CODE }} diff --git a/snf-pithos-webclient/pithos_webclient/templates/pithos_webclient/other_properties.html b/snf-pithos-webclient/pithos_webclient/templates/pithos_webclient/other_properties.html new file mode 100644 index 0000000..dd70d47 --- /dev/null +++ b/snf-pithos-webclient/pithos_webclient/templates/pithos_webclient/other_properties.html @@ -0,0 +1,7 @@ +{% for key, value in branding_settings.items %} + otherProperties.{{ key }} = "{{ value }}"; +{% endfor %} + +{% for key, value in urls_config.items %} + otherProperties.{{ key }} = "{{ value }}"; +{% endfor %} diff --git a/snf-pithos-webclient/pithos_webclient/views.py b/snf-pithos-webclient/pithos_webclient/views.py index 6b97c5f..d1fd0a9 100644 --- a/snf-pithos-webclient/pithos_webclient/views.py +++ b/snf-pithos-webclient/pithos_webclient/views.py @@ -43,15 +43,19 @@ from synnefo_branding.utils import get_branding_dict MEDIA_URL = getattr(settings, "PITHOS_WEB_CLIENT_MEDIA_URL", \ getattr(django_settings, "MEDIA_URL", "/static/")) +URLS_CONFIG = { + 'STORAGE_API_URL': '/v1', + 'USER_CATALOGS_API_URL': '/user_catalog' +} + def index(request): branding_settings = get_branding_dict("") - return direct_to_template(request, 'pithos_webclient/index.html', \ - {'settings': settings, - 'MEDIA_URL': MEDIA_URL, - 'CLIENT_VERSION': __version__, - 'PITHOS_UI_CLOUDBAR_ACTIVE_SERVICE': - settings.CLOUDBAR_ACTIVE_SERVICE, - 'branding_settings': branding_settings - }) - + return direct_to_template(request, 'pithos_webclient/index.html', { + 'settings': settings, + 'MEDIA_URL': MEDIA_URL, + 'CLIENT_VERSION': __version__, + 'PITHOS_UI_CLOUDBAR_ACTIVE_SERVICE': settings.CLOUDBAR_ACTIVE_SERVICE, + 'branding_settings': branding_settings, + 'urls_config': URLS_CONFIG + }) diff --git a/snf-pithos-webclient/setup.py b/snf-pithos-webclient/setup.py index d6fbb4c..1878c2b 100644 --- a/snf-pithos-webclient/setup.py +++ b/snf-pithos-webclient/setup.py @@ -32,6 +32,7 @@ # documentation are those of the authors and should not be # interpreted as representing official policies, either expressed # or implied, of GRNET S.A. + import distribute_setup distribute_setup.use_setuptools() @@ -59,11 +60,11 @@ PACKAGES = find_packages(PACKAGES_ROOT) # Package meta CLASSIFIERS = [ - 'Development Status :: 3 - Alpha', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Topic :: Utilities', - 'License :: OSI Approved :: BSD License', + 'Development Status :: 3 - Alpha', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Topic :: Utilities', + 'License :: OSI Approved :: BSD License', ] # Package requirements @@ -83,21 +84,24 @@ TESTS_REQUIRES = [ # of replicating them: standard_exclude = ["*.py", "*.pyc", "*$py.class", "*~", ".*", "*.bak"] standard_exclude_directories = [ - ".*", "CVS", "_darcs", "./build", "./dist", "EGG-INFO", "*.egg-info", "snf-0.7" + ".*", "CVS", "_darcs", "./build", "./dist", "EGG-INFO", "*.egg-info", + "snf-0.7" ] -# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) -# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php -# Note: you may want to copy this into your setup.py file verbatim, as -# you can't import this from another package, when you don't know if -# that package is installed yet. + +# (c) 2005 Ian Bicking and contributors; written for Paste +# (http://pythonpaste.org) Licensed under the MIT license: +# http://www.opensource.org/licenses/mit-license.php Note: you may want to +# copy this into your setup.py file verbatim, as you can't import this from +# another package, when you don't know if that package is installed yet. def find_package_data( where=".", package="", exclude=standard_exclude, exclude_directories=standard_exclude_directories, only_in_packages=True, - show_ignored=False): + show_ignored=False +): """ Return a dictionary suitable for use in ``package_data`` in a distutils ``setup.py`` file. @@ -134,7 +138,7 @@ def find_package_data( bad_name = False for pattern in exclude_directories: if (fnmatchcase(name, pattern) - or fn.lower() == pattern.lower()): + or fn.lower() == pattern.lower()): bad_name = True if show_ignored: print >> sys.stderr, ( @@ -144,20 +148,21 @@ def find_package_data( if bad_name: continue if (os.path.isfile(os.path.join(fn, "__init__.py")) - and not prefix): + and not prefix): if not package: new_package = name else: new_package = package + "." + name stack.append((fn, "", new_package, False)) else: - stack.append((fn, prefix + name + "/", package, only_in_packages)) + stack.append((fn, prefix + name + "/", package, + only_in_packages)) elif package or not only_in_packages: # is a file bad_name = False for pattern in exclude: - if (fnmatchcase(name, pattern) - or fn.lower() == pattern.lower()): + if (fnmatchcase(name, pattern) or + fn.lower() == pattern.lower()): bad_name = True if show_ignored: print >> sys.stderr, ( @@ -166,7 +171,7 @@ def find_package_data( break if bad_name: continue - out.setdefault(package, []).append(prefix+name) + out.setdefault(package, []).append(prefix + name) return out @@ -176,6 +181,7 @@ Gwt clea/build helpers import subprocess as sp import glob + def clean_gwt(root="../", public_dir="bin/www/gr.grnet.pithos.web.Pithos/"): # skip if no build.xml found (debian build process) if not os.path.exists(os.path.join(root, "build.xml")): @@ -187,19 +193,17 @@ def clean_gwt(root="../", public_dir="bin/www/gr.grnet.pithos.web.Pithos/"): if rcode == 1: raise Exception("GWT clean failed") os.chdir(curdir) - pub_dir = os.path.abspath(os.path.join(root, public_dir)) - static_dir = os.path.abspath(os.path.join("pithos_webclient", "static", \ - "pithos_webclient")) - templates_dir = os.path.abspath(os.path.join("pithos_webclient", \ - "templates", "pithos_webclient")) + #pub_dir = os.path.abspath(os.path.join(root, public_dir)) + static_dir = os.path.abspath(os.path.join("pithos_webclient", "static", + "pithos_webclient")) + #templates_dir = os.path.abspath(os.path.join("pithos_webclient", + #"templates", + #"pithos_webclient")) clean_static = ["rm", "-r"] + glob.glob(os.path.join(static_dir, "*")) - clean_templates = ["rm", "-r"] + glob.glob(os.path.join(templates_dir, "*")) # clean dirs if len(clean_static) > 2: sp.call(clean_static) - if len(clean_static) > 2: - sp.call(clean_templates) def build_gwt(root="../", public_dir="bin/www/gr.grnet.pithos.web.Pithos/"): @@ -215,46 +219,37 @@ def build_gwt(root="../", public_dir="bin/www/gr.grnet.pithos.web.Pithos/"): raise Exception("GWT build failed") os.chdir(curdir) - pub_dir = os.path.abspath(os.path.join(root, public_dir)) - static_dir = os.path.abspath(os.path.join("pithos_webclient", "static", \ - "pithos_webclient")) - templates_dir = os.path.abspath(os.path.join("pithos_webclient", \ - "templates", "pithos_webclient")) + static_dir = os.path.abspath(os.path.join("pithos_webclient", "static", + "pithos_webclient")) + templates_dir = os.path.abspath(os.path.join("pithos_webclient", + "templates", + "pithos_webclient")) clean_static = ["rm", "-r"] + glob.glob(os.path.join(static_dir, "*")) - clean_templates = ["rm", "-r"] + glob.glob(os.path.join(templates_dir, "*")) # clean dirs if len(clean_static) > 2: sp.call(clean_static) - if len(clean_static) > 2: - sp.call(clean_templates) - copy_static = ["cp", "-r"] + glob.glob(os.path.join(pub_dir, "*")) + [static_dir] + copy_static = ["cp", "-r"] + glob.glob(os.path.join(pub_dir, "*")) + \ + [static_dir] copy_index = ["cp", os.path.join(pub_dir, "index.html"), templates_dir] sp.call(copy_static) sp.call(copy_index) index = os.path.join(templates_dir, "index.html") index_data = file(index).read() - index_data = index_data.replace('href="', 'href="{{ MEDIA_URL }}pithos_webclient/') - index_data = index_data.replace('" src="', '" src="{{ MEDIA_URL }}pithos_webclient/') - index_data = index_data.replace('\' src=\'', '\' src=\'{{ MEDIA_URL }}pithos_webclient/') - index_data = index_data.replace('url(', 'url({{ MEDIA_URL }}pithos_webclient/') - - index_data = index_data.replace("{{ CLOUDBAR_CODE }}", """ - {{ CLOUDBAR_CODE }} - - """) - - index_data = index_data.replace("{{ EXTEND_OTHER_PROPERTIES }}", """ - {% for key, value in branding_settings.items %} - otherProperties.{{ key }} = "{{ value }}"; - {% endfor %} - """) + # fix locations of static files + index_data = index_data.replace('href="', + 'href="{{ MEDIA_URL }}pithos_webclient/') + index_data = index_data.replace('" src="', + '" src="{{ MEDIA_URL }}pithos_webclient/') + index_data = index_data.replace( + '\' src=\'', + '\' src=\'{{ MEDIA_URL }}pithos_webclient/') + index_data = index_data.replace('url(', + 'url({{ MEDIA_URL }}pithos_webclient/') ifile = file(index, "w+") ifile.write(index_data) @@ -262,7 +257,8 @@ def build_gwt(root="../", public_dir="bin/www/gr.grnet.pithos.web.Pithos/"): # do we need to run ant ??? -if any(x in ''.join(sys.argv) for x in ["sdist", "build", "develop", "install"]): +if any(x in ''.join(sys.argv) for x in ["sdist", "build", "develop", + "install"]): build_gwt() if any(x in ''.join(sys.argv) for x in ["clean"]): @@ -274,9 +270,9 @@ setup( version=VERSION, license='BSD', url='http://code.grnet.gr/projects/pithos-web-client', - description = SHORT_DESCRIPTION, - long_description=README + '\n\n' + CHANGES, - classifiers = CLASSIFIERS, + description=SHORT_DESCRIPTION, + long_description=README + '\n\n' + CHANGES, + classifiers=CLASSIFIERS, author='GRNET', author_email='pithos@grnet.gr', @@ -285,17 +281,17 @@ setup( package_data=find_package_data('.'), zip_safe=False, - install_requires = INSTALL_REQUIRES, + install_requires=INSTALL_REQUIRES, - dependency_links = ['http://docs.dev.grnet.gr/pypi'], + dependency_links=['http://docs.dev.grnet.gr/pypi'], entry_points={ 'synnefo': [ - 'web_apps = pithos_webclient.synnefo_settings:installed_apps', - 'urls = pithos_webclient.synnefo_settings:urlpatterns', - 'web_static = pithos_webclient.synnefo_settings:static_files', - 'web_context_processors = pithos_webclient.synnefo_settings:context_processors' + 'web_apps = pithos_webclient.synnefo_settings:installed_apps', + 'urls = pithos_webclient.synnefo_settings:urlpatterns', + 'web_static = pithos_webclient.synnefo_settings:static_files', + 'web_context_processors = ' + 'pithos_webclient.synnefo_settings:context_processors' ] } ) - diff --git a/src/gr/grnet/pithos/web/public/index.html b/src/gr/grnet/pithos/web/public/index.html index 6dbe606..e6cd74c 100644 --- a/src/gr/grnet/pithos/web/public/index.html +++ b/src/gr/grnet/pithos/web/public/index.html @@ -55,8 +55,7 @@ - {{ CLOUDBAR_CODE }} - + {% include "pithos_webclient/cloudbar.html" %}