Moves all custom logic to playdohlib for easy upgrades (issue 29)

This commit is contained in:
Kumar McMillan 2011-04-27 00:59:52 -05:00
Родитель 3d832593cb
Коммит a63674e4e5
15 изменённых файлов: 161 добавлений и 104 удалений

Просмотреть файл

@ -4,7 +4,7 @@ import shutil
from django.conf import settings
import test_utils
import manage
from playdohlib import manage
class AcceptedLocalesTest(test_utils.TestCase):

Просмотреть файл

@ -1,10 +1,10 @@
import re
from os import listdir
from os.path import join, dirname
from os.path import join
import test_utils
import manage
from playdohlib import manage
class MigrationTests(test_utils.TestCase):

Просмотреть файл

95
apps/playdohlib/manage.py Normal file
Просмотреть файл

@ -0,0 +1,95 @@
#!/usr/bin/env python
import logging
import os
import site
import sys
current_settings = None
execute_manager = None
log = logging.getLogger(__name__)
ROOT = None
def path(*a):
return os.path.join(ROOT, *a)
def setup_environ(manage_file, settings=None):
"""Sets up a Django app within a manage.py file.
Keyword Arguments
**settings**
An imported settings module. Without this, playdoh tries to import
these modules (in order): settings_local, settings
"""
# sys is global to avoid undefined local
global sys, current_settings, execute_manager, ROOT
ROOT = os.path.dirname(os.path.abspath(manage_file))
# Adjust the python path and put local packages in front.
prev_sys_path = list(sys.path)
# Make settings_local importable
sys.path.append(os.getcwd())
site.addsitedir(path('apps'))
site.addsitedir(path('lib'))
# Local (project) vendor library
site.addsitedir(path('vendor-local'))
site.addsitedir(path('vendor-local/lib/python'))
# Global (upstream) vendor library
site.addsitedir(path('vendor'))
site.addsitedir(path('vendor/lib/python'))
# Move the new items to the front of sys.path. (via virtualenv)
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.management import execute_manager, setup_environ
if not settings:
try:
import settings_local as settings
except ImportError:
try:
import settings
except ImportError:
import sys
sys.stderr.write(
"Error: Tried importing 'settings_local.py' and "
"'settings.py' but neither could be found (or they're "
"throwing an ImportError)."
" Please come back and try again later.")
raise
current_settings = settings
# If we want to use django settings anywhere, we need to set up the
# required environment variables.
setup_environ(settings)
# Monkey-patch django forms to avoid having to use Jinja2's |safe
# everywhere.
import safe_django_forms
safe_django_forms.monkeypatch()
# Configure Celery (optional)
try:
import djcelery
except ImportError, exc:
log.warning('%s (playdoh did not initialize djcelery)' % exc)
else:
djcelery.setup_loader()
def main():
execute_manager(current_settings)

Просмотреть файл

Просмотреть файл

@ -0,0 +1,7 @@
MySQL-python==1.2.3c1
Jinja2==2.5.5
# for bcrypt passwords
hmac==20101005
hashlib==20081119
py-bcrypt==0.2

Просмотреть файл

@ -0,0 +1,16 @@
# This file pulls in everything a developer needs. If it's a basic package
# needed to run the site, it belongs in requirements/prod.txt. If it's a
# package for developers (testing, docs, etc.), it goes in this file.
-r prod.txt
# Documentation
Sphinx==1.0.6
# Testing
nose==1.0.0
-e git://github.com/jbalogh/django-nose.git#egg=django_nose
-e git://github.com/jbalogh/test-utils.git#egg=test-utils
# L10n
translate-toolkit==1.8.0

Просмотреть файл

@ -0,0 +1,24 @@
# Django stuff
-e git://github.com/django/django@36c82ac8#egg=django
# Templates
-e git://github.com/jbalogh/jingo.git#egg=jingo
-e git://github.com/jsocol/jingo-minify.git#egg=jingo-minify
GitPython==0.1.7
# Various tidbits
-e git://github.com/jsocol/commonware.git#egg=commonware
-e git://github.com/mozilla/nuggets.git#egg=nuggets
# Security
-e git://github.com/fwenzel/django-sha2.git#egg=django-sha2
-e git://github.com/jsocol/bleach.git#egg=bleach
# Celery: Message queue
celery
django-celery
# L10n
Babel>=0.9.4
-e git://github.com/clouserw/tower.git#egg=tower
-e git://github.com/fwenzel/django-mozilla-product-details#egg=django-mozilla-product-details

Просмотреть файл

@ -1,12 +1,11 @@
# Django settings file for a project based on the playdoh template.
# import * into your settings_local.py
import logging
import os
from django.utils.functional import lazy
# Make file paths relative to settings.
ROOT = os.path.dirname(os.path.abspath(__file__))
path = lambda *a: os.path.join(ROOT, *a)
from playdohlib.manage import ROOT, path
ROOT_PACKAGE = os.path.basename(ROOT)

Просмотреть файл

@ -1,61 +1,17 @@
#!/usr/bin/env python
import os
import site
import sys
ROOT = os.path.dirname(os.path.abspath(__file__))
path = lambda *a: os.path.join(ROOT,*a)
tmp_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'apps')
sys.path.append(tmp_path)
from playdohlib import manage
# Let the path magic happen in setup_environ() !
sys.path.remove(tmp_path)
# Adjust the python path and put local packages in front.
prev_sys_path = list(sys.path)
site.addsitedir(path('apps'))
site.addsitedir(path('lib'))
# Local (project) vendor library
site.addsitedir(path('vendor-local'))
site.addsitedir(path('vendor-local/lib/python'))
# Global (upstream) vendor library
site.addsitedir(path('vendor'))
site.addsitedir(path('vendor/lib/python'))
# Move the new items to the front of sys.path. (via virtualenv)
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.management import execute_manager, setup_environ
try:
import settings_local as settings
except ImportError:
try:
import settings
except ImportError:
import sys
sys.stderr.write(
"Error: Tried importing 'settings_local.py' and 'settings.py' "
"but neither could be found (or they're throwing an ImportError)."
" Please come back and try again later.")
raise
# If we want to use django settings anywhere, we need to set up the required
# environment variables.
setup_environ(settings)
# Configure Celery
import djcelery
djcelery.setup_loader()
# Monkey-patch django forms to avoid having to use Jinja2's |safe everywhere.
import safe_django_forms
safe_django_forms.monkeypatch()
manage.setup_environ(__file__)
if __name__ == "__main__":
execute_manager(settings)
manage.main()

Просмотреть файл

@ -1,7 +1 @@
MySQL-python==1.2.3c1
Jinja2==2.5.5
# for bcrypt passwords
hmac==20101005
hashlib==20081119
py-bcrypt==0.2
-r ../apps/playdohlib/requirements/compiled.txt

Просмотреть файл

@ -2,15 +2,5 @@
# needed to run the site, it belongs in requirements/prod.txt. If it's a
# package for developers (testing, docs, etc.), it goes in this file.
-r prod.txt
# Documentation
Sphinx==1.0.6
# Testing
nose==1.0.0
-e git://github.com/jbalogh/django-nose.git#egg=django_nose
-e git://github.com/jbalogh/test-utils.git#egg=test-utils
# L10n
translate-toolkit==1.8.0
-r ../apps/playdohlib/requirements/compiled.txt
-r ../apps/playdohlib/requirements/dev.txt

Просмотреть файл

@ -1,24 +1 @@
# Django stuff
-e git://github.com/django/django@36c82ac8#egg=django
# Templates
-e git://github.com/jbalogh/jingo.git#egg=jingo
-e git://github.com/jsocol/jingo-minify.git#egg=jingo-minify
GitPython==0.1.7
# Various tidbits
-e git://github.com/jsocol/commonware.git#egg=commonware
-e git://github.com/mozilla/nuggets.git#egg=nuggets
# Security
-e git://github.com/fwenzel/django-sha2.git#egg=django-sha2
-e git://github.com/jsocol/bleach.git#egg=bleach
# Celery: Message queue
celery
django-celery
# L10n
Babel>=0.9.4
-e git://github.com/clouserw/tower.git#egg=tower
-e git://github.com/fwenzel/django-mozilla-product-details#egg=django-mozilla-product-details
-r ../apps/playdohlib/requirements/prod.txt

Просмотреть файл

@ -1,7 +1,7 @@
# This is an example settings_local.py file.
# Copy it and add your local settings here.
from settings import *
from playdohlib.settings_base import *
DATABASES = {

1
vendor

@ -1 +0,0 @@
Subproject commit 362d8119c34e9249bd36cfd0cdc4b297ce8a862c