Last active
December 11, 2015 22:18
-
-
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
This file contains hidden or 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
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