~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to djangoratings/__init__.py

  • Committer: franku
  • Date: 2018-11-21 17:54:32 UTC
  • mfrom: (508.1.1 widelands)
  • Revision ID: somal@arcor.de-20181121175432-8rc3h0332xmgmma4
merged trunk, resolved conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import os.path
2
 
import warnings
3
 
 
4
 
__version__ = (0, 3, 7)
5
 
 
6
 
 
7
 
def _get_git_revision(path):
8
 
    revision_file = os.path.join(path, 'refs', 'heads', 'master')
9
 
    if not os.path.exists(revision_file):
10
 
        return None
11
 
    fh = open(revision_file, 'r')
12
 
    try:
13
 
        return fh.read()
14
 
    finally:
15
 
        fh.close()
16
 
 
17
 
 
18
 
def get_revision():
19
 
    """
20
 
    :returns: Revision number of this branch/checkout, if available. None if
21
 
        no revision number can be determined.
22
 
    """
23
 
    package_dir = os.path.dirname(__file__)
24
 
    checkout_dir = os.path.normpath(os.path.join(package_dir, '..'))
25
 
    path = os.path.join(checkout_dir, '.git')
26
 
    if os.path.exists(path):
27
 
        return _get_git_revision(path)
28
 
    return None
29
 
 
30
 
__build__ = get_revision()
31
 
 
32
 
 
33
 
def lazy_object(location):
34
 
    def inner(*args, **kwargs):
35
 
        parts = location.rsplit('.', 1)
36
 
        warnings.warn('`djangoratings.%s` is deprecated. Please use `%s` instead.' % (
37
 
            parts[1], location), DeprecationWarning)
38
 
        try:
39
 
            imp = __import__(parts[0], globals(), locals(), [parts[1]], -1)
40
 
        except:
41
 
            imp = __import__(parts[0], globals(), locals(), [parts[1]])
42
 
        func = getattr(imp, parts[1])
43
 
        if callable(func):
44
 
            return func(*args, **kwargs)
45
 
        return func
46
 
    return inner
47
 
 
48
 
RatingField = lazy_object('djangoratings.fields.RatingField')
49
 
AnonymousRatingField = lazy_object('djangoratings.fields.AnonymousRatingField')
50
 
Rating = lazy_object('djangoratings.fields.Rating')