forked from pydemic/hcap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
104 lines (75 loc) · 2.21 KB
/
tasks.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
import os
from invoke import task
#
# Database
#
@task
def db(ctx):
"""Make migrations and then migrate."""
ctx.run("python manage.py makemigrations")
ctx.run("python manage.py migrate")
@task
def db_fake(ctx):
"""Populate with fake data."""
ctx.run("python manage.py migrate")
ctx.run("python manage.py createfakeusers --admin --roles")
ctx.run("python manage.py createfakeapp --scenario")
@task
def migrate(ctx):
"""Alias to Django's "migrate" command."""
ctx.run("python manage.py migrate")
@task
def migrations(ctx):
"""Alias to Django's "makemigrations" command."""
ctx.run("python manage.py makemigrations")
#
# Server
#
@task
def collectstatic(ctx):
ctx.run("python manage.py collectstatic --clear --no-input")
@task
def run(ctx):
"""Alias to Django's "runserver" command."""
ctx.run("python manage.py start")
#
# Development
#
@task
def clean(ctx, db=False, yes=False):
import re
auto_migration = re.compile(r"\d{4}_auto_\w+.py")
remove_files = []
for app in os.listdir("."):
migrations_path = f"{app}/migrations/"
if os.path.exists(migrations_path):
migrations = os.listdir(migrations_path)
if "__pycache__" in migrations:
migrations.remove("__pycache__")
elif sorted(migrations) == ["__init__.py", "0001_initial.py"]:
remove_files.append(f"{migrations_path}/0001_initial.py")
else:
remove_files.extend(
[f"{migrations_path}/{f}" for f in migrations if auto_migration.fullmatch(f)]
)
if remove_files:
print("Listing migrations:")
for file in remove_files:
print(f"* {file}")
if yes or input("Remove those files? (y/N)").lower() == "y":
for file in remove_files:
os.remove(file)
else:
print("No auto migrations found.")
if db:
try:
os.remove("db.sqlite3")
print("Removed db.sqlite3")
except FileNotFoundError:
print("No sqlite db to remove")
@task
def test(ctx):
ctx.run("python manage.py test_all")
@task
def shell(ctx):
ctx.run("python manage.py shell", pty=True)