-
Notifications
You must be signed in to change notification settings - Fork 5
/
aaconfig.py
executable file
·43 lines (36 loc) · 1.09 KB
/
aaconfig.py
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
38
39
40
41
42
43
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import configparser
import io
import os
import sys
config = configparser.RawConfigParser()
def configura_default():
config['user'] = {'nickname':'' , 'email': '', 'interval': 15}
__save()
def __save():
with open(__get_config_file(), "w") as configfile:
config.write(configfile)
def configura(params):
config.read(__get_config_file())
if not config.has_section('user'):
configura_default()
if len(params) == 2:
attribute, value = params
if attribute.count('.') == 1:
section, attribute = attribute.split('.')
if not (section in config):
config[section] = {}
config[section][attribute] = value
else:
config['user'][attribute] = value
#config.set('user', params[0], params[1])
__save()
def get_config(params):
config.read(__get_config_file())
section, attribute = params
return config[section][attribute]
def __get_config_file():
return os.getenv('HOME')+'/.aaconfig'
if __name__ == "__main__":
configura()