-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy path__init__.py
More file actions
75 lines (57 loc) · 1.92 KB
/
__init__.py
File metadata and controls
75 lines (57 loc) · 1.92 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
django-devserver
~~~~~~
`django-devserver <http://www.github.com/dcramer/django-devserver>` is a package
that aims to replace the built-in runserver command by providing additional
functionality such as real-time SQL debugging.
:copyright: 2010 by David Cramer
"""
__all__ = ('__version__', '__build__', '__docformat__', 'get_revision')
__version__ = (0, 8, 0)
__docformat__ = 'restructuredtext en'
import os
def _get_git_revision(path):
revision_file = os.path.join(path, 'refs', 'heads', 'master')
if not os.path.exists(revision_file):
return None
fh = open(revision_file, 'r')
try:
return fh.read().strip()
finally:
fh.close()
def get_revision():
"""
:returns: Revision number of this branch/checkout, if available. None if
no revision number can be determined.
"""
package_dir = os.path.dirname(__file__)
checkout_dir = os.path.normpath(os.path.join(package_dir, '..'))
path = os.path.join(checkout_dir, '.git')
if os.path.exists(path):
return _get_git_revision(path)
return None
__build__ = get_revision()
def get_version():
base = '.'.join(map(str, __version__))
if __build__:
base = '%s (%s)' % (base, __build__)
return base
def patch_get_commands():
# Make autoreload use the devserver's runserver command instead of the
# default one. This prevent crashing the devserver on a syntax error
import functools
import django.core.management
original = django.core.management.get_commands
if getattr(original, '_wrapped', False):
return
@functools.wraps(original)
def wrapper(*args, **kwargs):
commands = original(*args, **kwargs)
commands['runserver'] = 'devserver'
return commands
wrapper._wrapped = True
django.core.management.get_commands = wrapper
import django
major, minor = django.VERSION[:2]
if major >= 1 and minor >= 8:
patch_get_commands()