mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Merge pull request #204 from YunoHost/toml-utils
add utils.filesystem.read_toml and depends on toml in moulinette
This commit is contained in:
commit
3c9230ee9f
4 changed files with 28 additions and 0 deletions
1
debian/control
vendored
1
debian/control
vendored
|
@ -16,6 +16,7 @@ Depends: ${misc:Depends}, ${python:Depends},
|
|||
python-gnupg,
|
||||
python-gevent-websocket,
|
||||
python-argcomplete,
|
||||
python-toml,
|
||||
python-psutil,
|
||||
python-tz
|
||||
Replaces: yunohost-cli
|
||||
|
|
|
@ -4,6 +4,7 @@ File system operation utils
|
|||
.. autofunction:: moulinette.utils.filesystem.read_file
|
||||
.. autofunction:: moulinette.utils.filesystem.read_json
|
||||
.. autofunction:: moulinette.utils.filesystem.read_yaml
|
||||
.. autofunction:: moulinette.utils.filesystem.read_toml
|
||||
.. autofunction:: moulinette.utils.filesystem.write_to_file
|
||||
.. autofunction:: moulinette.utils.filesystem.append_to_file
|
||||
.. autofunction:: moulinette.utils.filesystem.write_to_json
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
"unknown_error_reading_file": "Unknown error while trying to read file {file:s} (reason: {error:s})",
|
||||
"corrupted_json": "Corrupted json read from {ressource:s} (reason: {error:s})",
|
||||
"corrupted_yaml": "Corrupted yaml read from {ressource:s} (reason: {error:s})",
|
||||
"corrupted_toml": "Corrupted toml read from {ressource:s} (reason: {error:s})",
|
||||
"error_writing_file": "Error when writing file {file:s}: {error:s}",
|
||||
"error_removing": "Error when removing {path:s}: {error:s}",
|
||||
"error_changing_file_permissions": "Error when changing permissions for {path:s}: {error:s}",
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import os
|
||||
import yaml
|
||||
import toml
|
||||
import errno
|
||||
import shutil
|
||||
import json
|
||||
import grp
|
||||
|
||||
from pwd import getpwnam
|
||||
from collections import OrderedDict
|
||||
|
||||
from moulinette import m18n
|
||||
from moulinette.core import MoulinetteError
|
||||
|
@ -78,6 +81,28 @@ def read_yaml(file_path):
|
|||
return loaded_yaml
|
||||
|
||||
|
||||
def read_toml(file_path):
|
||||
"""
|
||||
Safely read a toml file
|
||||
|
||||
Keyword argument:
|
||||
file_path -- Path to the toml file
|
||||
"""
|
||||
|
||||
# Read file
|
||||
file_content = read_file(file_path)
|
||||
|
||||
# Try to load toml to check if it's syntactically correct
|
||||
try:
|
||||
loaded_toml = toml.loads(file_content, _dict=OrderedDict)
|
||||
except Exception as e:
|
||||
raise MoulinetteError(errno.EINVAL,
|
||||
m18n.g('corrupted_toml',
|
||||
ressource=file_path, error=str(e)))
|
||||
|
||||
return loaded_toml
|
||||
|
||||
|
||||
def read_ldif(file_path, filtred_entries=[]):
|
||||
"""
|
||||
Safely read a LDIF file and create struct in the same style than
|
||||
|
|
Loading…
Add table
Reference in a new issue