-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfabfile.py
101 lines (78 loc) · 2.25 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
import os
import getpass
import datetime
from fabric.contrib import django
from fabric.context_managers import hide, cd
from fabric.operations import local, prompt, env, run, sudo
from fabric.decorators import task, roles
from fabric.utils import puts
from fabric.tasks import execute
from fabric.colors import green, cyan
BASE_DIR = os.path.dirname(os.path.realpath(__file__))
django.settings_module('{{ project_name }}.settings')
import django
django.setup()
from django.contrib.auth import get_user_model
ADMIN_EMAIL_ADDRESS = '[email protected]'
env.project_name = '{{ project_name }}'
env.project_root_dir = os.path.dirname(os.path.abspath(__file__))
env.project_src_dir = '{project_root_dir}/{project_name}'.format(**env)
@task
def pipenv_requirements():
"""
Update the requirements using global pipenv.
"""
with cd(env.project_src_dir):
run('pipenv install')
@task
def migrate():
"""
Run DB migrations.
"""
pipenv_run('python manage.py migrate')
@task
def npm_install():
"""
Install NPM dependencies and build
"""
with cd(env.node_modules_dir):
run('npm install')
@task
def collectstatic():
"""
Run DB migrations.
"""
pipenv_run('python manage.py collectstatic --noinput')
def pipenv_run_local(command):
"""
Run a "pipenv run" command locally.
"""
local('pipenv run {pipenv_command}'.format(pipenv_command=command, **env))
def pipenv_run(command):
"""
Run a "pipenv run" command on the server.
"""
with cd(env.project_src_dir):
run('pipenv run {pipenv_command}'.format(pipenv_command=command, **env))
def add_admin():
user_model = get_user_model()
admin = user_model(email=ADMIN_EMAIL_ADDRESS)
admin.is_superuser = True
admin.is_staff = True
admin.set_password('admin')
admin.save()
# def add_foo():
# pass
@task
def initial_data():
puts('==> Hi there! :)')
puts('==> Installing the requirements...')
local('pipenv install --dev')
puts('==> Creating the db...')
pipenv_run_local('python manage.py migrate')
local('bower install')
puts('==> Creating the superuser...')
add_admin()
# puts('==> Adding initial data...')
# add_foo()
puts('==> All done. Please do your thing and leave :)')