Files
mayan-edms/mayan/settings/utils.py
Roberto Rosario 1919e78041 Fix variable name in settings.utils
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
2018-09-05 00:40:56 -04:00

41 lines
1.0 KiB
Python

from __future__ import unicode_literals
import errno
import os
import sys
import yaml
def read_configuration_file(path):
try:
with open(path) as file_object:
file_object.seek(0, os.SEEK_END)
if file_object.tell():
file_object.seek(0)
try:
return yaml.safe_load(file_object)
except yaml.YAMLError as exception:
exit(
'Error loading configuration file: {}; {}'.format(
path, exception
)
)
except IOError as exception:
if exception.errno == errno.ENOENT:
pass
else:
raise
def yaml_loads(data, error_message=None):
if not error_message:
error_message = 'Error loading: {}; {}'
try:
return yaml.safe_load(data)
except yaml.YAMLError as exception:
exit(
error_message.format(error_message, exception)
)