raise exception when given a relative path
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
parent
96ca5b6988
commit
0ba6d55191
1 changed files with 12 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue