~ubuntu-branches/ubuntu/wily/bandit/wily-proposed

« back to all changes in this revision

Viewing changes to bandit/core/extension_loader.py

  • Committer: Package Import Robot
  • Author(s): Dave Walker (Daviey)
  • Date: 2015-07-22 09:01:39 UTC
  • Revision ID: package-import@ubuntu.com-20150722090139-fl0nluy0x8m9ctx4
Tags: upstream-0.12.0
ImportĀ upstreamĀ versionĀ 0.12.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding:utf-8 -*-
 
2
#
 
3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
 
4
# not use this file except in compliance with the License. You may obtain
 
5
# a copy of the License at
 
6
#
 
7
#      http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
9
# Unless required by applicable law or agreed to in writing, software
 
10
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
11
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
12
# License for the specific language governing permissions and limitations
 
13
# under the License.
 
14
 
 
15
from stevedore import extension
 
16
 
 
17
 
 
18
class Manager(object):
 
19
    def __init__(self, formatters_namespace='bandit.formatters',
 
20
                 plugins_namespace='bandit.plugins'):
 
21
        # Cache the extension managers, loaded extensions, and extension names
 
22
        self.load_formatters(formatters_namespace)
 
23
        self.formatters = list(self.formatters_mgr)
 
24
        self.formatter_names = self.formatters_mgr.names()
 
25
 
 
26
        self.load_plugins(plugins_namespace)
 
27
        self.plugins = list(self.plugins_mgr)
 
28
        self.plugin_names = self.plugins_mgr.names()
 
29
 
 
30
    def load_formatters(self, formatters_namespace):
 
31
        self.formatters_mgr = extension.ExtensionManager(
 
32
            namespace=formatters_namespace,
 
33
            # We don't want to call the formatter when we load it.
 
34
            invoke_on_load=False,
 
35
            # We don't care if the extension doesn't have the dependencies it
 
36
            # needs to start up.
 
37
            verify_requirements=False,
 
38
            )
 
39
 
 
40
    def load_plugins(self, plugins_namespace):
 
41
        # See comments in load_formatters for parameter explanations
 
42
        self.plugins_mgr = extension.ExtensionManager(
 
43
            namespace=plugins_namespace,
 
44
            invoke_on_load=False,
 
45
            verify_requirements=False,
 
46
            )
 
47
 
 
48
 
 
49
# Using entry-points and pkg_resources *can* be expensive. So let's load these
 
50
# once, store them on the object, and have a module global object for
 
51
# accessing them. After the first time this module is imported, it should save
 
52
# this attribute on the module and not have to reload the entry-points.
 
53
MANAGER = Manager()