Skip to content
Snippets Groups Projects
Commit 80ae30c4 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

New Settings.readAll method

parent 39eff181
No related branches found
No related tags found
No related merge requests found
...@@ -19,8 +19,10 @@ the following functions can be called at the module-level: ...@@ -19,8 +19,10 @@ the following functions can be called at the module-level:
Settings.readFile Settings.readFile
Settings.writeFile Settings.writeFile
Settings.deleteFile Settings.deleteFile
Settings.readAll
Settings.clear Settings.clear
These functions will have no effect before :func:`initialise` is called. These functions will have no effect before :func:`initialise` is called.
Two types of configuration data are available: Two types of configuration data are available:
...@@ -43,10 +45,12 @@ from __future__ import absolute_import ...@@ -43,10 +45,12 @@ from __future__ import absolute_import
import os import os
import os.path as op import os.path as op
import sys import sys
import copy
import atexit import atexit
import shutil import shutil
import pickle import pickle
import logging import logging
import fnmatch
import tempfile import tempfile
import platform import platform
...@@ -76,6 +80,7 @@ def initialise(*args, **kwargs): ...@@ -76,6 +80,7 @@ def initialise(*args, **kwargs):
mod.readFile = settings.readFile mod.readFile = settings.readFile
mod.writeFile = settings.writeFile mod.writeFile = settings.writeFile
mod.deleteFile = settings.deleteFile mod.deleteFile = settings.deleteFile
mod.readAll = settings.readAll
mod.clear = settings.clear mod.clear = settings.clear
...@@ -93,6 +98,8 @@ def writeFile(*args, **kwargs): ...@@ -93,6 +98,8 @@ def writeFile(*args, **kwargs):
pass pass
def deleteFile(*args, **kwargs): def deleteFile(*args, **kwargs):
pass pass
def readAll(*args, **kwarg):
return {}
def clear(*args, **kwarg): def clear(*args, **kwarg):
pass pass
...@@ -101,17 +108,6 @@ class Settings(object): ...@@ -101,17 +108,6 @@ class Settings(object):
"""The ``Settings`` class contains all of the logic provided by the """The ``Settings`` class contains all of the logic provided by the
``settings`` module. It is not meant to be instantiated directly ``settings`` module. It is not meant to be instantiated directly
(although you may do so if you wish). (although you may do so if you wish).
.. autosummary::
:nosignatures:
read
write
delete
readFile
writeFile
deleteFile
clear
""" """
...@@ -215,6 +211,19 @@ class Settings(object): ...@@ -215,6 +211,19 @@ class Settings(object):
os.remove(path) os.remove(path)
def readAll(self, pattern=None):
"""Returns all settings with names that match the given glob-style
pattern.
"""
if pattern is None:
return copy.deepcopy(self.__config)
keys = fnmatch.filter(self.__config.keys(), pattern)
vals = [copy.deepcopy(self.__config[k]) for k in keys]
return dict(zip(keys, vals))
def clear(self): def clear(self):
"""Delete all configuration settings and files. """ """Delete all configuration settings and files. """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment