Skip to content

Commit

Permalink
Misc formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
coordt committed Sep 21, 2012
1 parent 0132b58 commit d5977aa
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 46 deletions.
47 changes: 26 additions & 21 deletions create_app.py
@@ -1,13 +1,16 @@
#!/usr/bin/env python

import os, random, subprocess, sys
import os
import random
import subprocess
import sys

HAS_VENV = bool(subprocess.Popen(['which','virtualenv'], stdout=subprocess.PIPE).communicate()[0])
HAS_VENV = bool(subprocess.Popen(['which', 'virtualenv'], stdout=subprocess.PIPE).communicate()[0])
if not HAS_VENV:
print "virtualenv is required to run this script. Please install it with\n easy_install virtualenv\n\nor\n\n pip virtualenv"
sys.exit(1)

HAS_VENVW = bool(subprocess.Popen(['which','virtualenvwrapper.sh'], stdout=subprocess.PIPE).communicate()[0])
HAS_VENVW = bool(subprocess.Popen(['which', 'virtualenvwrapper.sh'], stdout=subprocess.PIPE).communicate()[0])
if not HAS_VENVW:
print "virtualenvwrapper is required to run this script. Please install it with\n easy_install virtualenvwrapper\n\nor\n\n pip virtualenvwrapper"
sys.exit(1)
Expand All @@ -24,18 +27,20 @@
'.hg',
)


def replace(repl, text):
text = text.replace('/gitignore', '/.gitignore')
for key, value in repl.iteritems():
text = text.replace('$$$$%s$$$$' % (key,), value)
return text


def main(repl, dest, templ_dir):
try:
os.makedirs(dest)
except OSError:
pass

for root, dirs, files in os.walk(templ_dir):
for filename in files:
source_fn = os.path.join(root, filename)
Expand All @@ -54,10 +59,10 @@ def main(repl, dest, templ_dir):
data = replace(repl, data)
open(dest_fn, 'w').write(data)
os.chmod(dest_fn, os.stat(source_fn)[0])

print "Making the virtual environment (%s)..." % repl['VIRTENV']
create_env_cmds = [
'source virtualenvwrapper.sh',
'source virtualenvwrapper.sh',
'cd %s' % dest,
'mkvirtualenv --no-site-packages --distribute %s' % repl['VIRTENV'],
'easy_install pip'
Expand All @@ -66,11 +71,11 @@ def main(repl, dest, templ_dir):
'source virtualenvwrapper.sh',
'cat > $WORKON_HOME/%s/bin/postactivate '\
'<<END\n#!/bin/bash/\ncd %s\nEND\n'\
'chmod +x $WORKON_HOME/%s/bin/postactivate' % (repl['VIRTENV'], dest,repl['VIRTENV'])
'chmod +x $WORKON_HOME/%s/bin/postactivate' % (repl['VIRTENV'], dest, repl['VIRTENV'])
]
subprocess.call([';'.join(create_env_cmds)], env=os.environ, executable='/bin/bash', shell=True)
subprocess.call([';'.join(create_pa_cmd)], env=os.environ, executable='/bin/bash', shell=True)

print "Now type: workon %s" % repl['VIRTENV']

if __name__ == '__main__':
Expand All @@ -85,7 +90,7 @@ def main(repl, dest, templ_dir):
parser.add_option("-d", "--dest", dest="destination", help="Where to put the new application. Relative paths are recognized.")
parser.add_option("-t", "--template", dest="template", help="The application template to use as a basis for the new application.")
(options, args) = parser.parse_args()

repl = {
'APP_NAME': None,
'PKG_NAME': None,
Expand All @@ -95,23 +100,23 @@ def main(repl, dest, templ_dir):
}
dest_dir = None
templ_dir = None

cur_user = os.getlogin()

if options.app_name:
repl['APP_NAME'] = options.app_name
elif len(args) > 0:
repl['APP_NAME'] = args[0]

while not repl['APP_NAME']:
repl['APP_NAME'] = raw_input('Application name: ')

if options.pkg_name:
repl['PKG_NAME'] = options.pkg_name
while not repl['PKG_NAME']:
default_name = repl['APP_NAME'].replace('django-', '').replace('-','_')
default_name = repl['APP_NAME'].replace('django-', '').replace('-', '_')
repl['PKG_NAME'] = raw_input('Package Name [%s]:' % default_name) or default_name

if options.author:
repl['AUTHOR'] = options.author
while not repl['AUTHOR']:
Expand All @@ -121,20 +126,20 @@ def main(repl, dest, templ_dir):
repl['AUTHOR_EMAIL'] = options.author_email
while not repl['AUTHOR_EMAIL']:
repl['AUTHOR_EMAIL'] = raw_input('Author\'s Email: ')

if options.url:
repl['URL'] = options.url
while not repl['URL']:
repl['URL'] = raw_input('Project Page URL: ')

repl['SECRET_KEY'] = ''.join([random.choice(CHARS) for i in xrange(50)])

if options.destination:
dest_dir = options.destination

while not dest_dir:
dest_dir = raw_input('Destination directory [%s]: ' % (os.getcwd(),)) or os.getcwd()
dest_dir = os.path.realpath(os.path.expanduser(dest_dir))
dest_dir = os.path.realpath(os.path.expanduser(dest_dir))
dest = os.path.join(dest_dir, repl['APP_NAME'])

if options.template:
Expand All @@ -146,7 +151,7 @@ def main(repl, dest, templ_dir):
templ_dir = os.path.realpath(os.path.expanduser(templ_dir))
if templ_dir[-1] != '/':
templ_dir = templ_dir + "/"

if options.VIRTENV:
repl['VIRTENV'] = options.VIRTENV
else:
Expand Down
2 changes: 2 additions & 0 deletions skel/MANIFEST.in
Expand Up @@ -7,3 +7,5 @@ recursive-include $$$$PKG_NAME$$$$/templates *
include LICENSE
include README
include *.txt

prune example/
File renamed without changes.
6 changes: 3 additions & 3 deletions skel/doc_src/index.rst
@@ -1,6 +1,6 @@
==============================
$$$$APP_NAME$$$$'s v |version|
==============================
============================
$$$$APP_NAME$$$$ v |version|
============================

About
=====
Expand Down
33 changes: 33 additions & 0 deletions skel/doc_src/reference/models.rst
@@ -0,0 +1,33 @@
===============
Model Reference
===============

ModelName
=========

.. py:class:: ModelName
.. py:attribute:: parent
:py:class:`TreeForeignKey` ``(self)``

The category's parent category. Leave this blank for an root category.

.. py:attribute:: name
**Required** ``CharField(100)``

The name of the category.

.. py:attribute:: slug
**Required** ``SlugField``

URL-friendly title. It is automatically generated from the title.

.. py:attribute:: active
**Required** ``BooleanField`` *default:* ``True``

Is this item active. If it is inactive, all children are set to inactive as well.

2 changes: 1 addition & 1 deletion skel/doc_src/reference/settings.rst
@@ -1,3 +1,3 @@

========
Settings
========
9 changes: 2 additions & 7 deletions skel/example/settings.py
Expand Up @@ -83,13 +83,6 @@
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'g2_39yupn*6j4p*cg2%w643jiq-1n_annua*%i8+rq0dx9p=$n'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
# 'django.template.loaders.eggs.load_template_source',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand All @@ -104,6 +97,7 @@
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(PROJ_ROOT, 'templates'),
)

INSTALLED_APPS = (
Expand All @@ -115,4 +109,5 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'$$$$PKG_NAME$$$$',
'simpleapp',
)
Empty file.
10 changes: 10 additions & 0 deletions skel/example/simpleapp/admin.py
@@ -0,0 +1,10 @@
from django.contrib import admin

from .models import SimpleModel

class SimpleModelAdmin(admin.ModelAdmin):
list_display = ('name', )
prepopulated_fields = {'slug': ('name',)}
search_fields = ('name',)

admin.site.register(SimpleModel, SimpleModelAdmin)
20 changes: 20 additions & 0 deletions skel/example/simpleapp/models.py
@@ -0,0 +1,20 @@
from django.db import models

class SimpleModel(models.Model):
"""
(SimpleModel description)
"""

name = models.CharField(max_length=255)
slug = models.SlugField(unique=True)
description = models.TextField(blank=True)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)

def __unicode__(self):
return self.name

@models.permalink
def get_absolute_url(self):
return ('simplemodel_detail_view_name', [str(self.id)])

Empty file.
Empty file.
12 changes: 12 additions & 0 deletions skel/example/simpleapp/urls.py
@@ -0,0 +1,12 @@
from django.conf.urls.defaults import *

from .models import SimpleModel

urlpatterns = patterns('django.views.generic.list_detail',
url(r'^$', 'object_list', {
'queryset': SimpleModel.objects.all(),
}, name="simplemodel_list"),
(r'^(?P<slug>[\w-]+)/', 'object_detail', {
'queryset': SimpleModel.objects.all(),
}, name="simplemodel_detail")
)
12 changes: 12 additions & 0 deletions skel/example/templates/base.html
@@ -0,0 +1,12 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>$$$$APP_NAME$$$$</title>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
2 changes: 1 addition & 1 deletion skel/example/urls.py
Expand Up @@ -5,7 +5,7 @@
admin.autodiscover()

urlpatterns = patterns('',
(r'^$$$$PKG_NAME$$$$/', include('$$$$PKG_NAME$$$$.urls')),
# (r'^$$$$PKG_NAME$$$$/', include('$$$$PKG_NAME$$$$.urls')),
(r'^admin/', include(admin.site.urls)),
)

Expand Down
28 changes: 15 additions & 13 deletions skel/setup.py
@@ -1,6 +1,7 @@
import os
from setuptools import setup, find_packages


def read_file(filename):
"""Read a file into a string"""
path = os.path.abspath(os.path.dirname(__file__))
Expand All @@ -9,10 +10,11 @@ def read_file(filename):
return open(filepath).read()
except IOError:
return ''



def get_readme():
"""Return the README file contents. Supports text,rst, and markdown"""
for name in ('README','README.rst','README.md'):
for name in ('README', 'README.rst', 'README.md'):
if os.path.exists(name):
return read_file(name)
return ''
Expand All @@ -21,17 +23,17 @@ def get_readme():
DESC = " ".join(__import__('$$$$PKG_NAME$$$$').__doc__.splitlines()).strip()

setup(
name = "$$$$APP_NAME$$$$",
version = __import__('$$$$PKG_NAME$$$$').get_version().replace(' ', '-'),
url = '$$$$URL$$$$',
author = '$$$$AUTHOR$$$$',
author_email = '$$$$AUTHOR_EMAIL$$$$',
description = DESC,
long_description = get_readme(),
packages = find_packages(),
include_package_data = True,
install_requires = read_file('requirements.txt'),
classifiers = [
name="$$$$APP_NAME$$$$",
version=__import__('$$$$PKG_NAME$$$$').get_version().replace(' ', '-'),
url='$$$$URL$$$$',
author='$$$$AUTHOR$$$$',
author_email='$$$$AUTHOR_EMAIL$$$$',
description=DESC,
long_description=get_readme(),
packages=find_packages(),
include_package_data=True,
install_requires=read_file('requirements.txt'),
classifiers=[
'License :: OSI Approved :: Apache Software License',
'Framework :: Django',
],
Expand Down

0 comments on commit d5977aa

Please sign in to comment.