-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
53 lines (44 loc) · 1.89 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
import os
from invoke import task, util
LOCAL_ROOT = os.path.dirname(os.path.realpath(__file__))
DOCKER_DEV_COMMAND_ROOT = 'docker-compose -f docker-compose.yml -f docker-compose.override.yml'
DOCKER_PROD_COMMAND_ROOT = 'docker-compose -f docker-compose.yml -f docker-compose.prod.yml'
@task
def control_docker_dev(ctx, cmd='up -d'):
ctx.run('cd {} && {} {}'.format(
LOCAL_ROOT,
DOCKER_DEV_COMMAND_ROOT,
cmd
))
@task
def run_tests(ctx, module='demotime', opts='', pty=True):
print("Cleaning out pycs")
ctx.run('find . -type f -name \*.pyc -delete')
with util.cd(os.path.join(LOCAL_ROOT, 'dt')):
ctx.run(
'TESTS=true coverage run --source=demotime manage.py test {} {}'.format(
module, opts
),
pty=pty
)
ctx.run('coverage xml')
@task
def load_test_data(ctx, filename='demotime_test_data.sql.gz'):
print("This will delete all of the data in the database, and recreate it from a backup. Are you sure?")
print("Press ctrl-c to exit, enter to continue")
input()
ctx.run('cp data/{} ~/dt_backups/'.format(filename))
ctx.run('docker exec -i src_db_1 su - postgres -c "dropdb postgres && createdb -EUNICODE -Opostgres postgres && zcat /backups/{} | psql postgres"'.format(
filename
))
ctx.run('docker exec -i src_demotime_1 python3 manage.py migrate --noinput')
ctx.run('docker restart src_demotime_1')
ctx.run('docker restart src_demotime_celery_1')
ctx.run('rm -f ~/dt_backups/{}'.format(filename))
@task
def purge_docker_emails(ctx):
print('Deleting the following email files')
ctx.run('docker exec src_demotime_1 ls -l /usr/local/demotime/static/emails/')
ctx.run('docker exec src_demotime_1 /home/docker/demotime/dt/purge_emails.sh')
print('Deletion complete')
ctx.run('docker exec src_demotime_1 ls -l /usr/local/demotime/static/emails/')