Passed
Push — master ( 61b47f...c33b3f )
by Emmanuel
05:17
created

stakkr.actions.StakkrActions._get_config()   A

Complexity

Conditions 2

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 7
nop 1
dl 0
loc 8
ccs 7
cts 7
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
# coding: utf-8
2 1
"""Stakkr main controller. Used by the CLI to do all its actions."""
3
4 1
import os
5 1
from platform import system as os_name
6 1
import subprocess
7 1
import sys
8 1
import click
9 1
from clint.textui import colored, puts, columns
10 1
from stakkr import command, docker_actions as docker
11 1
from stakkr.configreader import Config
12 1
from stakkr.proxy import Proxy
13
14
15 1
class StakkrActions:
16
    """Main class that does actions asked in the cli."""
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
17
18 1
    def __init__(self, ctx: dict):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
19
        """Set all require properties."""
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
20
        # Get info from config first to know the project name and project dir
21 1
        self.config_file = ctx['CONFIG']
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
22
23 1
        self.context = ctx
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
24
25
        # Set some general variables
26 1
        self.config = None
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
27 1
        self.project_name = None
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
28 1
        self.project_dir = None
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
29 1
        self.cwd_abs = os.getcwd()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
30 1
        self.cwd_relative = None
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
31 1
        self.cts = []
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
32 1
        self.running_cts = []
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
33
34 1
    def console(self, container: str, user: str, tty: bool):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
35
        """Enter a container. Stakkr will try to guess the right shell."""
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
36 1
        self.init_project()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
37
38 1
        docker.check_cts_are_running(self.project_name)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
39
40 1
        tty = 't' if tty is True else ''
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
41 1
        ct_name = docker.get_ct_name(container)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
42 1
        cmd = ['docker', 'exec', '-u', user, '-i' + tty]
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
43 1
        cmd += [docker.get_ct_name(container), docker.guess_shell(ct_name)]
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
44
        subprocess.call(cmd)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
45
46
        command.verbose(self.context['VERBOSE'], 'Command : "' + ' '.join(cmd) + '"')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (85/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
47
48 1
    def get_services_urls(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
49
        """Once started, displays a message with a list of running containers."""
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (81/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
50 1
        self.init_project()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
51
52 1
        cts = docker.get_running_containers(self.project_name)[1]
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
53
54 1
        text = ''
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
55 1
        for _, ct_info in cts.items():
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
56 1
            service_config = self.config['services'][ct_info['compose_name']]
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
57 1
            if ({'service_name', 'service_url'} <= set(service_config)) is False:
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (81/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
58 1
                continue
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
59
60 1
            url = self.get_url(service_config['service_url'], ct_info['compose_name'])
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (86/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
61 1
            name = colored.yellow(service_config['service_name'])
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
62
63 1
            text += '  - For {}'.format(name).ljust(55, ' ') + ' : ' + url + '\n'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (81/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
64
65 1
            if 'service_extra_ports' in service_config:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
66 1
                ports = ', '.join(map(str, service_config['service_extra_ports']))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (82/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
67 1
                text += ' '*4 + '(In your containers use the host '
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
68 1
                text += '"{}" and port(s) {})\n'.format(ct_info['compose_name'], ports)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (87/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
69
70 1
        return text
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
71
72 1
    def exec_cmd(self, container: str, user: str, args: tuple, tty: bool):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
73
        """Run a command from outside to any container. Wrapped into /bin/sh."""
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
74 1
        self.init_project()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
75
76 1
        docker.check_cts_are_running(self.project_name)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
77
78
        # Protect args to avoid strange behavior in exec
79 1
        args = ['"{}"'.format(arg) for arg in args]
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
80
81 1
        tty = 't' if tty is True else ''
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
82 1
        ct_name = docker.get_ct_name(container)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
83 1
        cmd = ['docker', 'exec', '-u', user, '-i' + tty, ct_name, 'sh', '-c']
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
84 1
        cmd += ["""test -d "/var/{0}" && cd "/var/{0}" ; exec {1}""".format(self.cwd_relative, ' '.join(args))]
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
85 1
        command.verbose(self.context['VERBOSE'], 'Command : "' + ' '.join(cmd) + '"')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (85/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
86 1
        subprocess.call(cmd, stdin=sys.stdin)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
87
88 1
    def get_config(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
89 1
        config = Config(self.config_file)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
90 1
        main_config = config.read()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
91 1
        if main_config is False:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
92 1
            config.display_errors()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
93 1
            sys.exit(1)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
94
95 1
        return main_config
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
96
97 1
    def init_project(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
98
        """
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
99
        Initializing the project by reading config and
100
        setting some properties of the object
101
        """
102 1
        if self.config is not None:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
103 1
            return
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
104
105 1
        self.config = self.get_config()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
106 1
        self.project_name = self.config['project_name']
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
107 1
        self.project_dir = self.config['project_dir']
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
108 1
        sys.path.append(self.project_dir)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
109
110 1
        self.cwd_relative = self._get_relative_dir()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
111 1
        os.chdir(self.project_dir)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
112
113 1
    def start(self, container: str, pull: bool, recreate: bool, proxy: bool):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
114
        """If not started, start the containers defined in config."""
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
115 1
        self.init_project()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
116 1
        verb = self.context['VERBOSE']
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
117 1
        debug = self.context['DEBUG']
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
118
119 1
        self._is_up(container)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
120
121 1
        if pull is True:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
122
            command.launch_cmd_displays_output(self._get_compose_base_cmd() + ['pull'], verb, debug, True)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (106/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
123
124 1
        recreate_param = '--force-recreate' if recreate is True else '--no-recreate'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (84/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
125 1
        cmd = self._get_compose_base_cmd() + ['up', '-d', recreate_param, '--remove-orphans']
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (93/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
126 1
        cmd += _get_single_container_option(container)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
127
128 1
        command.verbose(self.context['VERBOSE'], 'Command: ' + ' '.join(cmd))
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
129 1
        command.launch_cmd_displays_output(cmd, verb, debug, True)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
130
131 1
        self.running_cts, self.cts = docker.get_running_containers(self.project_name)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (85/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
132 1
        if self.running_cts is 0:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
133
            raise SystemError("Couldn't start the containers, run the start with '-v' and '-d'")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (96/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
134
135 1
        self._run_iptables_rules()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
136 1
        if proxy is True:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
137 1
            network_name = docker.get_network_name(self.project_name)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
138 1
            Proxy(self.config['proxy'].get('port')).start(network_name)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
139
140 1
    def status(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
141
        """Return a nice table with the list of started containers."""
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
142 1
        self.init_project()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
143
144 1
        try:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
145 1
            docker.check_cts_are_running(self.project_name)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
146 1
        except SystemError:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
147 1
            puts(colored.yellow('[INFO]') + ' stakkr is currently stopped')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
148 1
            sys.exit(0)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
149
150 1
        self._print_status_headers()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
151 1
        self._print_status_body()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
152
153 1
    def stop(self, container: str, proxy: bool):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
154
        """If started, stop the containers defined in config. Else throw an error."""
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (85/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
155 1
        self.init_project()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
156 1
        verb = self.context['VERBOSE']
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
157 1
        debug = self.context['DEBUG']
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
158
159 1
        docker.check_cts_are_running(self.project_name)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
160
161 1
        cmd = self._get_compose_base_cmd() + ['stop'] + _get_single_container_option(container)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (95/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
162 1
        command.launch_cmd_displays_output(cmd, verb, debug, True)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
163
164 1
        self.running_cts, self.cts = docker.get_running_containers(self.project_name)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (85/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
165 1
        if self.running_cts is not 0 and container is None:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
166
            raise SystemError("Couldn't stop services ...")
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
167
168 1
        if proxy is True:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
169 1
            Proxy(self.config['proxy'].get('port')).stop()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
170
171 1
    def _get_compose_base_cmd(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
172 1
        if self.context['CONFIG'] is None:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
173
            return ['stakkr-compose']
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
174
175 1
        return ['stakkr-compose', '-c', self.context['CONFIG']]
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
176
177 1
    def _get_relative_dir(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
178 1
        if self.cwd_abs.startswith(self.project_dir):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
179
            return self.cwd_abs[len(self.project_dir):].lstrip('/')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
180
181 1
        return ''
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
182
183 1
    def _is_up(self, container: str):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
184 1
        try:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
185 1
            docker.check_cts_are_running(self.project_name)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
186 1
        except SystemError:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
187 1
            return
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
188
189 1
        if container is None:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
190 1
            puts(colored.yellow('[INFO]') + ' stakkr is already started ...')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
191 1
            sys.exit(0)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
192
193
        # If single container : check if that specific one is running
194 1
        ct_name = docker.get_ct_item(container, 'name')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
195 1
        if docker.container_running(ct_name):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
196 1
            puts(colored.yellow('[INFO]') + ' service {} is already started ...'.format(container))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (99/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
197 1
            sys.exit(0)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
198
199 1
    def _print_status_headers(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
200 1
        puts(columns(
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
201
            [(colored.green('Container')), 16], [colored.green('IP'), 15],
202
            [(colored.green('Url')), 32], [(colored.green('Image')), 32],
203
            [(colored.green('Docker ID')), 15], [(colored.green('Docker Name')), 25]
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (84/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
204
            ))
205
206 1
        puts(columns(
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
207
            ['-'*16, 16], ['-'*15, 15],
208
            ['-'*32, 32], ['-'*32, 32],
209
            ['-'*15, 15], ['-'*25, 25]
210
            ))
211
212 1
    def _print_status_body(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
213 1
        self.running_cts, self.cts = docker.get_running_containers(self.project_name)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (85/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
214
215 1
        for container in sorted(self.cts.keys()):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
216 1
            ct_data = self.cts[container]
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
217 1
            if ct_data['ip'] == '':
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
218
                continue
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
219
220 1
            puts(columns(
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
221
                [ct_data['compose_name'], 16], [ct_data['ip'], 15],
222
                [ct_data['traefik_host'], 32], [ct_data['image'], 32],
223
                [ct_data['id'][:12], 15], [ct_data['name'], 25]
224
                ))
225
226 1
    def _run_iptables_rules(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
227
        """For some containers we need to add iptables rules added from the config."""
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (86/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
228 1
        block_config = self.config['network-block']
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
229 1
        for container, ports in block_config.items():
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
230 1
            error, msg = docker.block_ct_ports(container, ports, self.project_name)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (83/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
231 1
            if error is True:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
232
                click.secho(msg, fg='red')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
233
                continue
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
234
235 1
            command.verbose(self.context['VERBOSE'], msg)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
236
237 1
    def get_url(self, service_url: str, service: str):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
238
        """Build URL to be displayed."""
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
239 1
        proxy_conf = self.config['proxy']
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
240
        # By default our URL is the IP
241 1
        url = docker.get_ct_item(service, 'ip')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
242
        # If proxy enabled, display nice urls
243 1
        if int(proxy_conf['enabled']) is 1:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
244 1
            url = docker.get_ct_item(service, 'traefik_host')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
245 1
            url += '' if int(proxy_conf['port']) is 80 else ':{}'.format(proxy_conf['port'])
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (92/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
246
        elif os_name() in ['Windows', 'Darwin']:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
247
            puts(colored.yellow('[WARNING]') + ' Under Win and Mac, you need the proxy enabled')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (96/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
248
249 1
        return service_url.format(url)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
250
251
252 1
def _get_single_container_option(container: str):
253 1
    if container is None:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
254 1
        return []
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
255
256
    return [container]
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
257