Skip to content

Instantly share code, notes, and snippets.

@mariocesar
Last active December 11, 2015 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariocesar/4668165 to your computer and use it in GitHub Desktop.
Save mariocesar/4668165 to your computer and use it in GitHub Desktop.
Django wsgi patch. Every time it starts updates two files. changeset.txt with the current mercurial changeset, wsgistart_info.txt with the host and date of start
import os
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "crowddeals.settings")
def touch_wsgistart_info():
from mercurial import hg, ui
import time
import socket
root = os.path.abspath(os.path.dirname(__file__))
repo_path = os.path.join(root, '..')
repo = hg.repository(ui=ui.ui(), path=repo_path)
ctx = repo[None]
with file(os.path.join(root, 'templates/changeset.txt'), 'w') as f:
f.write('rev. %(num)s:%(rev)s%(changed)s (%(branch)s)' % {
'num': ctx.p1().rev(),
'rev': ctx.parents()[0],
'changed': '+' if ctx.status() else '',
'branch': ctx.branch()
})
with file(os.path.join(root, 'templates/wsgistart_info.txt'), 'w') as f:
f.write('since %s on %s' % (
time.asctime(time.localtime()),
socket.gethostname()
))
touch_wsgistart_info()
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment