mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge
This commit is contained in:
commit
2f9d6fb882
3 changed files with 45 additions and 4 deletions
11
bin/yunohost
11
bin/yunohost
|
@ -13,6 +13,9 @@ USE_CACHE = True
|
||||||
# Either the output has to be encoded as a JSON encoded string or not
|
# Either the output has to be encoded as a JSON encoded string or not
|
||||||
PRINT_JSON = False
|
PRINT_JSON = False
|
||||||
|
|
||||||
|
# Either the output has to printed for scripting usage or not
|
||||||
|
PRINT_PLAIN = False
|
||||||
|
|
||||||
# Level for which loggers will log
|
# Level for which loggers will log
|
||||||
LOGGERS_LEVEL = 'INFO'
|
LOGGERS_LEVEL = 'INFO'
|
||||||
|
|
||||||
|
@ -62,6 +65,10 @@ def _parse_argv():
|
||||||
global PRINT_JSON
|
global PRINT_JSON
|
||||||
PRINT_JSON = True
|
PRINT_JSON = True
|
||||||
argv.remove('--json')
|
argv.remove('--json')
|
||||||
|
if '--plain' in argv:
|
||||||
|
global PRINT_PLAIN
|
||||||
|
PRINT_PLAIN = True
|
||||||
|
argv.remove('--plain')
|
||||||
if '--debug' in argv:
|
if '--debug' in argv:
|
||||||
global LOGGERS_LEVEL
|
global LOGGERS_LEVEL
|
||||||
LOGGERS_LEVEL = 'DEBUG'
|
LOGGERS_LEVEL = 'DEBUG'
|
||||||
|
@ -156,6 +163,6 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
# Execute the action
|
# Execute the action
|
||||||
from moulinette import cli
|
from moulinette import cli
|
||||||
ret = cli(_retrieve_namespaces(), args,
|
ret = cli(_retrieve_namespaces(), args, use_cache=USE_CACHE,
|
||||||
print_json=PRINT_JSON, use_cache=USE_CACHE)
|
print_json=PRINT_JSON, print_plain=PRINT_PLAIN)
|
||||||
sys.exit(ret)
|
sys.exit(ret)
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
|
|
||||||
# Check if a user exists
|
# Check if a user exists
|
||||||
|
#
|
||||||
|
# usage: ynh_user_exists username
|
||||||
|
# | ret: retcode - 0 if user exists, 1 otherwise
|
||||||
ynh_user_exists() {
|
ynh_user_exists() {
|
||||||
sudo yunohost user list --json | grep -q "\"username\": \"${1}\""
|
sudo yunohost user list --json | grep -q "\"username\": \"${1}\""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Retrieve a user information
|
||||||
|
#
|
||||||
|
# usage: ynh_user_info username key
|
||||||
|
# | ret: string - the key's value
|
||||||
|
ynh_user_get_info() {
|
||||||
|
sudo yunohost user info "${1}" --plain | ynh_get_plain_key "${2}"
|
||||||
|
}
|
||||||
|
|
24
data/apps/helpers.d/utils
Normal file
24
data/apps/helpers.d/utils
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# Extract a key from a plain command output
|
||||||
|
#
|
||||||
|
# usage: ynh_get_plain_key key [subkey [subsubkey ...]]
|
||||||
|
# | ret: string - the key's value
|
||||||
|
ynh_get_plain_key() {
|
||||||
|
prefix="#"
|
||||||
|
founded=0
|
||||||
|
key=$1
|
||||||
|
shift
|
||||||
|
while read line; do
|
||||||
|
if [[ "$founded" == "1" ]] ; then
|
||||||
|
[[ "$line" =~ ^${prefix}[^#] ]] && return
|
||||||
|
echo $line
|
||||||
|
elif [[ "$line" =~ ^${prefix}${key}$ ]]; then
|
||||||
|
if [[ -n "$1" ]]; then
|
||||||
|
prefix+="#"
|
||||||
|
key=$1
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
founded=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue