forked from saschpe/libvirt-hook-qemu
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhookjsonconf.py
More file actions
48 lines (37 loc) · 1023 Bytes
/
hookjsonconf.py
File metadata and controls
48 lines (37 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python3
"""Libvirt port-forwarding hook config file parser library.
0.0.1:
======
* Initial version to decode/encode a JSON configuration
"""
__author__ = "Martin Bo Kristensen Groenholdt <martin.groenholdt@gmail.com>"
__version__ = "0.0.1"
import json
class HookConfig:
"""
Class for keeping configuration data in JSON strings.
"""
def __init__(self, config=None):
"""
Constructor
"""
if config is not None:
self.parse(config)
else:
self.config = None
def parse(self, config):
"""
Parse a JSON string as configuration data
"""
self.config = json.loads(config)
return self.config
def build(self, config, pretty=False):
"""
Encode configuration data as a JSON string
"""
jconf = ''
if pretty:
jconf = json.dumps(config, indent=4, sort_keys=True)
else:
jconf = json.dumps(config)
return(jconf)