forked from chathaway-codes/django-cms-bootstrap-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
148 lines (120 loc) · 4.38 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
from __future__ import print_function
from fabric.api import *
from fabric.colors import green
from fabric.contrib.console import confirm
from contextlib import contextmanager as _contextmanager
django_template = "https://github.com/chuck211991/django_template/zipball/master"
application_description = """
This wizard will ask you a series of questions it will use to generate a
standarized Django skeleton application. The Django application can be run
locally, for testing, with a default site or imported into another Django
application. A disutils setup.py file will also be configured and setup.
For the sake of simplicity, I am assuming you cloned this skeleton from a git
repository somewhere. Therefore, I am also assuming you have the following
fils in this directory:
* .gitignore
* libraries.txt
* libraries-vcs.txt
* README.md
Let's get started!
"""
activate_base_script = """
if [ ! -d "{env_name}/" ]; then
virtualenv {env_name}/
. ./{env_name}/bin/activate
pip install -r libraries.txt
fi
. ./{env_name}/bin/activate
"""
setup_py_base = """
import os, sys
try:
from setuptools import setup
except:
from distutils.core import setup
# Utility function to read the README file.
# Used for the long_description. It's nice, because now 1) we have a top level
# README file and 2) it's easier to type in the README file than to put a raw
# string in below ...
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
def read_requirements(fname):
f = open(os.path.join(os.path.dirname(__file__), fname))
return filter(lambda f: f != '', map(lambda f: f.strip(), f.readlines()))
setup(
zip_safe = False,
name = "{name}",
version = "{version}",
author = "{author}",
author_email = "{author_email}",
description = "{short_description}",
keywords = "",
packages=['{package_name}'],
long_description=read('README.md'),
install_requires = read_requirements('libraries.txt'),
test_suite = "dummy",
)
"""
django_manage_py = """
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{app_name}.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
"""
@_contextmanager
def virtualenv(virtualenv_dir):
with prefix('. ' + virtualenv_dir + '/bin/activate'):
yield
def start():
print(green("Hello! Welcome to the Django-App skeleton application"))
print(application_description)
print("All the following values can be updated by modifying setup.py")
application_name = prompt("Application name:")
package_name = prompt("Package name:", default=application_name)
version = prompt("Version:", default="1.0.0")
with hide('running'):
author = local('git config user.name', capture=True)
email = local('git config user.email', capture=True)
author = prompt("Author:", default=author)
email = prompt("Author email:", default=email)
short_description = prompt("Short description:")
print("Alright! Creating the setup.py file: ", end='')
f = open('setup.py', 'w')
f.write(
setup_py_base.format(
name=application_name,
package_name=package_name,
version=version,
author=author,
author_email=email,
short_description=short_description
)
)
print("done!")
env_name = setup_virtualenv()
setup_project(env_name, package_name)
def setup_virtualenv():
print("Time to create the Python virtual environment")
print("This makes it easier to manage multiple applications")
env_name = prompt("Environment name:", default="python")
local('virtualenv ' + env_name)
with virtualenv(env_name):
local('pip install -r libraries.txt')
print("Creating *nix activation script...")
f = open('activate', 'w')
f.write(
activate_base_script.format(
env_name = env_name
)
)
return env_name
def setup_project(env_name, app_name):
print("Creating project...")
with virtualenv(env_name):
local('django-admin.py startproject --template=%s %s' % (django_template, app_name))
local('mv %s %s.temp' % (app_name, app_name))
local('mv %s.temp/* .' % app_name)
local('rm -R %s.temp' % app_name)