Last active
December 15, 2015 14:39
-
-
Save dominicrodger/5276253 to your computer and use it in GitHub Desktop.
Quick snippet for upgrading Django installs across multiple sites on Webfaction (see http://www.dominicrodger.com/upgrading-django.html)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fabric.api import env, run, cd, hide, prefix | |
env.use_ssh_config = True | |
env.hosts = ['dmr', ] | |
django_apps = { | |
'dmr': ['myappname', | |
'myotherapp', ], | |
} | |
def get_django_version(app): | |
with cd('~/webapps/%s/' % app), hide('running', 'stdout'), prefix('source env/bin/activate'): | |
result = run('pip freeze | grep "^Django=="') | |
django, version=result.split('==') | |
return version | |
def upgrade_django_install(app, version): | |
with cd('~/webapps/%s/' % app), prefix('source env/bin/activate'): | |
run('pip install Django==%s' % version) | |
run('apache2/bin/restart') | |
def upgrade_django(from_version, to_version): | |
apps = django_apps[env.host_string] | |
for app in apps: | |
version = get_django_version(app) | |
if version == from_version: | |
print "Current version of Django for %s is %s, upgrading to %s..." % (app, version, to_version) | |
upgrade_django_install(app, to_version) | |
else: | |
print "Current version of Django for %s is %s, no upgrade needed." % (app, version) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment