-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.py
More file actions
31 lines (26 loc) · 924 Bytes
/
config.py
File metadata and controls
31 lines (26 loc) · 924 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
import os
import configparser
DEFAULT_CONFIG = {
'delete_file': True,
'file_directory': "Downloads"
}
class PrinterConfiguration:
def __init__(self, filename='config.ini'):
self.filename = filename
self.config = configparser.ConfigParser()
def read(self):
if not os.path.exists(self.filename):
self.create_default_config()
self.config.read(self.filename)
return self.config
def create_default_config(self):
self.config['DEFAULT'] = DEFAULT_CONFIG
with open(self.filename, 'w') as configfile:
self.config.write(configfile)
def update(self, section, key, value):
self.config.read(self.filename)
if section not in self.config:
self.config[section] = {}
self.config[section][key] = value
with open(self.filename, 'w') as configfile:
self.config.write(configfile)