tpl prj
authorOlivier Larchevêque <olivier.larcheveque@auf.org>
Thu, 12 Sep 2013 18:21:50 +0000 (14:21 -0400)
committerOlivier Larchevêque <olivier.larcheveque@auf.org>
Thu, 12 Sep 2013 18:21:50 +0000 (14:21 -0400)
14 files changed:
LICENSE.txt [new file with mode: 0644]
README.rst [new file with mode: 0644]
bin/django.wsgi [new file with mode: 0755]
deploy.py [new file with mode: 0644]
project_name/__init__.py [new file with mode: 0644]
project_name/manage.py [new file with mode: 0644]
project_name/settings/__init__.py [new file with mode: 0644]
project_name/settings/base.py [new file with mode: 0644]
project_name/settings/development.py [new file with mode: 0644]
project_name/settings/production.py [new file with mode: 0644]
requirements.txt [new file with mode: 0644]
requirements/development.txt [new file with mode: 0644]
requirements/production.txt [new file with mode: 0644]
requirements/wheezy.txt [new file with mode: 0644]

diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/README.rst b/README.rst
new file mode 100644 (file)
index 0000000..a6e38f6
--- /dev/null
@@ -0,0 +1,16 @@
+Démarrage d'un nouveau projet
+=============================
+
+* django-admin.py startproject <nom du projet> --template=
+
+* (optionnel) configurer les versions de PYTHON au besoin dans :
+   ./deploy.py
+   ./bin/django.wsgi
+
+* git init
+
+* git add remote.origin.url <url du dépôt git>
+
+* git push origin master
+
+
diff --git a/bin/django.wsgi b/bin/django.wsgi
new file mode 100755 (executable)
index 0000000..9ebb28b
--- /dev/null
@@ -0,0 +1,47 @@
+#! .virtualenv/bin/python
+
+import os
+import sys
+import site
+
+PYTHON = "python2.6"
+
+os.environ['DJANGO_SETTINGS_MODULE'] = '{{ project_name }}.production'
+
+ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
+VENV_DIR = os.path.join(ROOT_DIR, '.virtualenv')
+VENV_PKG_DIR = os.path.join(VENV_DIR, 'lib', PYTHON, 'site-packages')
+
+sys.path.append(os.path.join(
+    ROOT_DIR,
+    '{{ project_name }}',
+    '{{ project_name }}')
+    )
+
+# extra site-packages
+PATHS = (
+    VENV_PKG_DIR,
+)
+
+# Remember original sys.path.
+prev_sys_path = list(sys.path)
+
+# Add each new site-packages directory.
+for directory in PATHS:
+    site.addsitedir(directory)
+
+# Reorder sys.path so new directories at the front.
+new_sys_path = []
+for item in list(sys.path):
+    if item not in prev_sys_path:
+        new_sys_path.append(item)
+        sys.path.remove(item)
+sys.path[:0] = new_sys_path
+
+from django.core.handlers.wsgi import WSGIHandler
+application = WSGIHandler()
+try:
+    from raven.contrib.django.middleware.wsgi import Sentry
+    application = Sentry(application)
+except:
+    pass
diff --git a/deploy.py b/deploy.py
new file mode 100644 (file)
index 0000000..ad1d214
--- /dev/null
+++ b/deploy.py
@@ -0,0 +1,61 @@
+# -*- coding: utf-8 -*-
+
+import os
+import subprocess
+from pkg_resources import parse_version
+
+PYTHON = "python2.6"
+ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
+VENV_DIR = os.path.join(ROOT_DIR, '.virtualenv')
+
+
+def shell_exec(cmd):
+    """
+    Run blocked shell command.
+    """
+    sp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
+    sp.wait()
+    out = sp.stdout.read().replace('\n', '')
+    return out
+
+
+def setup_venv():
+    """
+    Virtualenv setup.
+    """
+    venv_version = shell_exec("virtualenv --version")
+    venv_options = ["virtualenv", VENV_DIR, ]
+
+    if parse_version(venv_version) >= parse_version('1.7'):
+        venv_options.append("--system-site-packages", "--python=%s" % PYTHON)
+    venv_create = " ".join(venv_options)
+
+    if not os.path.exists(VENV_DIR):
+        print u"VirtualEnv creation."
+        shell_exec(venv_create)
+        cleanup()
+    else:
+        print u"VirtualEnv already exists. Nothing to do."
+
+
+def setup_dependances():
+    print u"Deps installation"
+    shell_exec(
+        "%s/bin/pip install -r %s/requirements.txt" %
+        (VENV_DIR, ROOT_DIR)
+        )
+
+
+def cleanup():
+    """
+    Do some cleanup stuff after setup.
+    """
+    for f in os.listdir(ROOT_DIR):
+        if f.startswith('distribute'):
+            os.remove(f)
+
+
+if __name__ == "__main__":
+    setup_venv()
+    setup_dependances()
+    cleanup()
diff --git a/project_name/__init__.py b/project_name/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/project_name/manage.py b/project_name/manage.py
new file mode 100644 (file)
index 0000000..a6f5a1e
--- /dev/null
@@ -0,0 +1,9 @@
+import os
+import sys
+
+sys.path.append(os.path.abspath(os.path.dirname(__file__)))
+
+if __name__ == "__main__":
+    from django.core.management import execute_from_command_line
+    execute_from_command_line(sys.argv)
+
diff --git a/project_name/settings/__init__.py b/project_name/settings/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/project_name/settings/base.py b/project_name/settings/base.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/project_name/settings/development.py b/project_name/settings/development.py
new file mode 100644 (file)
index 0000000..3cd5377
--- /dev/null
@@ -0,0 +1,7 @@
+# -*- coding: utf-8 -*-
+
+from base import *  # NOQA
+
+INTERNAL_IPS = ('127.0.0.1',)
+INSTALLED_APPS += ('debug_toolbar',)
+MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
diff --git a/project_name/settings/production.py b/project_name/settings/production.py
new file mode 100644 (file)
index 0000000..9c1ace3
--- /dev/null
@@ -0,0 +1,8 @@
+# -*- 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 base import *  # NOQA
diff --git a/requirements.txt b/requirements.txt
new file mode 100644 (file)
index 0000000..ea77c2d
--- /dev/null
@@ -0,0 +1 @@
+-r requirements/production.txt
diff --git a/requirements/development.txt b/requirements/development.txt
new file mode 100644 (file)
index 0000000..d7f1e2f
--- /dev/null
@@ -0,0 +1 @@
+-r production.txt
diff --git a/requirements/production.txt b/requirements/production.txt
new file mode 100644 (file)
index 0000000..f9b5d7b
--- /dev/null
@@ -0,0 +1 @@
+-r wheezy.txt
diff --git a/requirements/wheezy.txt b/requirements/wheezy.txt
new file mode 100644 (file)
index 0000000..5936dcf
--- /dev/null
@@ -0,0 +1 @@
+Django==1.4.5