2015-12-15 06:51:47 +00:00
# node-config-python
2015-12-19 18:15:22 +00:00
2015-12-19 18:19:09 +00:00
Read and write python config files non-destructively (preserves comments and line-order)
2015-12-19 18:15:22 +00: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 18:18:54 +00:00
## Install
2015-12-19 18:15:22 +00:00
```bash
npm install --save pyconf
```
2015-12-19 18:18:54 +00:00
## Usage
2015-12-19 18:15:22 +00:00
```javascript
var pyconf = require('pyconf');
# alias for fs.readFile() then pyconf.parse()
pyconf.readFile("/path/to/foo.conf", function (err, obj) {
console.log(obj);
});
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 18:16:23 +00:00
```javascript
2015-12-19 18:15:56 +00:00
pyconf
2015-12-19 18:16:23 +00:00
.parse(str, cb) // => err, object
2015-12-19 18:15:56 +00:00
2015-12-19 18:16:23 +00:00
.stringify(obj, cb) // => err, text
2015-12-19 18:15:56 +00:00
2015-12-19 18:16:23 +00:00
.readFile(filename, cb) // => err, object
2015-12-19 18:15:56 +00:00
2015-12-19 18:16:23 +00:00
.writeFile(filename, obj, cb) // => err
2015-12-19 18:15:22 +00:00
```