2015-12-14 22:51:47 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# node-config-python
  
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:15:22 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:19:09 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Read and write python config files non-destructively (preserves comments and line-order)
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:15:22 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Turns this kind of thing:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```python
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								foo = True
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bar = None
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								baz = whatever
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								qux = apples,bananas
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Into this kind of thing:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```javascript
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ foo: true
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								, bar: null
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								, baz: "whatever"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								, qux: ["apples", "bananas"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								(comments are stored in meta-data keys `__lines`  and `__keys` )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:18:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Install
  
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:15:22 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```bash
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								npm install --save pyconf
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:18:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Usage
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:15:22 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```javascript
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								var pyconf = require('pyconf');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:19:50 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// alias for fs.readFile() then pyconf.parse()
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:15:22 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								pyconf.readFile("/path/to/foo.conf", function (err, obj) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  console.log(obj);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								});
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:19:50 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// alias for pyconf.stringify() then safeReplace.writeFile()
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:15:22 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								pyconf.writeFile("/path/to/foo.conf", obj, function (err, obj) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  console.log("wrote file");
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								});
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Note: the `writeFile`  function uses `safe-replace`  so that it will work even in environments where race conditions are possible and will also create a backup file `whatever.conf.bak`  of the config being overwritten.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## API
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:16:23 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```javascript
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:15:56 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								pyconf
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:16:23 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  .parse(str, cb)                   // => err, object
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:15:56 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:16:23 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  .stringify(obj, cb)               // => err, text
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:15:56 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:16:23 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  .readFile(filename, cb)           // => err, object
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:15:56 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:16:23 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  .writeFile(filename, obj, cb)     // => err 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-19 10:15:22 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```