Skip to content

Commit

Permalink
add template options
Browse files Browse the repository at this point in the history
  • Loading branch information
layterz committed Oct 17, 2011
1 parent e968255 commit f020662
Show file tree
Hide file tree
Showing 47 changed files with 184 additions and 3 deletions.
19 changes: 16 additions & 3 deletions kickstart.py
Expand Up @@ -7,12 +7,21 @@
parser = OptionParser()
parser.add_option("-t", "--template", dest="template", help="default project template", default="default")
parser.add_option("-a", "--add-template", dest="add", help="install new template")
parser.add_option("-d", "--remove-template", dest="remove", help="remove a template")
parser.add_option("-r", "--remove-template", dest="remove", help="remove a template")
parser.add_option("-d", "--default", dest="default_template", help="set default template")
(options, args) = parser.parse_args()

template_dir = os.path.join(kickstarter.__path__[0], 'templates', options.template)


def set_default():
templates_dir = os.path.join(kickstarter.__path__[0], 'templates')
shutil.rmtree('%s/default' % templates_dir)
shutil.copytree('%s/%s' % (templates_dir, options.default_template), '%s/%s' % (templates_dir, 'default'))
shutil.copytree('%s/default/%s' % (templates_dir, options.default_template), '%s/default/default' % templates_dir)
shutil.rmtree('%s/default/%s' % (templates_dir, options.default_template))


def create_template():
templates_dir = os.path.join(kickstarter.__path__[0], 'templates')
shutil.copytree(options.add, '%s/%s' % (templates_dir, options.add))
Expand Down Expand Up @@ -51,7 +60,9 @@ def copy_template():
shutil.copytree(template, name)
shutil.copytree('%s/%s' % (name, options.template), '%s/%s' % (name, config['project']))
shutil.rmtree('%s/%s' % (name, options.template))
os.remove('%s/%s' % (name, 'config.yaml'))

if os.path.exists('%s/%s' % (name, 'config.yaml')):
os.remove('%s/%s' % (name, 'config.yaml'))

for dirname, dirnames, files in os.walk(name):
for filename in files:
Expand Down Expand Up @@ -79,7 +90,9 @@ def copy_template():

if options.add:
create_template()
if options.remove:
elif options.remove:
remove_template()
elif options.default_template:
set_default()
else:
create_project(args[0], template_dir)
1 change: 1 addition & 0 deletions kickstarter/templates/default/README.md
@@ -0,0 +1 @@
# {{ PROJECT_NAME }}
5 changes: 5 additions & 0 deletions kickstarter/templates/default/config.yaml
@@ -0,0 +1,5 @@
# YAML

server_name: dev.{{ project }}.com
host: 127.0.0.1
port: '5000'
5 changes: 5 additions & 0 deletions kickstarter/templates/default/default/__init__.py
@@ -0,0 +1,5 @@
from flask import Flask

app = Flask(__name__)

from __config_project_module__ import views
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions kickstarter/templates/default/default/views.py
@@ -0,0 +1,7 @@
from flask import render_template
from __config_project_module__ import app


@app.route('/')
def index():
return 'Hello {{ PROJECT_NAME }}'
26 changes: 26 additions & 0 deletions kickstarter/templates/default/fabfile.py
@@ -0,0 +1,26 @@
from fabric.api import local


def symlink(file_name, link):
local('sudo ln -sf %s %s' % (file_name, link))


def nginx():
symlink('{{ PROJECT_ROOT }}/server/local/nginx.conf', '/etc/nginx/sites-available/{{ PROJECT_MODULE }}.conf')
symlink('/etc/nginx/sites-available/{{ PROJECT_MODULE }}.conf', '/etc/nginx/sites-enabled/{{ PROJECT_MODULE }}.conf')
local('sudo /etc/init.d/nginx restart')


def install_requirements():
local('pip install -r requirements.pip')


def install_environment():
local('pip install -e .')


def install(env):
install_requirements()
install_environment()
local('sudo chmod 755 run.py')
nginx()
7 changes: 7 additions & 0 deletions kickstarter/templates/default/requirements.pip
@@ -0,0 +1,7 @@
Fabric==1.2.2
Flask==0.8
Jinja2==2.6
Werkzeug==0.8.1
blinker==1.1
paramiko==1.7.7.1
pycrypto==2.3
5 changes: 5 additions & 0 deletions kickstarter/templates/default/run.py
@@ -0,0 +1,5 @@
#! /usr/bin/env python

from __config_project_module__ import app

app.run()
Empty file.
21 changes: 21 additions & 0 deletions kickstarter/templates/default/server/local/nginx.conf
@@ -0,0 +1,21 @@
server {

listen 80;
server_name {{ SERVER_NAME }};

location / {
proxy_pass http://{{ HOST }}:{{ PORT }};
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /static/ {
alias {{ PROJECT_ROOT }}/static/;
}

location /media/ {
alias {{ PROJECT_ROOT }}/media/;
}

}
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions kickstarter/templates/default/setup.py
@@ -0,0 +1,7 @@
#!/usr/bin/env python
from setuptools import setup, find_packages

setup(name='{{ PROJECT_MODULE }}',
version='0.1',
packages=find_packages(),
package_data={'{{ PROJECT }}': ['templates/*.*']})
Empty file.
1 change: 1 addition & 0 deletions kickstarter/templates/flask/README.md
@@ -0,0 +1 @@
# {{ PROJECT_NAME }}
5 changes: 5 additions & 0 deletions kickstarter/templates/flask/config.yaml
@@ -0,0 +1,5 @@
# YAML

server_name: dev.{{ project }}.com
host: 127.0.0.1
port: '5000'
26 changes: 26 additions & 0 deletions kickstarter/templates/flask/fabfile.py
@@ -0,0 +1,26 @@
from fabric.api import local


def symlink(file_name, link):
local('sudo ln -sf %s %s' % (file_name, link))


def nginx():
symlink('{{ PROJECT_ROOT }}/server/local/nginx.conf', '/etc/nginx/sites-available/{{ PROJECT_MODULE }}.conf')
symlink('/etc/nginx/sites-available/{{ PROJECT_MODULE }}.conf', '/etc/nginx/sites-enabled/{{ PROJECT_MODULE }}.conf')
local('sudo /etc/init.d/nginx restart')


def install_requirements():
local('pip install -r requirements.pip')


def install_environment():
local('pip install -e .')


def install(env):
install_requirements()
install_environment()
local('sudo chmod 755 run.py')
nginx()
5 changes: 5 additions & 0 deletions kickstarter/templates/flask/flask/__init__.py
@@ -0,0 +1,5 @@
from flask import Flask

app = Flask(__name__)

from __config_project_module__ import views
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions kickstarter/templates/flask/flask/views.py
@@ -0,0 +1,7 @@
from flask import render_template
from __config_project_module__ import app


@app.route('/')
def index():
return 'Hello {{ PROJECT_NAME }}'
7 changes: 7 additions & 0 deletions kickstarter/templates/flask/requirements.pip
@@ -0,0 +1,7 @@
Fabric==1.2.2
Flask==0.8
Jinja2==2.6
Werkzeug==0.8.1
blinker==1.1
paramiko==1.7.7.1
pycrypto==2.3
5 changes: 5 additions & 0 deletions kickstarter/templates/flask/run.py
@@ -0,0 +1,5 @@
#! /usr/bin/env python

from __config_project_module__ import app

app.run()
Empty file.
21 changes: 21 additions & 0 deletions kickstarter/templates/flask/server/local/nginx.conf
@@ -0,0 +1,21 @@
server {

listen 80;
server_name {{ SERVER_NAME }};

location / {
proxy_pass http://{{ HOST }}:{{ PORT }};
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /static/ {
alias {{ PROJECT_ROOT }}/static/;
}

location /media/ {
alias {{ PROJECT_ROOT }}/media/;
}

}
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions kickstarter/templates/flask/setup.py
@@ -0,0 +1,7 @@
#!/usr/bin/env python
from setuptools import setup, find_packages

setup(name='{{ PROJECT_MODULE }}',
version='0.1',
packages=find_packages(),
package_data={'{{ PROJECT }}': ['templates/*.*']})
Empty file.

0 comments on commit f020662

Please sign in to comment.