from teleforma.models import Conference
-from deefuzzer.tools.utils import get_conf_dict, write_conf
+from tools.tools import write_conf, get_conf_dict
from tools import *
pass
+def get_conf_dict(file):
+ mime_type = mimetypes.guess_type(file)[0]
+
+ # Do the type check first, so we don't load huge files that won't be used
+ if 'xml' in mime_type:
+ confile = open(file, 'r')
+ data = confile.read()
+ confile.close()
+ return xmltodict(data, 'utf-8')
+ elif 'yaml' in mime_type:
+ import yaml
+
+ def custom_str_constructor(loader, node):
+ return loader.construct_scalar(node).encode('utf-8')
+
+ yaml.add_constructor(u'tag:yaml.org,2002:str', custom_str_constructor)
+ confile = open(file, 'r')
+ data = confile.read()
+ confile.close()
+ return yaml.load(data)
+ elif 'json' in mime_type:
+ import json
+
+ confile = open(file, 'r')
+ data = confile.read()
+ confile.close()
+ return json.loads(data)
+
+ return False
+
+
+def write_conf(conf_dict, path):
+ filename, ext = os.path.splitext(path)
+ f = open(path, 'w')
+
+ if 'xml' in ext:
+ xml_data = dicttoxml(conf_dict)
+ f.write(xml_data)
+
+ elif 'yaml' in ext or 'yml' in ext:
+ import yaml
+ yaml.dump(conf_dict, f)
+
+ elif 'json' in ext:
+ import json
+ json.dump(conf_dict, f)
+
+ f.close()