From 7751bc4700427dd1bf1ee66870b37e377add1ff2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Larchev=C3=AAque?= Date: Tue, 24 Jul 2012 12:10:37 -0400 Subject: [PATCH] boostrap --- .gitignore | 31 +++++++++++++++++++ bootstrap.py | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ buildout.cfg | 25 ++++++++++++++++ devel.cfg | 9 ++++++ project/conf.py.edit | 13 ++++++++ project/dashboard.py | 27 +++++++++++++++++ project/development.py | 13 ++++++++ project/mysql_ram.py | 47 +++++++++++++++++++++++++++++ project/production.py | 9 ++++++ project/settings.py | 62 ++++++++++++++++++++++++++++++++++++++ project/urls.py | 27 +++++++++++++++++ versions.cfg | 20 +++++++++++++ 12 files changed, 360 insertions(+) create mode 100644 .gitignore create mode 100644 bootstrap.py create mode 100644 buildout.cfg create mode 100644 devel.cfg create mode 100644 project/__init__.py create mode 100644 project/conf.py.edit create mode 100644 project/dashboard.py create mode 100644 project/development.py create mode 100644 project/mysql_ram.py create mode 100644 project/production.py create mode 100644 project/settings.py create mode 100644 project/urls.py create mode 100644 versions.cfg diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c8c4403 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +# binaires +*.pyc +*.pyo + +# Fichier temporaires: +.*.swp +*~ +\#*# +src/* + +# DB de dev +*.db + +# restants de merge +*.orig +*.rej + +# Configuration du projet - par environnement +conf.py +django.wsgi + +# buildout +.installed.cfg +bin +develop-eggs +downloads +eggs +log +parts +tmp +sitestatic diff --git a/bootstrap.py b/bootstrap.py new file mode 100644 index 0000000..7728587 --- /dev/null +++ b/bootstrap.py @@ -0,0 +1,77 @@ +############################################################################## +# +# Copyright (c) 2006 Zope Corporation and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## +"""Bootstrap a buildout-based project + +Simply run this script in a directory containing a buildout.cfg. +The script accepts buildout command-line options, so you can +use the -c option to specify an alternate configuration file. + +$Id$ +""" + +import os, shutil, sys, tempfile, urllib2 + +tmpeggs = tempfile.mkdtemp() + +is_jython = sys.platform.startswith('java') + +try: + import pkg_resources +except ImportError: + ez = {} + exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py' + ).read() in ez + ez['use_setuptools'](to_dir=tmpeggs, download_delay=0) + + import pkg_resources + +if sys.platform == 'win32': + def quote(c): + if ' ' in c: + return '"%s"' % c # work around spawn lamosity on windows + else: + return c +else: + def quote (c): + return c + +cmd = 'from setuptools.command.easy_install import main; main()' +ws = pkg_resources.working_set + +if is_jython: + import subprocess + + assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd', + quote(tmpeggs), 'zc.buildout'], + env=dict(os.environ, + PYTHONPATH= + ws.find(pkg_resources.Requirement.parse('setuptools')).location + ), + ).wait() == 0 + +else: + assert os.spawnle( + os.P_WAIT, sys.executable, quote (sys.executable), + '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout', + dict(os.environ, + PYTHONPATH= + ws.find(pkg_resources.Requirement.parse('setuptools')).location + ), + ) == 0 + +ws.add_entry(tmpeggs) +ws.require('zc.buildout') +import zc.buildout.buildout +zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap']) +shutil.rmtree(tmpeggs) diff --git a/buildout.cfg b/buildout.cfg new file mode 100644 index 0000000..8801c03 --- /dev/null +++ b/buildout.cfg @@ -0,0 +1,25 @@ + +[buildout] +extends = versions.cfg +extensions = buildout-versions +buildout_versions_file = versions.cfg +versions = versions +unzip = true +parts = django +versions = versions + +find-links = http://pypi.auf.org/simple/auf.recipe.django + +eggs = + auf.recipe.django + django + south + django-admin-tools + +[django] +recipe = auf.recipe.django +wsgi=true +settings=production +project = project +extra-paths = project +eggs = ${buildout:eggs} diff --git a/devel.cfg b/devel.cfg new file mode 100644 index 0000000..dfece77 --- /dev/null +++ b/devel.cfg @@ -0,0 +1,9 @@ +[buildout] +extends=buildout.cfg + +[django] +wsgi=false +settings=development +eggs = ${buildout:eggs} + django-debug-toolbar + diff --git a/project/__init__.py b/project/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/project/conf.py.edit b/project/conf.py.edit new file mode 100644 index 0000000..023d8de --- /dev/null +++ b/project/conf.py.edit @@ -0,0 +1,13 @@ +# -*- encoding: utf-8 -* + +DATABASES = { + 'default': { + #'ENGINE': 'django.db.backends.mysql', + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': 'db.sqlite', + 'USER': '', + 'PASSWORD': '', + 'HOST': '', + 'PORT': '', + } +} diff --git a/project/dashboard.py b/project/dashboard.py new file mode 100644 index 0000000..649674a --- /dev/null +++ b/project/dashboard.py @@ -0,0 +1,27 @@ +# -*- encoding: utf-8 -* + +from django.utils.translation import ugettext_lazy as _ +from admin_tools.dashboard import modules, Dashboard + + +class CustomIndexDashboard(Dashboard): + """ + Custom index dashboard + """ + + def init_with_context(self, context): + + # append an app list module for "Applications" + self.children.append(modules.AppList( + _('Applications'), + exclude=('django.contrib.*',), + )) + + # append an app list module for "Administration" + self.children.append(modules.AppList( + _('Administration'), + models=('django.contrib.*',), + )) + + # append a recent actions module + self.children.append(modules.RecentActions(_('Recent Actions'), 5)) diff --git a/project/development.py b/project/development.py new file mode 100644 index 0000000..ce0c0f8 --- /dev/null +++ b/project/development.py @@ -0,0 +1,13 @@ +# -*- encoding: utf-8 -*- + +from project.settings import * +DEBUG=True +TEMPLATE_DEBUG=DEBUG + +# Décommentez ces lignes pour activer la debugtoolbar +#INTERNAL_IPS = ('127.0.0.1',) +#INSTALLED_APPS += ('debug_toolbar',) +#MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',) + +AUTH_PASSWORD_REQUIRED = False + diff --git a/project/mysql_ram.py b/project/mysql_ram.py new file mode 100644 index 0000000..71e73e4 --- /dev/null +++ b/project/mysql_ram.py @@ -0,0 +1,47 @@ +#encoding UTF-8 +# -*- encoding: utf-8 -*- + +""" +Configuration du site pour faire fonctionner les tests unitaires avec +MySQL en RAM. +""" + +from production import * + +DATABASES['default']['HOST'] = '/var/run/mysqld/mysqld-ram.sock' + +host = "mysql --socket=%s -uroot -e" % DATABASES['default']['HOST'] +db = "unittests_%s" % DATABASES['default']['NAME'] +DATABASES['default']['NAME'] = db +DATABASES['default']['TEST_NAME'] = db +user = DATABASES['default']['USER'] +pwd = DATABASES['default']['PASSWORD'] + +cmd_creer_bd = "%(host)s \ + 'CREATE DATABASE %(db)s;'" % { + 'host': host, + 'db': db, + } + +cmd_creer_user = """%(host)s \ + "GRANT USAGE ON *.* TO %(user)s@localhost \ + IDENTIFIED BY '%(pwd)s';" """ % { + 'host': host, + 'user': user, + 'pwd': pwd, + } + +cmd_creer_privileges = "%(host)s \ + 'GRANT ALL PRIVILEGES ON *.* TO %(user)s@localhost ;'" % { + 'host': host, + 'user': user, + } + + +# La bd non préfixée par "test_" a besoin d'exister pour lancer les tests. +# Cette commande ne modifie rien, si la table existe déjà. +os.system(cmd_creer_bd) + +# Création de l'accès à la base "test_xxx" en fonction de conf.py +os.system(cmd_creer_user) +os.system(cmd_creer_privileges) diff --git a/project/production.py b/project/production.py new file mode 100644 index 0000000..ee6bb2e --- /dev/null +++ b/project/production.py @@ -0,0 +1,9 @@ +# -*- encoding: utf-8 -*- + +# En production, rediriger la sortie terminal on disponible en WSGI +# vers la sortie fichier errorlog. +import sys +sys.stdout = sys.stderr + +from project.settings import * + diff --git a/project/settings.py b/project/settings.py new file mode 100644 index 0000000..a8b2ac5 --- /dev/null +++ b/project/settings.py @@ -0,0 +1,62 @@ +# -*- encoding: utf-8 -*- + +import os +import socket +from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as \ + DEFAULT_TEMPLATE_CONTEXT_PROCESSORS + +# Rapports d'erreurs +SERVER_EMAIL = 'ne-pas-repondre@auf.org' +EMAIL_SUBJECT_PREFIX = '[IFGU - %s] ' % socket.gethostname() +ADMINS = ( + ('Équipe ARI-SI', 'developpeurs@ca.auf.org'), +) + +MANAGERS = ADMINS + +TIME_ZONE = 'America/Montreal' + +LANGUAGE_CODE = 'fr-ca' + +PROJECT_ROOT = os.path.dirname(__file__) +SITE_ROOT = os.path.dirname(PROJECT_ROOT) + +MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media') +MEDIA_URL = '/media/' + +STATIC_ROOT = os.path.join(SITE_ROOT, 'sitestatic') +STATIC_URL = '/static/' +STATICFILES_DIRS = ( + os.path.join(PROJECT_ROOT, 'static'), +) + +ROOT_URLCONF = 'project.urls' + +INSTALLED_APPS = ( + 'admin_tools', + 'admin_tools.theming', + 'admin_tools.menu', + 'admin_tools.dashboard', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.admin', + 'django.contrib.staticfiles', + 'south', +) + +TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_TEMPLATE_CONTEXT_PROCESSORS + ( + 'django.core.context_processors.static', + 'django.core.context_processors.request', +) + + +TEMPLATE_DIRS = ( + os.path.join(os.path.dirname(__file__), "templates"), +) + +SOUTH_TESTS_MIGRATE = False + +ADMIN_TOOLS_INDEX_DASHBOARD = 'project.dashboard.CustomIndexDashboard' + +from conf import * diff --git a/project/urls.py b/project/urls.py new file mode 100644 index 0000000..c29c8f2 --- /dev/null +++ b/project/urls.py @@ -0,0 +1,27 @@ +# -*- encoding: utf-8 -* + +from django.conf.urls.defaults import patterns, include, \ + handler500, handler404, url +from django.conf import settings +from django.contrib import admin +from django.contrib.staticfiles.urls import staticfiles_urlpatterns + +admin.autodiscover() + +handler404 +handler500 # Pyflakes + +urlpatterns = patterns( + '', + # admin + url(r'^admin_tools/', include('admin_tools.urls')), + (r'^admin/', include(admin.site.urls)), +) + +if settings.DEBUG: + urlpatterns += staticfiles_urlpatterns() + urlpatterns += patterns('', + url(r'^media/(?P.*)$', + 'django.views.static.serve', { + 'document_root': settings.MEDIA_ROOT, }), + ) diff --git a/versions.cfg b/versions.cfg new file mode 100644 index 0000000..9fe715a --- /dev/null +++ b/versions.cfg @@ -0,0 +1,20 @@ +[versions] +Django = 1.3.1 +django-admin-tools = 0.4.1 + +# Added by Buildout Versions at 2012-07-24 12:06:10.908373 +South = 0.7.5 +auf.recipe.django = 2.0 +buildout-versions = 1.7 +django-debug-toolbar = 0.9.4 +djangorecipe = 1.2.1 + +# Required by: +# auf.recipe.django==2.0 +# djangorecipe==1.2.1 +zc.buildout = 1.5.2 + +# Required by: +# auf.recipe.django==2.0 +# djangorecipe==1.2.1 +zc.recipe.egg = 1.3.2 -- 1.7.10.4