You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.8 KiB
59 lines
1.8 KiB
4 years ago
|
#!/usr/bin/env python
|
||
|
# -*- coding: utf-8 -*-
|
||
|
|
||
|
"""-------------------------------------------------------------------------------------------
|
||
|
-- IMPORTS
|
||
|
-------------------------------------------------------------------------------------------"""
|
||
|
|
||
|
""" --- PYTHON IMPORTS --- """
|
||
|
import os, io, shutil
|
||
|
from os.path import dirname, abspath
|
||
|
|
||
|
from configobj import ConfigObj
|
||
|
from validate import Validator
|
||
|
|
||
|
"""-------------------------------------------------------------------------------------------
|
||
|
-- PUSHBULLET CONFIG
|
||
|
-------------------------------------------------------------------------------------------"""
|
||
|
|
||
|
class PushConfig(ConfigObj):
|
||
|
|
||
|
configspec = u"""
|
||
|
[PUSHBULLET]
|
||
|
api_key = string(default='')
|
||
|
channel = string(default='')
|
||
|
"""
|
||
|
|
||
|
def __init__(self):
|
||
|
super(PushConfig, self).__init__()
|
||
|
|
||
|
configspecfile = os.path.join(
|
||
|
dirname(abspath(__file__)),
|
||
|
'configspec.ini'
|
||
|
)
|
||
|
|
||
|
if not os.path.exists(configspecfile):
|
||
|
with open(configspecfile, 'w') as fd:
|
||
|
shutil.copyfileobj(io.StringIO(PushConfig.configspec), fd)
|
||
|
|
||
|
self.filename = os.path.join(
|
||
|
dirname(abspath(__file__)),
|
||
|
'config.ini'
|
||
|
)
|
||
|
self.configspec = configspecfile
|
||
|
self.encoding = "UTF8"
|
||
|
|
||
|
tmp = ConfigObj(self.filename, configspec=self.configspec, encoding=self.encoding)
|
||
|
validator = Validator()
|
||
|
tmp.validate(validator, copy=True)
|
||
|
|
||
|
self.merge(tmp)
|
||
|
|
||
|
if not os.path.exists(self.filename):
|
||
|
self.write()
|
||
|
|
||
|
"""-------------------------------------------------------------------------------------------
|
||
|
-- CONFIGURATION DEFINITION
|
||
|
-------------------------------------------------------------------------------------------"""
|
||
|
|
||
|
pushconfig = PushConfig()
|