Applied flake8 in config.
This commit is contained in:
parent
690f8ce792
commit
5510b6d3b9
@ -1,10 +1,9 @@
|
||||
import os
|
||||
import copy
|
||||
from .p3 import configparser
|
||||
|
||||
# constant stuff (DFT = DEFAULT)
|
||||
|
||||
MAIN_SECTION = 'papers'
|
||||
MAIN_SECTION = 'papers'
|
||||
DFT_CONFIG_PATH = os.path.expanduser('~/.papersrc')
|
||||
try:
|
||||
DFT_EDIT_CMD = os.environ['EDITOR']
|
||||
@ -32,16 +31,19 @@ BOOLEANS = {'import_copy', 'import_move', 'color', 'version_warning'}
|
||||
# package-shared config that can be accessed using :
|
||||
# from configs import config
|
||||
_config = None
|
||||
def config(section = MAIN_SECTION):
|
||||
|
||||
|
||||
def config(section=MAIN_SECTION):
|
||||
if _config is None:
|
||||
raise ValueError('not config instanciated yet')
|
||||
_config._section = section
|
||||
return _config
|
||||
|
||||
|
||||
class Config(object):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
object.__setattr__(self, '_section', MAIN_SECTION) # active section
|
||||
object.__setattr__(self, '_section', MAIN_SECTION) # active section
|
||||
object.__setattr__(self, '_cfg', configparser.SafeConfigParser())
|
||||
|
||||
self._cfg.add_section(self._section)
|
||||
@ -55,11 +57,11 @@ class Config(object):
|
||||
global _config
|
||||
_config = self
|
||||
|
||||
def load(self, path = DFT_CONFIG_PATH):
|
||||
def load(self, path=DFT_CONFIG_PATH):
|
||||
self._cfg.read(path)
|
||||
return self
|
||||
|
||||
def save(self, path = DFT_CONFIG_PATH):
|
||||
def save(self, path=DFT_CONFIG_PATH):
|
||||
with open(path, 'w') as f:
|
||||
self._cfg.write(f)
|
||||
|
||||
@ -77,7 +79,7 @@ class Config(object):
|
||||
value = str2bool(value)
|
||||
return value
|
||||
|
||||
def get(self, name, default = None):
|
||||
def get(self, name, default=None):
|
||||
try:
|
||||
return self.__getattr__(name)
|
||||
except (configparser.NoOptionError, configparser.NoSectionError):
|
||||
@ -89,5 +91,6 @@ class Config(object):
|
||||
value = str2bool(value)
|
||||
yield name, value
|
||||
|
||||
|
||||
def str2bool(s):
|
||||
return str(s).lower() in ('yes', 'true', 't', 'y', '1')
|
||||
|
Loading…
x
Reference in New Issue
Block a user