This repository was archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
114 lines (84 loc) · 2.73 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
import os
from fabric.api import *
# === Utility functions ===
def _get_project_dir():
project_dir = '{{ project_name }}'
if '{' in project_dir:
for file in os.listdir(os.curdir):
if '.' not in file:
return file
return project_dir
def _get_settings(module='settings'):
settings_module = '%s.%s' % (_get_project_dir(), module)
print 'Using settings:', settings_module
return settings_module
# === Environments ===
def dev():
env.env = 'dev'
env.settings = _get_settings('dev_settings')
# def staging():
# env.env = 'staging'
# env.settings = '{{ project_name }}.settings.staging'
# env.remote = ''
# env.heroku_app = ''
#
#
# def production():
# env.env = 'production'
# env.settings = '{{ project_name }}.settings.production'
# env.remote = ''
# env.heroku_app = ''
# Default Environment
dev()
# === Utils ===
def manage(command='help'):
man = 'python manage.py %s --settings={settings}' % command
local(man.format(**env))
# === Static assets stuff ===
def collectstatic():
# brunchbuild()
local('python manage.py collectstatic --noinput --settings={settings}'.format(**env))
# === DB ===
def resetdb(create_admin=False):
if env.env == 'dev':
with settings(warn_only=True):
local('rm -f dev.db')
local('python manage.py syncdb --settings={settings} --noinput --all'.format(**env))
local('python manage.py migrate --settings={settings} --fake'.format(**env))
else:
# Your production code here
pass
loaddata()
if create_admin:
local('python manage.py createsuperuser --settings={settings}'.format(**env))
manage('goscale update_posts')
def schemamigration(app_names='core'):
local('python manage.py schemamigration {app_names} --auto --settings={settings}'.format(app_names, **env))
def migrate():
if env.env == 'dev':
local('python manage.py migrate --settings={settings}'.format(**env))
else:
# Your production code here
pass
def updatedb(app_names=None):
if app_names:
schemamigration(app_names)
else:
schemamigration()
migrate()
def dumpdata():
manage('goscale dump')
def loaddata():
manage('goscale load')
# === Bootstrap the environment ===
def bootstrap(create_admin=False, virtualenv=None, static=False):
if virtualenv:
local('mkvirtualenv %s' % 'goscale' if type(virtualenv) is bool else virtualenv)
local('pip install -r requirements.txt')
resetdb(create_admin)
if static:
collectstatic()
print 'Project is ready, execute "fab run" to run the server.'
# === Routine tasks ===
def run():
local('python manage.py runserver --settings=%s' % env.settings)