forked from ungleich-public/cdist
		
	Merge pull request #312 from asteven/issue/312
all files cdist creates should allways end with newline
This commit is contained in:
		
				commit
				
					
						1bb897f9a2
					
				
			
		
					 1 changed files with 7 additions and 1 deletions
				
			
		| 
						 | 
					@ -143,6 +143,9 @@ class DirectoryDict(collections.MutableMapping):
 | 
				
			||||||
                        fd.write(str(v) + '\n')
 | 
					                        fd.write(str(v) + '\n')
 | 
				
			||||||
                else:
 | 
					                else:
 | 
				
			||||||
                    fd.write(str(value))
 | 
					                    fd.write(str(value))
 | 
				
			||||||
 | 
					                    # ensure file ends with a single newline
 | 
				
			||||||
 | 
					                    if value and value[-1] != '\n':
 | 
				
			||||||
 | 
					                        fd.write('\n')
 | 
				
			||||||
        except EnvironmentError as e:
 | 
					        except EnvironmentError as e:
 | 
				
			||||||
            raise cdist.Error(str(e))
 | 
					            raise cdist.Error(str(e))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -281,7 +284,7 @@ class FileStringProperty(FileBasedProperty):
 | 
				
			||||||
        value = ""
 | 
					        value = ""
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            with open(path, "r") as fd:
 | 
					            with open(path, "r") as fd:
 | 
				
			||||||
                value = fd.read()
 | 
					                value = fd.read().rstrip('\n')
 | 
				
			||||||
        except EnvironmentError:
 | 
					        except EnvironmentError:
 | 
				
			||||||
            pass
 | 
					            pass
 | 
				
			||||||
        return value
 | 
					        return value
 | 
				
			||||||
| 
						 | 
					@ -292,6 +295,9 @@ class FileStringProperty(FileBasedProperty):
 | 
				
			||||||
            try:
 | 
					            try:
 | 
				
			||||||
                with open(path, "w") as fd:
 | 
					                with open(path, "w") as fd:
 | 
				
			||||||
                    fd.write(str(value))
 | 
					                    fd.write(str(value))
 | 
				
			||||||
 | 
					                    # ensure file ends with a single newline
 | 
				
			||||||
 | 
					                    if value[-1] != '\n':
 | 
				
			||||||
 | 
					                        fd.write('\n')
 | 
				
			||||||
            except EnvironmentError as e:
 | 
					            except EnvironmentError as e:
 | 
				
			||||||
                raise cdist.Error(str(e))
 | 
					                raise cdist.Error(str(e))
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue