GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AppContextCommand.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 4
rs 10
1
# -*- coding: utf-8 -*-
2
import os
3
import sys
4
5
from gearbox.command import Command
6
from paste.deploy import loadapp
7
from webtest import TestApp
8
9
10
class BaseCommand(Command):
11
    def take_action(self, parsed_args):
12
        raise NotImplementedError
13
14
15
class AppContextCommand(BaseCommand):
16
    """
17
    Command who initialize app context at beginning of take_action method.
18
    """
19
    def __init__(self, *args, **kwargs):
20
        super(AppContextCommand, self).__init__(*args, **kwargs)
21
        self._wsgi_app = None
22
        self._test_app = None
23
24
    @staticmethod
25
    def _get_initialized_app_context(parsed_args):
26
        """
27
        :param parsed_args: parsed args (eg. from take_action)
28
        :return: (wsgi_app, test_app)
29
        """
30
        config_file = parsed_args.config_file
31
        config_name = 'config:%s' % config_file
32
        here_dir = os.getcwd()
33
34
        # Load locals and populate with objects for use in shell
35
        sys.path.insert(0, here_dir)
36
37
        # Load the wsgi app first so that everything is initialized right
38
        wsgi_app = loadapp(config_name, relative_to=here_dir)
39
        test_app = TestApp(wsgi_app)
40
41
        # Make available the tg.request and other global variables
42
        tresponse = test_app.get('/_test_vars')
43
44
        return wsgi_app, test_app
45
46
    def take_action(self, parsed_args):
47
        wsgi_app, test_app = self._get_initialized_app_context(parsed_args)
48
        self._wsgi_app = wsgi_app
49
        self._test_app = test_app
50
51
    def get_parser(self, prog_name):
52
        parser = super(AppContextCommand, self).get_parser(prog_name)
53
54
        parser.add_argument("-c", "--config",
55
                            help='application config file to read '
56
                                 '(default: development.ini)',
57
                            dest='config_file', default="development.ini")
58
        return parser
59