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
 | 
					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):
 | 
					class FileList(collections.MutableSequence):
 | 
				
			||||||
    """A list that stores it's state in a file.
 | 
					    """A list that stores it's state in a file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    def __init__(self, path, initial=None):
 | 
					    def __init__(self, path, initial=None):
 | 
				
			||||||
 | 
					        if not os.path.isabs(path):
 | 
				
			||||||
 | 
					            raise AbsolutePathRequiredError(path)
 | 
				
			||||||
        self._path = path
 | 
					        self._path = path
 | 
				
			||||||
        if initial:
 | 
					        if initial:
 | 
				
			||||||
            # delete existing file
 | 
					            # delete existing file
 | 
				
			||||||
| 
						 | 
					@ -108,6 +118,8 @@ class DirectoryDict(collections.MutableMapping):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    def __init__(self, path, dict=None, **kwargs):
 | 
					    def __init__(self, path, dict=None, **kwargs):
 | 
				
			||||||
 | 
					        if not os.path.isabs(path):
 | 
				
			||||||
 | 
					            raise AbsolutePathRequiredError(path)
 | 
				
			||||||
        self._path = path
 | 
					        self._path = path
 | 
				
			||||||
        if dict is not None:
 | 
					        if dict is not None:
 | 
				
			||||||
            self.update(dict)
 | 
					            self.update(dict)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue