X-Git-Url: https://git.mdrn.pl/fnpdeploy.git/blobdiff_plain/29714d0ceb75972088d7bc709e8e65061dfff48c..d0b568e2e2037ec2efde1aa41169d5d7a15280f4:/fnpdeploy/__init__.py?ds=sidebyside diff --git a/fnpdeploy/__init__.py b/fnpdeploy/__init__.py index 058accf..9010a5c 100644 --- a/fnpdeploy/__init__.py +++ b/fnpdeploy/__init__.py @@ -21,7 +21,6 @@ Then set up some env properties: """ from subprocess import check_output from os.path import abspath, dirname, exists, join -from django.utils.crypto import get_random_string from fabric.api import * from fabric.context_managers import settings from fabric.contrib import files @@ -31,6 +30,14 @@ env.virtualenv = '/usr/bin/virtualenv' env.services = None +def get_random_string(length=12, + allowed_chars='abcdefghijklmnopqrstuvwxyz' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'): + from random import SystemRandom + random = SystemRandom() + return ''.join(random.choice(allowed_chars) for i in range(length)) + + @task def setup(): """ @@ -216,22 +223,28 @@ def install_requirements(): print '>>> install requirements' require('release', provided_by=[deploy]) require('app_path') - if not files.exists('%(app_path)s/ve' % env): + set_ve() + if not files.exists(env.ve): + # HERE: maybe venv? require('virtualenv') - run('%(virtualenv)s %(app_path)s/ve' % env, pty=True) + run('%(virtualenv)s %(ve)s' % env, pty=True) with cd('%(app_path)s/releases/%(release)s' % env): - run('%(app_path)s/ve/bin/pip install -r requirements.txt' % env, pty=True) + run('%(ve)s/bin/pip install -r %(reqs)s' % {'ve': env.ve, 'reqs': env.get('requirements_file', 'requirements.txt')}, pty=True) with cd(get_django_root_path(env['release'])): # Install DB requirement database_reqs = { 'django.db.backends.postgresql_psycopg2': 'psycopg2', 'django.db.backends.mysql': 'MySQL-python', } - databases = run('''DJANGO_SETTINGS_MODULE=%(project_name)s.settings %(app_path)s/ve/bin/python -c 'from django.conf import settings; print " ".join(set([d["ENGINE"] for d in settings.DATABASES.values()]))' ''' % env) + databases = run( + 'DJANGO_SETTINGS_MODULE=%(project_name)s.settings ' + '%(ve)s/bin/python -c \'' + 'from django.conf import settings;' + 'print(" ".join(set([d["ENGINE"] for d in settings.DATABASES.values()])))\'' % env) for database in databases.split(): if database in database_reqs: # TODO: set pip default pypi - run('%(app_path)s/ve/bin/pip install ' % env + database_reqs[database]) + run('%(ve)s/bin/pip install ' % env + database_reqs[database]) def copy_localsettings(): @@ -258,10 +271,10 @@ def migrate(): print '>>> migrate' require('app_path', 'project_name') with cd(get_django_root_path('current')): - run('%(app_path)s/ve/bin/python manage.py syncdb --noinput' % env, pty=True) + run('%(ve)s/bin/python manage.py syncdb --noinput' % env, pty=True) for app, migration in env.get('migrate_fake', ()): - run('%s/ve/bin/python manage.py migrate %s --fake %s' % (env.app_path, app, migration), pty=True) - run('%(app_path)s/ve/bin/python manage.py migrate' % env, pty=True) + run('%s/bin/python manage.py migrate %s --fake %s' % (env.ve, app, migration), pty=True) + run('%(ve)s/bin/python manage.py migrate' % env, pty=True) def pre_collectstatic(): print '>>> pre_collectstatic' @@ -276,8 +289,7 @@ def collectstatic(): return require('app_path', 'project_name') with cd(get_django_root_path('current')): - run('%(app_path)s/ve/bin/python manage.py collectstatic --noinput' % env, pty=True) - + run('%(ve)s/bin/python manage.py collectstatic --noinput' % env, pty=True) def get_django_root_path(release): require('app_path') @@ -285,3 +297,7 @@ def get_django_root_path(release): if 'django_root_path' in env: path = join(path, env['django_root_path']) return path + +def set_ve(): + if 've' not in env: + env['ve'] = '%s/ve' % env.app_path