forked from ungleich-public/cdist
		
	DirectoryDictProperty: create directory if it doesnt exist
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
		
					parent
					
						
							
								e70e0569ec
							
						
					
				
			
			
				commit
				
					
						9c04da1d42
					
				
			
		
					 1 changed files with 6 additions and 2 deletions
				
			
		| 
						 | 
					@ -155,6 +155,9 @@ class DirectoryDict(collections.MutableMapping):
 | 
				
			||||||
        if not os.path.isabs(path):
 | 
					        if not os.path.isabs(path):
 | 
				
			||||||
            raise AbsolutePathRequiredError(path)
 | 
					            raise AbsolutePathRequiredError(path)
 | 
				
			||||||
        self.path = path
 | 
					        self.path = path
 | 
				
			||||||
 | 
					        # create directory if it doesn't exist
 | 
				
			||||||
 | 
					        if not os.path.isdir(self.path):
 | 
				
			||||||
 | 
					            os.mkdir(self.path)
 | 
				
			||||||
        if initial is not None:
 | 
					        if initial is not None:
 | 
				
			||||||
            self.update(initial)
 | 
					            self.update(initial)
 | 
				
			||||||
        if kwargs:
 | 
					        if kwargs:
 | 
				
			||||||
| 
						 | 
					@ -210,6 +213,9 @@ class DirectoryDictProperty(DirectoryDict):
 | 
				
			||||||
                path = path(*args, **kwargs)
 | 
					                path = path(*args, **kwargs)
 | 
				
			||||||
            if not os.path.isabs(path):
 | 
					            if not os.path.isabs(path):
 | 
				
			||||||
                raise AbsolutePathRequiredError(path)
 | 
					                raise AbsolutePathRequiredError(path)
 | 
				
			||||||
 | 
					            # create directory if it doesn't exist
 | 
				
			||||||
 | 
					            if not os.path.isdir(path):
 | 
				
			||||||
 | 
					                os.mkdir(path)
 | 
				
			||||||
            self.path = path
 | 
					            self.path = path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Descriptor Protocol
 | 
					    # Descriptor Protocol
 | 
				
			||||||
| 
						 | 
					@ -222,8 +228,6 @@ class DirectoryDictProperty(DirectoryDict):
 | 
				
			||||||
    def __set__(self, obj, value):
 | 
					    def __set__(self, obj, value):
 | 
				
			||||||
        self._set_path(obj)
 | 
					        self._set_path(obj)
 | 
				
			||||||
        if value is not None:
 | 
					        if value is not None:
 | 
				
			||||||
            # create directory if it doesn't exist
 | 
					 | 
				
			||||||
            os.makedirs(self.path, exist_ok=True)
 | 
					 | 
				
			||||||
            for name in self.keys():
 | 
					            for name in self.keys():
 | 
				
			||||||
                del self[name]
 | 
					                del self[name]
 | 
				
			||||||
            self.update(value)
 | 
					            self.update(value)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue