├── .gitignore ├── LICENSE ├── MANIFEST.in ├── README ├── bin └── dj-scaffold.py ├── dj_scaffold ├── __init__.py ├── conf │ ├── app │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── forms.py │ │ ├── management │ │ │ ├── __init__.py │ │ │ └── commands │ │ │ │ └── __init__.py │ │ ├── models.py │ │ ├── settings.py │ │ ├── static │ │ │ └── empty │ │ ├── templates │ │ │ └── empty │ │ ├── templatetags │ │ │ └── __init__.py │ │ ├── tests.py │ │ ├── urls.py │ │ └── views.py │ └── prj │ │ ├── .gitignore │ │ ├── deploy │ │ └── dj_scaffold.wsgi │ │ ├── docs │ │ └── empty │ │ ├── env.rc │ │ ├── readme.rst │ │ ├── requirements.txt │ │ └── sites │ │ ├── __init__.py │ │ ├── manage.py │ │ ├── media │ │ └── empty │ │ ├── settings │ │ ├── __init__.py │ │ ├── base.py │ │ ├── dev.py │ │ ├── local.sample │ │ ├── pre.sample │ │ └── production.py │ │ ├── static │ │ ├── css │ │ │ └── empty │ │ ├── img │ │ │ └── empty │ │ └── js │ │ │ └── empty │ │ ├── templates │ │ └── empty │ │ └── urls.py ├── env.py ├── management │ ├── __init__.py │ └── commands │ │ ├── __init__.py │ │ └── lbstartapp.py ├── startproject.py └── utils.py └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | django_startproject.egg-info 3 | build 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011, dj-scaffold 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | * 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. 8 | * Neither the name of dj-scaffold. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 9 | 10 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER 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. 11 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README 2 | include LICENSE 3 | include MANIFEST.in 4 | recursive-include dj_scaffold * 5 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | ============ 2 | dj-scaffold 3 | ============ 4 | 5 | dj-scaffold installs a script which allows the easy creation of a standard 6 | Django project layout. 7 | dj-scaffold add a commend lbstartapp to django, which allows the easy creation 8 | of a standard Django app layout. 9 | 10 | 11 | dj-scaffold.py 12 | ============== 13 | 14 | After installing dj-scaffold, simply run the following command (from within 15 | the directory in where the new project directory should be created):: 16 | 17 | dj-scaffold.py project_name 18 | 19 | The script will prompt for values to replace boilerplate variables with. These 20 | variables allow for both the file contents and path names to be customized to 21 | this specific project. 22 | 23 | directory structure 24 | ------------------- 25 | 26 | |+docs/ 27 | |+env/ #python virtual env, created by scripts/create_env.py 28 | |~requirements.txt 29 | |~scripts/ #some scripts for this project 30 | | |-create_env.py #initialize python virtual env and install requirements 31 | | `-env.rc #start python virtual env. Create $mg as a shortcut for python manger.py. you can use $mg in any folder. 32 | |~sites/ #django's project files. Added some default settings. default db is sqlite, set up template folder and static folder for project. 33 | | |+media/ #media folder 34 | | |+static/ #static folder(css/js...) 35 | | |~settings/ #settings files 36 | | | |-__init__.py 37 | | | |-base.py #base settings 38 | | | |-dev.py #settings for develop environment 39 | | | |-local.sample 40 | | | |-pre.sample #you can create pre.py to set which settings file you want to use(default is dev) 41 | | | `-production.py ##settings for production environment 42 | | `+templates/ #templates folder 43 | |+tools/ 44 | `~deploy/ 45 | `-dj_scaffold.wsgi 46 | 47 | note: project's app put in sites/ folder. sites/you app/ 48 | 49 | lbstartapp 50 | =============================== 51 | 52 | add dj_scaffold to INSTALLED_APPS. 53 | run commend:: 54 | 55 | python manage.py lbstartapp app_name 56 | -------------------------------------------------------------------------------- /bin/dj-scaffold.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | def main(): 6 | from dj_scaffold.startproject import start_project 7 | start_project() 8 | 9 | 10 | if __name__ == '__main__': 11 | main() 12 | -------------------------------------------------------------------------------- /dj_scaffold/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/__init__.py -------------------------------------------------------------------------------- /dj_scaffold/conf/app/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/conf/app/__init__.py -------------------------------------------------------------------------------- /dj_scaffold/conf/app/admin.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | from django.contrib import admin 3 | 4 | #from models import 5 | #admin.site.register() 6 | -------------------------------------------------------------------------------- /dj_scaffold/conf/app/forms.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: UTF-8 -*- 3 | from django import forms 4 | -------------------------------------------------------------------------------- /dj_scaffold/conf/app/management/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/conf/app/management/__init__.py -------------------------------------------------------------------------------- /dj_scaffold/conf/app/management/commands/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/conf/app/management/commands/__init__.py -------------------------------------------------------------------------------- /dj_scaffold/conf/app/models.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | from django.db import models 3 | -------------------------------------------------------------------------------- /dj_scaffold/conf/app/settings.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | 3 | #DEMO_VAL = getattr(settings, 'DEMO_VAL', 'default_val') 4 | -------------------------------------------------------------------------------- /dj_scaffold/conf/app/static/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/conf/app/static/empty -------------------------------------------------------------------------------- /dj_scaffold/conf/app/templates/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/conf/app/templates/empty -------------------------------------------------------------------------------- /dj_scaffold/conf/app/templatetags/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/conf/app/templatetags/__init__.py -------------------------------------------------------------------------------- /dj_scaffold/conf/app/tests.py: -------------------------------------------------------------------------------- 1 | """ 2 | This file demonstrates two different styles of tests (one doctest and one 3 | unittest). These will both pass when you run "manage.py test". 4 | 5 | Replace these with more appropriate tests for your application. 6 | """ 7 | 8 | from django.test import TestCase 9 | 10 | class SimpleTest(TestCase): 11 | def test_basic_addition(self): 12 | """ 13 | Tests that 1 + 1 always equals 2. 14 | """ 15 | self.failUnlessEqual(1 + 1, 2) 16 | 17 | __test__ = {"doctest": """ 18 | Another way to test that 1 + 1 is equal to 2. 19 | 20 | >>> 1 + 1 == 2 21 | True 22 | """} 23 | -------------------------------------------------------------------------------- /dj_scaffold/conf/app/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls.defaults import patterns, urls 2 | 3 | urlpatterns = patterns('', 4 | #url(r'^$', views.index, name='app_index'), 5 | ) 6 | -------------------------------------------------------------------------------- /dj_scaffold/conf/app/views.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: UTF-8 -*- 3 | from django.shortcuts import render 4 | -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.swp 3 | *.sqlite 4 | env/ 5 | -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/deploy/dj_scaffold.wsgi: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import site 4 | 5 | def add_site_dir(site_dirs): 6 | prev_sys_path = list(sys.path) 7 | for directory in site_dirs: 8 | site.addsitedir(directory) 9 | new_sys_path = [] 10 | for item in list(sys.path): 11 | if item not in prev_sys_path: 12 | new_sys_path.append(item) 13 | sys.path.remove(item) 14 | sys.path[:0] = new_sys_path 15 | 16 | HERE = os.path.dirname(__file__) 17 | ROOT_PATH = os.path.abspath(os.path.join(HERE, '../')) 18 | 19 | ALLDIRS = [os.path.join(ROOT_PATH, 'env/lib/python2.7/site-packages'), os.path.join(ROOT_PATH, 'sites')] 20 | add_site_dir(ALLDIRS) 21 | 22 | os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' 23 | 24 | import django.core.handlers.wsgi 25 | application = django.core.handlers.wsgi.WSGIHandler() 26 | -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/docs/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/conf/prj/docs/empty -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/env.rc: -------------------------------------------------------------------------------- 1 | SCRIPT=$(readlink -f ${PWD}/${BASH_SOURCE}) 2 | TOP_PATH=`dirname $SCRIPT` 3 | 4 | if ! [ -e $TOP_PATH/env/bin/activate ]; then 5 | if [ -n "${VIRTUAL_ENV+x}" ]; then 6 | deactivate 7 | fi 8 | virtualenv --unzip-setuptools --no-site-packages --distribute "$TOP_PATH/env" 9 | $TOP_PATH/env/bin/pip install -r requirements.txt 10 | fi 11 | 12 | source $TOP_PATH/env/bin/activate 13 | export mg="$TOP_PATH/env/bin/python $TOP_PATH/sites/manage.py" 14 | -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/readme.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/conf/prj/readme.rst -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/requirements.txt: -------------------------------------------------------------------------------- 1 | Django>=1.3 2 | south 3 | dj-scaffold 4 | django-devserver 5 | django-debug-toolbar 6 | django_compressor 7 | gunicorn 8 | -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/sites/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/conf/prj/sites/__init__.py -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/sites/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from django.core.management import execute_manager 3 | import imp 4 | import os, sys 5 | 6 | HERE = os.path.dirname(os.path.abspath(__file__)) 7 | sys.path.insert(0, os.path.join(HERE, '../requirement')) 8 | 9 | try: 10 | imp.find_module('settings') # Assumed to be in the same directory. 11 | except ImportError: 12 | import sys 13 | sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__) 14 | sys.exit(1) 15 | 16 | import settings 17 | 18 | if __name__ == "__main__": 19 | execute_manager(settings) 20 | -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/sites/media/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/conf/prj/sites/media/empty -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/sites/settings/__init__.py: -------------------------------------------------------------------------------- 1 | SETTINGS = 'dev' 2 | try: 3 | from pre import SETTINGS 4 | except: 5 | pass 6 | exec 'from %s import *' % SETTINGS 7 | 8 | try: 9 | from local import * 10 | except ImportError: 11 | pass 12 | -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/sites/settings/base.py: -------------------------------------------------------------------------------- 1 | # Django settings for simple_todo_site project. 2 | import os 3 | HERE = os.path.dirname(os.path.abspath(__file__)) 4 | HERE = os.path.join(HERE, '../') 5 | 6 | DEBUG = True 7 | TEMPLATE_DEBUG = DEBUG 8 | 9 | ADMINS = ( 10 | # ('Your Name', 'your_email@example.com'), 11 | ) 12 | 13 | MANAGERS = ADMINS 14 | 15 | DATABASES = { 16 | 'default': { 17 | 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 18 | 'NAME': os.path.join(HERE, 'db.sqlite'), # Or path to database file if using sqlite3. 19 | 'USER': '', # Not used with sqlite3. 20 | 'PASSWORD': '', # Not used with sqlite3. 21 | 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. 22 | 'PORT': '', # Set to empty string for default. Not used with sqlite3. 23 | } 24 | } 25 | 26 | # Local time zone for this installation. Choices can be found here: 27 | # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name 28 | # although not all choices may be available on all operating systems. 29 | # On Unix systems, a value of None will cause Django to use the same 30 | # timezone as the operating system. 31 | # If running in a Windows environment this must be set to the same as your 32 | # system time zone. 33 | TIME_ZONE = 'America/Chicago' 34 | 35 | # Language code for this installation. All choices can be found here: 36 | # http://www.i18nguy.com/unicode/language-identifiers.html 37 | LANGUAGE_CODE = 'en-us' 38 | 39 | SITE_ID = 1 40 | 41 | # If you set this to False, Django will make some optimizations so as not 42 | # to load the internationalization machinery. 43 | USE_I18N = True 44 | 45 | # If you set this to False, Django will not format dates, numbers and 46 | # calendars according to the current locale 47 | USE_L10N = True 48 | 49 | # Absolute filesystem path to the directory that will hold user-uploaded files. 50 | # Example: "/home/media/media.lawrence.com/media/" 51 | MEDIA_ROOT = os.path.join(HERE, 'media') 52 | 53 | # URL that handles the media served from MEDIA_ROOT. Make sure to use a 54 | # trailing slash. 55 | # Examples: "http://media.lawrence.com/media/", "http://example.com/media/" 56 | MEDIA_URL = '/media/' 57 | 58 | # Absolute path to the directory static files should be collected to. 59 | # Don't put anything in this directory yourself; store your static files 60 | # in apps' "static/" subdirectories and in STATICFILES_DIRS. 61 | # Example: "/home/media/media.lawrence.com/static/" 62 | STATIC_ROOT = os.path.join(HERE, 'collectedstatic') 63 | 64 | # URL prefix for static files. 65 | # Example: "http://media.lawrence.com/static/" 66 | STATIC_URL = '/static/' 67 | 68 | # URL prefix for admin static files -- CSS, JavaScript and images. 69 | # Make sure to use a trailing slash. 70 | # Examples: "http://foo.com/static/admin/", "/static/admin/". 71 | ADMIN_MEDIA_PREFIX = '/static/admin/' 72 | 73 | # Additional locations of static files 74 | STATICFILES_DIRS = ( 75 | os.path.join(HERE, 'static/'), 76 | # Put strings here, like "/home/html/static" or "C:/www/django/static". 77 | # Always use forward slashes, even on Windows. 78 | # Don't forget to use absolute paths, not relative paths. 79 | ) 80 | 81 | # List of finder classes that know how to find static files in 82 | # various locations. 83 | STATICFILES_FINDERS = ( 84 | 'django.contrib.staticfiles.finders.FileSystemFinder', 85 | 'django.contrib.staticfiles.finders.AppDirectoriesFinder', 86 | 'compressor.finders.CompressorFinder', 87 | # 'django.contrib.staticfiles.finders.DefaultStorageFinder', 88 | ) 89 | 90 | # Make this unique, and don't share it with anybody. 91 | SECRET_KEY = '' 92 | 93 | # List of callables that know how to import templates from various sources. 94 | TEMPLATE_LOADERS = ( 95 | 'django.template.loaders.filesystem.Loader', 96 | 'django.template.loaders.app_directories.Loader', 97 | # 'django.template.loaders.eggs.Loader', 98 | ) 99 | 100 | MIDDLEWARE_CLASSES = ( 101 | 'django.middleware.common.CommonMiddleware', 102 | 'django.contrib.sessions.middleware.SessionMiddleware', 103 | 'django.middleware.csrf.CsrfViewMiddleware', 104 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 105 | 'django.contrib.messages.middleware.MessageMiddleware', 106 | ) 107 | 108 | ROOT_URLCONF = 'urls' 109 | 110 | TEMPLATE_DIRS = ( 111 | # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". 112 | # Always use forward slashes, even on Windows. 113 | # Don't forget to use absolute paths, not relative paths. 114 | os.path.join(HERE, 'templates_plus'), 115 | os.path.join(HERE, 'templates'), 116 | ) 117 | 118 | INSTALLED_APPS = ( 119 | 'django.contrib.auth', 120 | 'django.contrib.contenttypes', 121 | 'django.contrib.sessions', 122 | 'django.contrib.sites', 123 | 'django.contrib.messages', 124 | 'django.contrib.staticfiles', 125 | # Uncomment the next line to enable the admin: 126 | 'django.contrib.admin', 127 | # Uncomment the next line to enable admin documentation: 128 | 'django.contrib.admindocs', 129 | 130 | 'dj_scaffold', 131 | 'south', 132 | 'compressor', 133 | ) 134 | 135 | try: 136 | import gunicorn 137 | INSTALLED_APPS += ('gunicorn',) 138 | except: 139 | pass 140 | 141 | # A sample logging configuration. The only tangible logging 142 | # performed by this configuration is to send an email to 143 | # the site admins on every HTTP 500 error. 144 | # See http://docs.djangoproject.com/en/dev/topics/logging for 145 | # more details on how to customize your logging configuration. 146 | LOGGING = { 147 | 'version': 1, 148 | 'disable_existing_loggers': False, 149 | 'handlers': { 150 | 'mail_admins': { 151 | 'level': 'ERROR', 152 | 'class': 'django.utils.log.AdminEmailHandler' 153 | } 154 | }, 155 | 'loggers': { 156 | 'django.request': { 157 | 'handlers': ['mail_admins'], 158 | 'level': 'ERROR', 159 | 'propagate': True, 160 | }, 161 | } 162 | } 163 | 164 | COMPRESS_PRECOMPILERS = ( 165 | ('text/coffeescript', 'coffee --compile --stdio'), 166 | ('text/less', 'lessc {infile} {outfile}'), 167 | ('text/x-sass', 'sass {infile} {outfile}'), 168 | ('text/x-scss', 'sass --scss {infile} {outfile}'), 169 | ) 170 | -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/sites/settings/dev.py: -------------------------------------------------------------------------------- 1 | from base import * 2 | 3 | DEBUG = True 4 | EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' 5 | 6 | #devserver 7 | try: 8 | import devserver 9 | INSTALLED_APPS += ('devserver',) 10 | MIDDLEWARE_CLASSES += ('devserver.middleware.DevServerMiddleware',) 11 | INSTALLED_APPS = ('devserver',) + INSTALLED_APPS#devserver must in first 12 | except Exception, e: 13 | pass 14 | 15 | #debug_toolbar 16 | try: 17 | import debug_toolbar 18 | INSTALLED_APPS += ('debug_toolbar',) 19 | MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',) 20 | INTERNAL_IPS = ('127.0.0.1',) 21 | except Exception, e: 22 | pass 23 | -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/sites/settings/local.sample: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/conf/prj/sites/settings/local.sample -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/sites/settings/pre.sample: -------------------------------------------------------------------------------- 1 | SETTINGS = 'production' 2 | -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/sites/settings/production.py: -------------------------------------------------------------------------------- 1 | from base import * 2 | 3 | DEBUG = False -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/sites/static/css/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/conf/prj/sites/static/css/empty -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/sites/static/img/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/conf/prj/sites/static/img/empty -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/sites/static/js/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/conf/prj/sites/static/js/empty -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/sites/templates/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/conf/prj/sites/templates/empty -------------------------------------------------------------------------------- /dj_scaffold/conf/prj/sites/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls.defaults import patterns, include, url 2 | from django.contrib.staticfiles.urls import staticfiles_urlpatterns 3 | from django.conf.urls.static import static 4 | from django.conf import settings 5 | 6 | # Uncomment the next two lines to enable the admin: 7 | from django.contrib import admin 8 | admin.autodiscover() 9 | 10 | urlpatterns = patterns('', 11 | # Uncomment the admin/doc line below to enable admin documentation: 12 | url(r'^admin/doc/', include('django.contrib.admindocs.urls')), 13 | 14 | # Uncomment the next line to enable the admin: 15 | url(r'^admin/', include(admin.site.urls)), 16 | 17 | # Examples: 18 | #url('^$', 'demoapp.views.index', name='idx'), 19 | #url(r'^demo/', include('demoapp.urls')), 20 | ) 21 | 22 | if settings.DEBUG: 23 | urlpatterns += staticfiles_urlpatterns() 24 | urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 25 | -------------------------------------------------------------------------------- /dj_scaffold/env.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import site 3 | 4 | def add_site_dir(site_dirs): 5 | prev_sys_path = list(sys.path) 6 | for directory in site_dirs: 7 | site.addsitedir(directory) 8 | new_sys_path = [] 9 | for item in list(sys.path): 10 | if item not in prev_sys_path: 11 | new_sys_path.append(item) 12 | sys.path.remove(item) 13 | sys.path[:0] = new_sys_path 14 | -------------------------------------------------------------------------------- /dj_scaffold/management/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/management/__init__.py -------------------------------------------------------------------------------- /dj_scaffold/management/commands/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicalloy/dj-scaffold/92e9a991e0699f8b88c16d8a95b23bd5b3cf29e1/dj_scaffold/management/commands/__init__.py -------------------------------------------------------------------------------- /dj_scaffold/management/commands/lbstartapp.py: -------------------------------------------------------------------------------- 1 | import os 2 | from optparse import make_option 3 | 4 | import dj_scaffold 5 | from django.core.management.base import CommandError, LabelCommand 6 | from django.utils.importlib import import_module 7 | 8 | from dj_scaffold import utils 9 | 10 | 11 | class Command(LabelCommand): 12 | option_list = LabelCommand.option_list + ( 13 | make_option('--template', '-t', action='store', dest='app_template', 14 | help='The path to the app template'), 15 | make_option('--parent_path', '-p', action='store', dest='parent_path', 16 | help='The parent path of the app to be created'), 17 | ) 18 | 19 | help = ("Creates a Django application directory structure based on the specified template directory.") 20 | args = "[appname]" 21 | label = 'application name' 22 | 23 | requires_model_validation = False 24 | can_import_settings = True 25 | 26 | #def handle_label(self, label, **options): 27 | def handle_label(self, app_name, directory=None, **options): 28 | if directory is None: 29 | directory = os.getcwd() 30 | #app_name =label 31 | app_template = options.get('app_template') or os.path.join(dj_scaffold.__path__[0], 'conf', 'app') 32 | app_dir = os.path.join(options.get('parent_path') or directory, app_name) 33 | 34 | if not os.path.exists(app_template): 35 | raise CommandError("The template path, %r, does not exist." % app_template) 36 | 37 | # Determine the project_name by using the basename of directory, 38 | # which should be the full path of the project directory (or the 39 | # current directory if no directory was passed). 40 | project_name = os.path.basename(directory) 41 | if app_name == project_name: 42 | raise CommandError("You cannot create an app with the same name" 43 | " (%r) as your project." % app_name) 44 | 45 | # Check that the app_name cannot be imported. 46 | try: 47 | import_module(app_name) 48 | except ImportError: 49 | pass 50 | else: 51 | raise CommandError("%r conflicts with the name of an existing Python module and cannot be used as an app name. Please try another name." % app_name) 52 | 53 | # Get any boilerplate replacement variables: 54 | replace = {} 55 | utils.copy_template(app_template, app_dir, replace) 56 | -------------------------------------------------------------------------------- /dj_scaffold/startproject.py: -------------------------------------------------------------------------------- 1 | import optparse 2 | import os 3 | import sys 4 | 5 | from dj_scaffold import utils 6 | 7 | 8 | TEMPLATE_DIR = os.path.join(os.path.dirname(os.path.realpath(utils.__file__)), 9 | 'conf', 'prj') 10 | 11 | def start_project(): 12 | """ 13 | Copy a project template, replacing boilerplate variables. 14 | 15 | """ 16 | usage = "usage: %prog [options] project_name [base_destination_dir]" 17 | parser = optparse.OptionParser(usage=usage) 18 | parser.add_option('-t', '--template-dir', dest='src_dir', 19 | help='project template directory to use', 20 | default=TEMPLATE_DIR) 21 | options, args = parser.parse_args() 22 | if len(args) not in (1, 2): 23 | parser.print_help() 24 | sys.exit(1) 25 | project_name = args[0] 26 | 27 | src = options.src_dir 28 | if len(args) > 1: 29 | base_dest_dir = args[1] 30 | else: 31 | base_dest_dir = '' 32 | dest = os.path.join(base_dest_dir, project_name) 33 | 34 | # Get any boilerplate replacement variables: 35 | replace = {} 36 | for var, help, default in utils.get_boilerplate(src, project_name): 37 | help = help or var 38 | if default is not None: 39 | prompt = '%s [%s]: ' % (help, default) 40 | else: 41 | prompt = '%s: ' % help 42 | value = None 43 | while not value: 44 | value = raw_input(prompt) or default 45 | replace[var] = value 46 | 47 | utils.copy_template(src, dest, replace) 48 | -------------------------------------------------------------------------------- /dj_scaffold/utils.py: -------------------------------------------------------------------------------- 1 | import os 2 | import re 3 | import shutil 4 | import stat 5 | from random import choice 6 | 7 | 8 | def copy_template(src, dest, replace=None): 9 | """ 10 | Copy all files in the source path to the destination path. 11 | 12 | To replace boilerplate strings in the source data, pass a dictionary to the 13 | ``replace`` argument where each key is the boilerplate string and the 14 | corresponding value is the string which should replace it. 15 | 16 | The destination file paths are also parsed through the boilerplate 17 | replacements, so directories and file names may also be modified. 18 | 19 | """ 20 | for path, dirs, files in os.walk(src): 21 | relative_path = path[len(src):].lstrip(os.sep) 22 | # Replace boilerplate strings in destination directory. 23 | for old_val, new_val in replace.items(): 24 | relative_path = relative_path.replace(old_val, new_val) 25 | os.mkdir(os.path.join(dest, relative_path)) 26 | for i, subdir in enumerate(dirs): 27 | if subdir.startswith('.'): 28 | del dirs[i] 29 | for filename in files: 30 | if (filename.startswith('.startproject') or 31 | filename.endswith('.pyc')): 32 | continue 33 | src_file_path = os.path.join(path, filename) 34 | # Replace boilerplate strings in destination filename. 35 | for old_val, new_val in replace.items(): 36 | filename = filename.replace(old_val, new_val) 37 | dest_file_path = os.path.join(dest, relative_path, filename) 38 | copy_template_file(src_file_path, dest_file_path, replace) 39 | 40 | 41 | def copy_template_file(src, dest, replace=None): 42 | """ 43 | Copy a source file to a new destination file. 44 | 45 | To replace boilerplate strings in the source data, pass a dictionary to the 46 | ``replace`` argument where each key is the boilerplate string and the 47 | corresponding value is the string which should replace it. 48 | 49 | """ 50 | replace = replace or {} 51 | # Read the data from the source file. 52 | src_file = open(src, 'r') 53 | data = src_file.read() 54 | src_file.close() 55 | # Replace boilerplate strings. 56 | for old_val, new_val in replace.items(): 57 | data = data.replace(old_val, new_val) 58 | 59 | # Generate SECRET_KEY for settings file 60 | secret_key = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]) 61 | data = re.sub(r"(?<=SECRET_KEY = ')'", secret_key + "'", data) 62 | 63 | # Write the data to the destination file. 64 | dest_file = open(dest, 'w') 65 | dest_file.write(data) 66 | dest_file.close() 67 | # Copy permissions from source file. 68 | shutil.copymode(src, dest) 69 | # Make new file writable. 70 | if os.access(dest, os.W_OK): 71 | st = os.stat(dest) 72 | new_permissions = stat.S_IMODE(st.st_mode) | stat.S_IWUSR 73 | os.chmod(dest, new_permissions) 74 | 75 | 76 | def get_boilerplate(path, project_name): 77 | """ 78 | Look for a ``.startproject_boilerplate`` file the given path and parse it. 79 | 80 | Return a list of 3-part tuples, each containing a boilerplate variable, 81 | optional description and default value. 82 | 83 | If no file was found (or no lines contained boilerplate variables), return 84 | an empty list. 85 | 86 | """ 87 | defaults = {} 88 | defaults_path = os.path.join(path, '.scaffold_defaults') 89 | if os.path.isfile(defaults_path): 90 | defaults_file = open(defaults_path, 'r') 91 | for line in defaults_file: 92 | match = re.match(r'\s*(\w+)\s*(.*)$', line) 93 | if match: 94 | var, default = match.groups() 95 | defaults[var] = default 96 | boilerplate = [] 97 | boilerplate_path = os.path.join(path, '.scaffold_boilerplate') 98 | if os.path.isfile(boilerplate_path): 99 | boilerplate_file = open(boilerplate_path, 'r') 100 | for line in boilerplate_file: 101 | match = re.match(r'\s*(\w+)\s*(.*)$', line) 102 | if match: 103 | var, description = match.groups() 104 | default = defaults.get(var) 105 | boilerplate.append((var, description, default)) 106 | return boilerplate 107 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | from distutils.command.install_data import install_data 3 | from distutils.command.install import INSTALL_SCHEMES 4 | import os 5 | import sys 6 | 7 | 8 | class osx_install_data(install_data): 9 | # On MacOS, the platform-specific lib dir is /System/Library/Framework/Python/.../ 10 | # which is wrong. Python 2.5 supplied with MacOS 10.5 has an Apple-specific fix 11 | # for this in distutils.command.install_data#306. It fixes install_lib but not 12 | # install_data, which is why we roll our own install_data class. 13 | 14 | def finalize_options(self): 15 | # By the time finalize_options is called, install.install_lib is set to the 16 | # fixed directory, so we set the installdir to install_lib. The 17 | # install_data class uses ('install_data', 'install_dir') instead. 18 | self.set_undefined_options('install', ('install_lib', 'install_dir')) 19 | install_data.finalize_options(self) 20 | 21 | if sys.platform == "darwin": 22 | cmdclasses = {'install_data': osx_install_data} 23 | else: 24 | cmdclasses = {'install_data': install_data} 25 | 26 | def fullsplit(path, result=None): 27 | """ 28 | Split a pathname into components (the opposite of os.path.join) in a 29 | platform-neutral way. 30 | """ 31 | if result is None: 32 | result = [] 33 | head, tail = os.path.split(path) 34 | if head == '': 35 | return [tail] + result 36 | if head == path: 37 | return result 38 | return fullsplit(head, [tail] + result) 39 | 40 | # Tell distutils to put the data_files in platform-specific installation 41 | # locations. See here for an explanation: 42 | # http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb 43 | for scheme in INSTALL_SCHEMES.values(): 44 | scheme['data'] = scheme['purelib'] 45 | 46 | # Compile the list of packages available, because distutils doesn't have 47 | # an easy way to do this. 48 | packages, data_files = [], [] 49 | root_dir = os.path.dirname(__file__) 50 | if root_dir != '': 51 | os.chdir(root_dir) 52 | dj_scaffold_dir = 'dj_scaffold' 53 | 54 | for dirpath, dirnames, filenames in os.walk(dj_scaffold_dir): 55 | # Ignore dirnames that start with '.' 56 | is_data = False 57 | if '/conf/' in dirpath.replace('\\', '/'): 58 | is_data = True 59 | for i, dirname in enumerate(dirnames): 60 | if dirname.startswith('.'): del dirnames[i] 61 | if '__init__.py' in filenames and not is_data: 62 | packages.append('.'.join(fullsplit(dirpath))) 63 | elif filenames: 64 | data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]]) 65 | 66 | # Small hack for working with bdist_wininst. 67 | # See http://mail.python.org/pipermail/distutils-sig/2004-August/004134.html 68 | if len(sys.argv) > 1 and sys.argv[1] == 'bdist_wininst': 69 | for file_info in data_files: 70 | file_info[0] = '\\PURELIB\\%s' % file_info[0] 71 | 72 | 73 | setup(name='dj-scaffold', 74 | version='1.0.6', 75 | author='vicalloy', 76 | author_email='zbirder@gmail.com', 77 | description=('Create a Django project layout based on vicalloy\'s' 78 | 'best practices.'), 79 | long_description='', 80 | packages=packages, 81 | scripts=['bin/dj-scaffold.py'], 82 | data_files = data_files, 83 | classifiers=[ 84 | 'Development Status :: 3 - Alpha', 85 | 'Environment :: Web Environment', 86 | 'Framework :: Django', 87 | 'Intended Audience :: Developers', 88 | 'License :: OSI Approved :: BSD License', 89 | 'Operating System :: OS Independent', 90 | 'Programming Language :: Python', 91 | 'Topic :: Software Development :: Libraries :: Python Modules']) 92 | --------------------------------------------------------------------------------