Passed
Push — master ( 525f7c...1e26bf )
by Dave
01:15
created

backend.fcmservice.Configuration.__init__()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
import os
2
3
class ServiceName:
4
    '''names of infrastructure services'''
5
    messagebus = 'rabbit'
6
    cache = 'redis'
7
    database = 'mysql'
8
    email = 'gmail'
9
    telegram = 'telegram'
10
11
class InfrastructureService:
12
    '''configuration for a dependency'''
13
    def __init__(self, name, connection, host, port, user, password):
14
        self.name = name
15
        self.connection = connection
16
        self.host = host
17
        self.port = port
18
        self.user = user
19
        self.password = password
20
21
class Configuration(object):
22
    def __init__(self, config):
23
        self.__config = config
24
25
    def get(self, key):
26
        if not key in self.__config:
27
            return None
28
        return self.__config[key]
29
30
    def is_enabled(self, key):
31
        lookupkey = '{0}.enabled'.format(key)
32
        if not lookupkey in self.__config:
33
            return False
34
        value = self.__config[lookupkey]
35
        if isinstance(value, str):
36
            return value == 'true' or value == 'True'
37
        return value
38
39
class Telegram(object):
40
    def __init__(self, config, service):
41
        self.configuration = config
42
        self.service = service
43
44
    def sendtelegramphoto(self, file_name):
45
        if os.path.isfile(file_name) and os.path.getsize(file_name) > 0:
46
            if self.configuration.is_enabled('telegram'):
47
                sendphoto(file_name, self.service)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable sendphoto does not seem to be defined.
Loading history...
48
49