~ubuntu-branches/debian/stretch/electrum/stretch

« back to all changes in this revision

Viewing changes to gui/kivy/tools/.buildozer/android/platform/python-for-android/dist/kivy/python-install/lib/python2.7/site-packages/kivy/core/__init__.py

  • Committer: Package Import Robot
  • Author(s): Tristan Seligmann
  • Date: 2016-04-04 03:02:39 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20160404030239-0szgkio8yryjv7c9
Tags: 2.6.3-1
* New upstream release.
  - Drop backported install-wizard-connect.patch.
* Add Suggests: python-zbar and update the installation hint to suggest
  apt-get instead of pip (closes: #819517).
* Bump Standards-Version to 3.9.7 (no changes).
* Update Vcs-* links.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'''
 
2
Core Abstraction
 
3
================
 
4
 
 
5
This module defines the abstraction layers for our core providers and their
 
6
implementations. For further information, please refer to
 
7
:ref:`architecture` and the :ref:`providers` section of the documentation.
 
8
 
 
9
In most cases, you shouldn't directly use a library that's already covered
 
10
by the core abstraction. Always try to use our providers first.
 
11
In case we are missing a feature or method, please let us know by
 
12
opening a new Bug report instead of relying on your library.
 
13
 
 
14
.. warning::
 
15
    These are **not** widgets! These are just abstractions of the respective
 
16
    functionality. For example, you cannot add a core image to your window.
 
17
    You have to use the image **widget** class instead. If you're really
 
18
    looking for widgets, please refer to :mod:`kivy.uix` instead.
 
19
'''
 
20
 
 
21
 
 
22
import os
 
23
import sys
 
24
import traceback
 
25
import kivy
 
26
from kivy.logger import Logger
 
27
 
 
28
 
 
29
class CoreCriticalException(Exception):
 
30
    pass
 
31
 
 
32
 
 
33
def core_select_lib(category, llist, create_instance=False,
 
34
                    base='kivy.core', basemodule=None):
 
35
    if 'KIVY_DOC' in os.environ:
 
36
        return
 
37
    category = category.lower()
 
38
    basemodule = basemodule or category
 
39
    libs_ignored = []
 
40
    errs = []
 
41
    for option, modulename, classname in llist:
 
42
        try:
 
43
            # module activated in config ?
 
44
            try:
 
45
                if option not in kivy.kivy_options[category]:
 
46
                    libs_ignored.append(modulename)
 
47
                    Logger.debug(
 
48
                        '{0}: Provider <{1}> ignored by config'.format(
 
49
                            category.capitalize(), option))
 
50
                    continue
 
51
            except KeyError:
 
52
                pass
 
53
 
 
54
            # import module
 
55
            mod = __import__(name='{2}.{0}.{1}'.format(
 
56
                basemodule, modulename, base),
 
57
                globals=globals(),
 
58
                locals=locals(),
 
59
                fromlist=[modulename], level=0)
 
60
            cls = mod.__getattribute__(classname)
 
61
 
 
62
            # ok !
 
63
            Logger.info('{0}: Provider: {1}{2}'.format(
 
64
                category.capitalize(), option,
 
65
                '({0} ignored)'.format(libs_ignored) if libs_ignored else ''))
 
66
            if create_instance:
 
67
                cls = cls()
 
68
            return cls
 
69
 
 
70
        except ImportError as e:
 
71
            errs.append((option, e, sys.exc_info()[2]))
 
72
            libs_ignored.append(modulename)
 
73
            Logger.debug('{0}: Ignored <{1}> (import error)'.format(
 
74
                category.capitalize(), option))
 
75
            Logger.trace('', exc_info=e)
 
76
 
 
77
        except CoreCriticalException as e:
 
78
            errs.append((option, e, sys.exc_info()[2]))
 
79
            Logger.error('{0}: Unable to use {1}'.format(
 
80
                category.capitalize(), option))
 
81
            Logger.error(
 
82
                '{0}: The module raised an important error: {1!r}'.format(
 
83
                    category.capitalize(), e.message))
 
84
            raise
 
85
 
 
86
        except Exception as e:
 
87
            errs.append((option, e, sys.exc_info()[2]))
 
88
            libs_ignored.append(modulename)
 
89
            Logger.trace('{0}: Unable to use {1}'.format(
 
90
                category.capitalize(), option, category))
 
91
            Logger.trace('', exc_info=e)
 
92
 
 
93
    err = '\n'.join(['{} - {}: {}\n{}'.format(opt, e.__class__.__name__, e,
 
94
                   ''.join(traceback.format_tb(tb))) for opt, e, tb in errs])
 
95
    Logger.critical(
 
96
        '{0}: Unable to find any valuable {0} provider at all!\n{1}'.format(
 
97
            category.capitalize(), err))
 
98
 
 
99
 
 
100
def core_register_libs(category, libs, base='kivy.core'):
 
101
    if 'KIVY_DOC' in os.environ:
 
102
        return
 
103
    category = category.lower()
 
104
    kivy_options = kivy.kivy_options[category]
 
105
    libs_loadable = {}
 
106
    libs_ignored = []
 
107
 
 
108
    for option, lib in libs:
 
109
        # module activated in config ?
 
110
        if option not in kivy_options:
 
111
            Logger.debug('{0}: option <{1}> ignored by config'.format(
 
112
                category.capitalize(), option))
 
113
            libs_ignored.append(lib)
 
114
            continue
 
115
        libs_loadable[option] = lib
 
116
 
 
117
    libs_loaded = []
 
118
    for item in kivy_options:
 
119
        try:
 
120
            # import module
 
121
            try:
 
122
                lib = libs_loadable[item]
 
123
            except KeyError:
 
124
                continue
 
125
            __import__(name='{2}.{0}.{1}'.format(category, lib, base),
 
126
                       globals=globals(),
 
127
                       locals=locals(),
 
128
                       fromlist=[lib],
 
129
                       level=0)
 
130
 
 
131
            libs_loaded.append(lib)
 
132
 
 
133
        except Exception as e:
 
134
            Logger.trace('{0}: Unable to use <{1}> as loader!'.format(
 
135
                category.capitalize(), option))
 
136
            Logger.trace('', exc_info=e)
 
137
            libs_ignored.append(lib)
 
138
 
 
139
    Logger.info('{0}: Providers: {1} {2}'.format(
 
140
        category.capitalize(),
 
141
        ', '.join(libs_loaded),
 
142
        '({0} ignored)'.format(
 
143
            ', '.join(libs_ignored)) if libs_ignored else ''))
 
144
    return libs_loaded