raise exception when given a relative path

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2011-10-10 09:57:56 +02:00
parent 96ca5b6988
commit 0ba6d55191

View file

@ -25,11 +25,21 @@ import collections
import cdist
class AbsolutePathRequiredError(cdist.Error):
def __init__(self, path):
self.path = path
def __str__(self):
return 'Absolute path required, got: %s' % self.path
class FileList(collections.MutableSequence):
"""A list that stores it's state in a file.
"""
def __init__(self, path, initial=None):
if not os.path.isabs(path):
raise AbsolutePathRequiredError(path)
self._path = path
if initial:
# delete existing file
@ -108,6 +118,8 @@ class DirectoryDict(collections.MutableMapping):
"""
def __init__(self, path, dict=None, **kwargs):
if not os.path.isabs(path):
raise AbsolutePathRequiredError(path)
self._path = path
if dict is not None:
self.update(dict)