| Total Complexity | 9 |
| Total Lines | 30 |
| Duplicated Lines | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 1 |
| 1 | #!/usr/bin/env python |
||
| 23 | class Config(dict): |
||
| 24 | def __init__(self, filename): |
||
| 25 | self.path = self.findFile(filename) |
||
| 26 | with open(self.path) as file: |
||
| 27 | self.merge(json.load(file)) |
||
| 28 | |||
| 29 | def merge(self, data): |
||
| 30 | merge_dict(self, data) |
||
| 31 | |||
| 32 | @classmethod |
||
| 33 | def findFile(cls, filename): |
||
| 34 | if os.path.isfile(filename): |
||
| 35 | return filename |
||
| 36 | |||
| 37 | command = sys.argv[0] |
||
| 38 | if '/' != command[0]: |
||
| 39 | command = os.path.normpath(os.path.join(os.getcwd(), command)) |
||
| 40 | path = os.path.join(os.path.dirname(os.path.dirname(command)), 'etc', filename) |
||
| 41 | if os.path.isfile(path): |
||
| 42 | return path |
||
| 43 | |||
| 44 | if ':' in filename: |
||
| 45 | return cls.findFile(filename.split(':', 1)[0]) |
||
| 46 | |||
| 47 | ext = os.path.splitext(filename)[1] |
||
| 48 | |||
| 49 | if ext != '.json': |
||
| 50 | return cls.findFile(filename + '.json') |
||
| 51 | else: |
||
| 52 | return os.path.join('/etc/heppy', filename) |
||
| 53 | |||
| 54 |