Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

# -*- coding: UTF-8 -*- 

# Copyright 2002-2016 Luc Saffre 

# License: BSD (see file COPYING for details) 

 

"""This is the main module of the Lino framework. 

 

.. autosummary:: 

   :toctree: 

 

   core 

   hello 

   api 

   utils 

   mixins 

   projects 

   modlib 

   sphinxcontrib 

 

 

""" 

 

from __future__ import unicode_literals 

from __future__ import absolute_import 

 

import sys 

import os 

from os.path import join, dirname 

 

 

filename = join(dirname(__file__), 'setup_info.py') 

exec(compile(open(filename, "rb").read(), filename, 'exec')) 

 

# above line is equivalent to "execfile(filename)", except that it 

# works also in Python 3 

 

__version__ = SETUP_INFO['version'] 

intersphinx_urls = dict(docs="http://www.lino-framework.org") 

srcref_url = 'https://github.com/lsaffre/lino/blob/master/%s' 

 

 

if sys.version_info[0] > 2: 

    PYAFTER26 = True 

elif sys.version_info[0] == 2 and sys.version_info[1] > 6: 

    PYAFTER26 = True 

else: 

    PYAFTER26 = False 

 

 

def setup_project(settings_module): 

    os.environ['DJANGO_SETTINGS_MODULE'] = settings_module 

    from lino.api.shell import settings 

 

 

DJANGO_DEFAULT_LANGUAGE = 'en-us' 

 

 

def assert_django_code(django_code): 

    if '_' in django_code: 

        raise Exception("Invalid language code %r. " 

                        "Use values like 'en' or 'en-us'." % django_code) 

 

 

from django import VERSION 

 

AFTER17 = False 

AFTER18 = False 

if VERSION[0] == 1: 

    if VERSION[1] > 6: 

        AFTER17 = True 

        if VERSION[1] > 8: 

            AFTER18 = True 

else: 

    raise Exception("Unsupported Django version %s" % VERSION) 

 

 

def startup(settings_module=None): 

    """Start up Django and Lino. 

 

    Until Django 1.6 this was called automatically (by 

    :mod:`lino.modlib.lino_startup`), but this trick no longer worked 

    after 1.7. 

 

    This is called automatically when a process is invoked by a 

    *management command*. 

 

    For testable documents you need to call it manually using e.g.: 

 

    >>> import lino 

    >>> lino.startup('my.project.settings') 

 

    Note that above two lines are recommended over the old-style 

    method (which works only under Django 1.6):: 

 

    >>> import os 

    >>> os.environ['DJANGO_SETTINGS_MODULE'] = 'my.project.settings' 

 

    """ 

    #print "startup" 

    if settings_module: 

        import os 

        os.environ['DJANGO_SETTINGS_MODULE'] = settings_module 

 

    if AFTER17: 

        import django 

        django.setup() 

    #print "startup done" 

 

 

def site_startup(): 

    """Called from `lino.models` before Django 1.7""" 

    #print "site_startup" 

    from django.conf import settings 

    if False: 

        settings.SITE.startup() 

    else: 

        try: 

            settings.SITE.startup() 

        except ImportError as e: 

            import traceback 

            #~ traceback.print_exc(e) 

            #~ sys.exit(-1) 

            raise Exception("ImportError during startup:\n" + 

                            traceback.format_exc(e)) 

 

# deprecated use, only for backwards compat: 

from django.utils.translation import ugettext_lazy as _