-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.py
More file actions
37 lines (26 loc) · 946 Bytes
/
Copy pathconfig.py
File metadata and controls
37 lines (26 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
from configparser import ConfigParser
class Config:
raw_config_object = None
FILES_SECTION = ''
COMPRESSION_SECTION = ''
TRANSPORT_SECTION = ''
ENCRYPTION_SECTION = ''
def __init__(self, filename: str):
self.raw_config_object = self.get_config_object(filename)
self.COMPRESSION_SECTION = 'COMPRESSION'
self.TRANSPORT_SECTION = 'TRANSPORT'
self.ENCRYPTION_SECTION = 'ENCRYPTION'
self.FILES_SECTION = 'FILES'
self.validate()
'''
exceptions:
ValueError: (if tmp directory is not writable)
'''
def validate(self):
if not os.access(self.raw_config_object[self.FILES_SECTION]['tmp_directory'], os.W_OK):
raise ValueError('Tmp directory is not writable')
def get_config_object(self, filename: str) -> dict:
config_parser = ConfigParser()
config_parser.read(filename)
return config_parser