| Total Complexity | 12 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 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) |
||
|
|
|||
| 48 | |||
| 49 |