Skip to content

Commit 90da0f8

Browse files
committed
removed limit&offset function + faster listings
1 parent 8a5d155 commit 90da0f8

35 files changed

+1365
-1517
lines changed

bin/v_list_db_base

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,81 @@
66
#----------------------------------------------------------#
77

88
# Argument defenition
9-
user="$1"
10-
database="$2"
11-
format="${3-shell}"
9+
user=$1
10+
database=$2
11+
format=${3-shell}
1212

1313
# Importing variables
1414
source $VESTA/conf/vars.conf
1515
source $V_FUNC/shared_func.sh
1616
source $V_FUNC/db_func.sh
1717

18+
# Json function
19+
json_list_db() {
20+
i=1
21+
22+
# Define words number
23+
last_word=$(echo "$fields" | wc -w)
24+
25+
# Reading file line by line
26+
line=$(grep "DB='$database'" $conf)
27+
28+
# Print top bracket
29+
echo '{'
30+
31+
# Parsing key=value
32+
for key in $line; do
33+
eval ${key%%=*}=${key#*=}
34+
done
35+
36+
# Starting output loop
37+
for field in $fields; do
38+
39+
# Parsing key=value
40+
eval value=$field
41+
42+
# Checking first field
43+
if [ "$i" -eq 1 ]; then
44+
echo -e "\t\"$value\": {"
45+
else
46+
if [ "$last_word" -eq "$i" ]; then
47+
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
48+
else
49+
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
50+
fi
51+
fi
52+
53+
# Updating iterator
54+
(( ++i))
55+
done
56+
57+
# If there was any output
58+
if [ -n "$value" ]; then
59+
echo -e "\t}"
60+
fi
61+
62+
# Printing bottom json bracket
63+
echo -e '}'
64+
}
65+
66+
# Shell list for single database
67+
shell_list_db() {
68+
69+
# Reading file line by line
70+
line=$(grep "DB='$database'" $conf)
71+
72+
# Parsing key=value
73+
for key in $line; do
74+
eval ${key%%=*}=${key#*=}
75+
done
76+
77+
# Print result line
78+
for field in $fields; do
79+
eval key="$field"
80+
echo "${field//$/}: $key "
81+
done
82+
}
83+
1884

1985
#----------------------------------------------------------#
2086
# Verifications #
@@ -38,16 +104,17 @@ is_db_valid
38104
#----------------------------------------------------------#
39105

40106
# Defining config
41-
conf="$V_USERS/$user/db.conf"
107+
conf=$V_USERS/$user/db.conf
42108

43109
# Defining fileds to select
44110
fields='$DB $USER $HOST $TYPE $U_DISK $SUSPEND $DATE'
45111

46112
# Listing database
47113
case $format in
48-
json) db_json_single_list ;;
49-
shell) db_shell_single_list | column -t ;;
50-
*) check_args '2' "0" 'user database [format]'
114+
json) json_list_db ;;
115+
plain) shell_list_db ;;
116+
shell) shell_list_db | column -t ;;
117+
*) check_args '2' '0' 'user database [format]'
51118
esac
52119

53120

@@ -58,4 +125,4 @@ esac
58125
# Logging
59126
log_event 'system' "$V_EVENT"
60127

61-
exit $OK
128+
exit

bin/v_list_db_bases

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
#----------------------------------------------------------#
77

88
# Argument defenition
9-
user="$1"
10-
format="${2-shell}"
11-
limit="${3-1000}"
12-
offset="${4-1}"
9+
user=$1
10+
format=${2-shell}
1311

1412
# Importing variables
1513
source $VESTA/conf/vars.conf
@@ -21,10 +19,10 @@ source $V_FUNC/shared_func.sh
2119
#----------------------------------------------------------#
2220

2321
# Checking args
24-
check_args '1' "$#" 'user [format] [limit] [offset]'
22+
check_args '1' "$#" 'user [format]'
2523

2624
# Checking argument format
27-
format_validation 'user' 'limit' 'offset'
25+
format_validation 'user'
2826

2927
# Checking user
3028
is_user_valid
@@ -35,16 +33,17 @@ is_user_valid
3533
#----------------------------------------------------------#
3634

3735
# Defining config
38-
conf="$V_USERS/$user/db.conf"
36+
conf=$V_USERS/$user/db.conf
3937

4038
# Defining fileds to select
4139
fields='$DB $USER $HOST $TYPE $U_DISK $SUSPEND $DATE'
4240

4341
# Listing databases
4442
case $format in
45-
json) v_json_list ;;
46-
shell) v_shell_list| column -t ;;
47-
*) check_args '1' "0" 'user [format] [limit] [offset]'
43+
json) json_list ;;
44+
plain) nohead=1; shell_list ;;
45+
shell) shell_list | column -t ;;
46+
*) check_args '1' '0' 'user [format]'
4847
esac
4948

5049

@@ -55,4 +54,4 @@ esac
5554
# Logging
5655
log_event 'system' "$V_EVENT"
5756

58-
exit $OK
57+
exit

bin/v_list_db_host

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,79 @@
66
#----------------------------------------------------------#
77

88
# Argument defenition
9-
type="$1"
10-
host="$2"
11-
format="${3-shell}"
9+
type=$1
10+
host=$2
11+
format=${3-shell}
1212

1313
# Importing variables
1414
source $VESTA/conf/vars.conf
1515
source $V_FUNC/shared_func.sh
1616
source $V_FUNC/db_func.sh
1717

18+
# Json function
19+
json_list_dbhost() {
20+
# Definigng variables
21+
i=1
22+
23+
# Define words number
24+
fields_count=$(echo "$fields" | wc -w)
25+
26+
# Reading file line by line
27+
line=$(grep "HOST='$host'" $conf)
28+
29+
# Print top bracket
30+
echo '{'
31+
32+
# Assign key=value
33+
for key in $line; do
34+
eval ${key%%=*}=${key#*=}
35+
done
36+
37+
# Starting output loop
38+
for field in $fields; do
39+
40+
# Parsing key=value
41+
eval value=$field
42+
43+
# Checking first field
44+
if [ "$i" -eq 1 ]; then
45+
echo -e "\t\"$value\": {"
46+
else
47+
if [ "$fields_count" -eq "$i" ]; then
48+
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
49+
else
50+
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
51+
fi
52+
fi
53+
(( ++i))
54+
done
55+
# If there was any output
56+
if [ -n "$value" ]; then
57+
echo -e "\t}"
58+
fi
59+
60+
# Printing bottom json bracket
61+
echo -e "}"
62+
}
63+
64+
# Shell function
65+
shell_list_dbhost() {
66+
67+
# Reading file line by line
68+
line=$(grep "HOST='$host'" $conf)
69+
70+
# Parsing key=value
71+
for key in $line; do
72+
eval ${key%%=*}=${key#*=}
73+
done
74+
75+
# Print result line
76+
for field in $fields; do
77+
eval key="$field"
78+
echo "${field//$/}: $key"
79+
done
80+
}
81+
1882

1983
#----------------------------------------------------------#
2084
# Verifications #
@@ -38,16 +102,17 @@ is_db_host_valid
38102
#----------------------------------------------------------#
39103

40104
# Defining config type
41-
conf="$V_DB/$type.conf"
105+
conf=$V_DB/$type.conf
42106

43107
# Defining fileds to select
44108
fields='$HOST $PORT $MAX_USERS $MAX_DB $U_SYS_USERS $U_DB_BASES $ACTIVE $DATE'
45109

46110
# Listing database
47111
case $format in
48-
json) dbhost_json_single_list ;;
49-
shell) dbhost_shell_single_list | column -t;;
50-
*) check_args '2' "0" 'type host [format]'
112+
json) json_list_dbhost ;;
113+
plain) nohead=1; shell_list_dbhost ;;
114+
shell) shell_list_dbhost | column -t;;
115+
*) check_args '2' '0' 'type host [format]'
51116
esac
52117

53118

@@ -58,4 +123,4 @@ esac
58123
# Logging
59124
log_event 'system' "$V_EVENT"
60125

61-
exit $OK
126+
exit

bin/v_list_db_hosts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
#----------------------------------------------------------#
77

88
# Argument defenition
9-
type="$1"
10-
format="${2-shell}"
11-
limit="${3-1000}"
12-
offset="${4-1}"
9+
type=$1
10+
format=${2-shell}
1311

1412

1513
# Importing variables
@@ -36,17 +34,18 @@ is_type_valid 'db' "$type"
3634
#----------------------------------------------------------#
3735

3836
# Defining config type
39-
conf="$V_DB/$type.conf"
37+
conf=$V_DB/$type.conf
4038

4139
# Defining fileds to select
4240
fields='$HOST $PORT $MAX_USERS $MAX_DB $U_SYS_USERS $U_DB_BASES $ACTIVE $DATE'
4341

4442
# Listing database
4543
case $format in
46-
json) v_json_list ;;
47-
shell) fields='$HOST $PORT $MAX_USERS $MAX_DB $U_DB_BASES $ACTIVE $DATE';
48-
v_shell_list | column -t ;;
49-
*) check_args '2' "0" 'type [format] [limit] [offset]'
44+
json) json_list ;;
45+
plain) nohead=1; shell_list;;
46+
shell) fields='$HOST $PORT $MAX_USERS $MAX_DB $U_DB_BASES $ACTIVE $DATE';
47+
shell_list | column -t ;;
48+
*) check_args '2' '0' 'type [format]'
5049
esac
5150

5251

@@ -57,4 +56,4 @@ esac
5756
# Logging
5857
log_event 'system' "$V_EVENT"
5958

60-
exit $OK
59+
exit

0 commit comments

Comments
 (0)