feat(package): hemar: conected to nix config
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,5 @@
|
|||||||
.env
|
.env
|
||||||
result
|
result
|
||||||
result-man
|
result-*
|
||||||
rust-toolchain.toml
|
rust-toolchain.toml
|
||||||
target/
|
target/
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ log_allowed() {
|
|||||||
# log(level, text...)
|
# log(level, text...)
|
||||||
log() {
|
log() {
|
||||||
delimetr=${DELIMETR:-' '};
|
delimetr=${DELIMETR:-' '};
|
||||||
level="${1:?}"; shift
|
level="${1:?}"
|
||||||
log_allowed "$level" || return 0
|
log_allowed "$level" || return 0
|
||||||
|
|
||||||
case "$level" in
|
case "$level" in
|
||||||
@@ -125,9 +125,14 @@ log() {
|
|||||||
notice) color="$CYAN" ;;
|
notice) color="$CYAN" ;;
|
||||||
warn) color="$YELLOW" ;;
|
warn) color="$YELLOW" ;;
|
||||||
error) color="$RED" ;;
|
error) color="$RED" ;;
|
||||||
*) color="$WHITE" ;;
|
*)
|
||||||
|
color="$WHITE"
|
||||||
|
NO_SHIFT=1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
[ ${NO_SHIFT+x} ] || shift
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# shellcheck disable=SC1003
|
# shellcheck disable=SC1003
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ in {
|
|||||||
onlinepubs2man = pkgs.callPackage ./onlinepubs2man {};
|
onlinepubs2man = pkgs.callPackage ./onlinepubs2man {};
|
||||||
migrator = pkgs.callPackage ./migrator {};
|
migrator = pkgs.callPackage ./migrator {};
|
||||||
nbt2json = pkgs.callPackage ./nbt2json {};
|
nbt2json = pkgs.callPackage ./nbt2json {};
|
||||||
|
hemar = pkgs.callPackage ./hemar {};
|
||||||
pg-17-ext-http = buildHttpExt pkgs "17";
|
pg-17-ext-http = buildHttpExt pkgs "17";
|
||||||
pg-17-ext-smtp-client = buildSmtpExt pkgs "17";
|
pg-17-ext-smtp-client = buildSmtpExt pkgs "17";
|
||||||
pg-17-ext-plhaskell = buildPlHaskellExt pkgs "17";
|
pg-17-ext-plhaskell = buildPlHaskellExt pkgs "17";
|
||||||
|
|||||||
36
package/hemar/default.nix
Normal file
36
package/hemar/default.nix
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
{ dash, hectic, symlinkJoin }:
|
||||||
|
let
|
||||||
|
shell = "${dash}/bin/dash";
|
||||||
|
bashOptions = [
|
||||||
|
"errexit"
|
||||||
|
"nounset"
|
||||||
|
];
|
||||||
|
|
||||||
|
test = hectic.writeShellApplication {
|
||||||
|
inherit shell bashOptions;
|
||||||
|
name = "hemar-test";
|
||||||
|
runtimeInputs = [ ];
|
||||||
|
|
||||||
|
text = ''
|
||||||
|
WORKSPACE=${./.}
|
||||||
|
${builtins.readFile hectic.helpers.posix-shell.log}
|
||||||
|
${builtins.readFile ./test.sh}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
hemar = hectic.writeShellApplication {
|
||||||
|
inherit shell bashOptions;
|
||||||
|
name = "hemar";
|
||||||
|
runtimeInputs = [ ];
|
||||||
|
|
||||||
|
text = ''
|
||||||
|
WORKSPACE=${./.}
|
||||||
|
${builtins.readFile hectic.helpers.posix-shell.log}
|
||||||
|
${builtins.readFile ./hemar.sh}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
in
|
||||||
|
symlinkJoin {
|
||||||
|
name = "hemar";
|
||||||
|
paths = [ hemar test ];
|
||||||
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
#!/bin/dash
|
#!/bin/dash
|
||||||
|
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
. "${WORKSPACE:?}/src/plex/plex.sh"
|
||||||
|
init_plex jq
|
||||||
|
|
||||||
# Syntax scheme:
|
# Syntax scheme:
|
||||||
#
|
#
|
||||||
# hemar
|
# hemar
|
||||||
@@ -163,7 +167,7 @@
|
|||||||
# AbstarctSyntaxTree (ATS) = {
|
# AbstarctSyntaxTree (ATS) = {
|
||||||
# e = [Element] # elements array
|
# e = [Element] # elements array
|
||||||
# }
|
# }
|
||||||
AST=''
|
#AST=''
|
||||||
|
|
||||||
# 0 - text
|
# 0 - text
|
||||||
# 1 - deside tag type
|
# 1 - deside tag type
|
||||||
@@ -218,6 +222,8 @@ find_open_pattern() {
|
|||||||
parse() {
|
parse() {
|
||||||
char="$1"
|
char="$1"
|
||||||
|
|
||||||
|
data_pointer=
|
||||||
|
|
||||||
case "$STAGE" in
|
case "$STAGE" in
|
||||||
0)
|
0)
|
||||||
if find_open_pattern "$char"; then
|
if find_open_pattern "$char"; then
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
#!/bin/dash
|
|
||||||
|
|
||||||
init_plex() {
|
|
||||||
local backend
|
|
||||||
backend=${1:?}
|
|
||||||
|
|
||||||
case "$backend" in
|
|
||||||
env)
|
|
||||||
. ${WORKSPACE}/plex/backend/env_var.sh
|
|
||||||
;;
|
|
||||||
file)
|
|
||||||
. ${WORKSPACE}/plex/backend/file.sh
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
@@ -2,29 +2,12 @@
|
|||||||
|
|
||||||
PLEX_TEMP="$(mktemp -d)"
|
PLEX_TEMP="$(mktemp -d)"
|
||||||
|
|
||||||
|
#plex_set(name, key, value)
|
||||||
plex_set() {
|
plex_set() {
|
||||||
local plexfile key val regex base esc_key esc
|
local plexfile key val regex base esc_key esc
|
||||||
plexfile="${PLEX_TEMP:?}${1:?}" key="${2:?}" val="${3:?}"
|
plexfile="${PLEX_TEMP:?}${1:?}" key="${2:?}" val="${3:?}"
|
||||||
|
|
||||||
# construct regex for ancestors
|
find PLEX_
|
||||||
regex="^$key="
|
|
||||||
|
|
||||||
base=$key
|
|
||||||
while expr "$base" : '.*\.' >/dev/null; do
|
|
||||||
base=$(printf '%s\n' "$base" | sed 's/\.[^.]*$//')
|
|
||||||
esc=$(printf '%s\n' "$base" | sed 's/\./\\./g')
|
|
||||||
regex="$regex|^$esc="
|
|
||||||
done
|
|
||||||
|
|
||||||
# add descendants
|
|
||||||
esc_key="$(printf '%s\n' "$key" | sed 's/\./\\./g')"
|
|
||||||
regex="$regex|^${esc_key}\."
|
|
||||||
|
|
||||||
# remove old
|
|
||||||
grep -v -E "$regex" "$plexfile" > "$plexfile.tmp" && mv "$plexfile.tmp" "$plexfile"
|
|
||||||
|
|
||||||
# add new
|
|
||||||
printf '%s=%s\n' "$key" "$val" >> "$plexfile"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
plex_child() {
|
plex_child() {
|
||||||
40
package/hemar/src/plex/backend/yq-go.sh
Normal file
40
package/hemar/src/plex/backend/yq-go.sh
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#!/bin/dash
|
||||||
|
|
||||||
|
PLEX_TEMP="$(mktemp -d)"
|
||||||
|
trap 'rm -rf $PLEX_TEMP' EXIT
|
||||||
|
|
||||||
|
#plex_set(name, key, value)
|
||||||
|
plex_set() {
|
||||||
|
local plexfile key val
|
||||||
|
plexfile="${PLEX_TEMP:?}/${1:?}" key="${2:?}" val="${3:?}"
|
||||||
|
|
||||||
|
touch "$plexfile"
|
||||||
|
|
||||||
|
yq -i ".$key += \"$val\"" "$plexfile"
|
||||||
|
}
|
||||||
|
|
||||||
|
#plex_child(plexfile, key)
|
||||||
|
plex_child() {
|
||||||
|
plex_fetch "${1:?}" "${2:?}"
|
||||||
|
}
|
||||||
|
|
||||||
|
#plex_val(plexfile, key)
|
||||||
|
plex_val() {
|
||||||
|
plex_fetch "${1:?}" "${2:?}"
|
||||||
|
}
|
||||||
|
|
||||||
|
#plex_val(plexfile, key)
|
||||||
|
plex_fetch() {
|
||||||
|
local plexfile key
|
||||||
|
plexfile="${PLEX_TEMP:?}/${1:?}" key="${2:?}"
|
||||||
|
|
||||||
|
yq -i ".$key" "$plexfile"
|
||||||
|
}
|
||||||
|
|
||||||
|
#plex_push(name, prefix, val)
|
||||||
|
plex_push() {
|
||||||
|
local plexfile prefix val
|
||||||
|
plexfile="${PLEX_TEMP:?}/${1:?}" prefix="${2:?}" val="${3:?}"
|
||||||
|
|
||||||
|
yq -i ".$prefix += [\"$val\"]" "$plexfile"
|
||||||
|
}
|
||||||
21
package/hemar/src/plex/plex.sh
Normal file
21
package/hemar/src/plex/plex.sh
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/dash
|
||||||
|
|
||||||
|
init_plex() {
|
||||||
|
local backend
|
||||||
|
backend=${1:?}
|
||||||
|
|
||||||
|
case "$backend" in
|
||||||
|
env)
|
||||||
|
. ${WORKSPACE}/src/plex/backend/env_var.sh
|
||||||
|
;;
|
||||||
|
file)
|
||||||
|
. ${WORKSPACE}/src/plex/backend/file.sh
|
||||||
|
;;
|
||||||
|
yq-go)
|
||||||
|
. ${WORKSPACE}/src/plex/backend/yq-go.sh
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/dash
|
#!/bin/dash
|
||||||
|
|
||||||
WORKSPACE="$(cd "$(dirname "$0")" && pwd)"
|
# shellcheck disable=SC1091
|
||||||
|
#. "${WORKSPACE:?}/test/plex/jq_backend_time.sh"
|
||||||
#. "${WORKSPACE:?}/test/plex.sh"
|
#. "${WORKSPACE:?}/test/plex/env_backend_time.sh"
|
||||||
. "${WORKSPACE:?}/test/plex/time.sh"
|
. "${WORKSPACE:?}/test/plex/jq_backend.sh"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#!/bin/dash
|
#!/bin/dash
|
||||||
|
|
||||||
. "${WORKSPACE:?}/plex.sh"
|
. "${WORKSPACE:?}/src/plex/plex.sh"
|
||||||
|
init_plex env
|
||||||
|
|
||||||
MY_STRUCT=''
|
MY_STRUCT=''
|
||||||
|
|
||||||
7
package/hemar/test/plex/jq_backend.sh
Normal file
7
package/hemar/test/plex/jq_backend.sh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
. "${WORKSPACE:?}/src/plex/plex.sh"
|
||||||
|
init_plex yq-go
|
||||||
|
|
||||||
|
plex_set ZALUPA zalupa apulaz
|
||||||
|
log error "struct: $WHITE$(yq . "$PLEX_TEMP/ZALUPA")$NC"
|
||||||
|
|
||||||
|
plex_set ZALUPA zalupa.zalupa apulaz
|
||||||
129
package/hemar/test/plex/jq_backend_time.sh
Normal file
129
package/hemar/test/plex/jq_backend_time.sh
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
#!/bin/dash
|
||||||
|
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
. "${WORKSPACE:?}/src/plex/plex.sh"
|
||||||
|
init_plex yq-go
|
||||||
|
|
||||||
|
math() {
|
||||||
|
awk "BEGIN {print $1}"
|
||||||
|
}
|
||||||
|
|
||||||
|
elapsed() {
|
||||||
|
local task time count decrease avg
|
||||||
|
task=$1
|
||||||
|
time=$2
|
||||||
|
count=$3
|
||||||
|
decrease=${4:-0}
|
||||||
|
avg=$(math "$time/$count-$decrease")
|
||||||
|
|
||||||
|
if [ "$time" -eq 0 ]; then
|
||||||
|
log info "\n[$WHITE${task}$NC]\ninstant\n"
|
||||||
|
else
|
||||||
|
log info "\n[$WHITE${task}$NC]\nelapsed $WHITE${avg}$NC seconds\n$WHITE$(math "1/$avg")$NC per second\n"
|
||||||
|
fi
|
||||||
|
printf '%s' "$avg"
|
||||||
|
}
|
||||||
|
|
||||||
|
set_word_length() {
|
||||||
|
local length
|
||||||
|
length=${1:?}
|
||||||
|
|
||||||
|
# shellcheck disable=SC2183
|
||||||
|
__WORD_OFFSET_PATERN="$(printf '%*s' "$length" | tr ' ' '?')"
|
||||||
|
}
|
||||||
|
|
||||||
|
UNIQ_8_WORDS_COUNT=1000
|
||||||
|
DEFAULT_WORD_LENGTH=8
|
||||||
|
set_word_length "$DEFAULT_WORD_LENGTH"
|
||||||
|
|
||||||
|
randomword() {
|
||||||
|
local length
|
||||||
|
length=${1:-$DEFAULT_WORD_LENGTH}
|
||||||
|
LC_ALL=C tr -dc 'A-Za-z0-9' </dev/urandom | head -c "$length"
|
||||||
|
}
|
||||||
|
|
||||||
|
WORDS=$(randomword $((8 * UNIQ_8_WORDS_COUNT)))
|
||||||
|
WORDS=0123456789abcdefg
|
||||||
|
|
||||||
|
new_word() {
|
||||||
|
local prefix
|
||||||
|
# shellcheck disable=SC2295
|
||||||
|
prefix=${WORDS%"${WORDS#${__WORD_OFFSET_PATERN:?}}"}
|
||||||
|
# shellcheck disable=SC2295
|
||||||
|
WORDS=${WORDS#${__WORD_OFFSET_PATERN:?}}$prefix
|
||||||
|
printf '%s' "$prefix"
|
||||||
|
}
|
||||||
|
|
||||||
|
bench_set() {
|
||||||
|
local task depth count wordtime i start key d end
|
||||||
|
task=$1
|
||||||
|
depth=$2
|
||||||
|
count=$3
|
||||||
|
wordtime=$4
|
||||||
|
i=0
|
||||||
|
start=$(date +%s)
|
||||||
|
while [ "$i" -lt "$count" ]; do
|
||||||
|
key=$(new_word)
|
||||||
|
if [ "$depth" -gt 1 ]; then
|
||||||
|
d=1
|
||||||
|
while [ "$d" -lt "$depth" ]; do
|
||||||
|
key="$key.$(new_word)"
|
||||||
|
d=$((d + 1))
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
set +e
|
||||||
|
plex_set 'MY_STRUCT' "$key" "$i"
|
||||||
|
error_code=$?
|
||||||
|
log warning "error_code: $error_code"
|
||||||
|
set -e
|
||||||
|
if [ $error_code != 0 ]; then
|
||||||
|
log error "key: $WHITE$key$NC, i: $WHITE$i$NC, struct: $WHITE$(jq . "$PLEX_TEMP/MY_STRUCT")$NC"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
i=$((i + 1))
|
||||||
|
done
|
||||||
|
end=$(date +%s)
|
||||||
|
elapsed "$task" "$((end - start))" "$count" "$(math "$wordtime*$depth")" >/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFAULT_TRIES=1000
|
||||||
|
ACCURATE_TRIES=10000
|
||||||
|
SUPPER_ACCURATE_TRIES=100000
|
||||||
|
|
||||||
|
WORD_CREATE_ACCURACY="$SUPPER_ACCURATE_TRIES"
|
||||||
|
BENCH_ACCURACY="$DEFAULT_TRIES"
|
||||||
|
|
||||||
|
count="$WORD_CREATE_ACCURACY"
|
||||||
|
set_word_length 8
|
||||||
|
i=0
|
||||||
|
start=$(date +%s)
|
||||||
|
while [ "$i" -lt "${count:?}" ]; do
|
||||||
|
new_word >/dev/null
|
||||||
|
i=$((i + 1))
|
||||||
|
done
|
||||||
|
end=$(date +%s)
|
||||||
|
time=$((end - start))
|
||||||
|
log debug "word creation time: $time"
|
||||||
|
wordtime=$(elapsed 'Word creation' "$time" "$count")
|
||||||
|
|
||||||
|
bench_set 'Set element with depth 1 length 8' 1 "$BENCH_ACCURACY" "$wordtime"
|
||||||
|
bench_set 'Set element with depth 2 length 8' 2 "$BENCH_ACCURACY" "$wordtime"
|
||||||
|
bench_set 'Set element with depth 3 length 8' 3 "$BENCH_ACCURACY" "$wordtime"
|
||||||
|
|
||||||
|
log notice -
|
||||||
|
|
||||||
|
count="$WORD_CREATE_ACCURACY"
|
||||||
|
set_word_length 2
|
||||||
|
i=0
|
||||||
|
start=$(date +%s)
|
||||||
|
while [ "$i" -lt "${count:?}" ]; do
|
||||||
|
new_word >/dev/null
|
||||||
|
i=$((i + 1))
|
||||||
|
done
|
||||||
|
end=$(date +%s)
|
||||||
|
wordtime=$(elapsed 'Word creation' "$((end - start))" "$count")
|
||||||
|
|
||||||
|
bench_set 'Set element with depth 1 length 2' 1 "$BENCH_ACCURACY" "$wordtime"
|
||||||
|
bench_set 'Set element with depth 2 length 2' 2 "$BENCH_ACCURACY" "$wordtime"
|
||||||
|
bench_set 'Set element with depth 3 length 2' 3 "$BENCH_ACCURACY" "$wordtime"
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
#!/bin/dash
|
##!/bin/dash
|
||||||
|
#
|
||||||
HECTIC_NAMESPACE=test-migration-list
|
#HECTIC_NAMESPACE=test-migration-list
|
||||||
|
#
|
||||||
psql "$DATABASE_URL" 'CREATE TABLE profile (
|
#psql "$DATABASE_URL" 'CREATE TABLE profile (
|
||||||
id INTEGER,
|
# id INTEGER,
|
||||||
username TEXT
|
# username TEXT
|
||||||
)'
|
#)'
|
||||||
|
#
|
||||||
migrator --db-url "$DATABASE_URL" migrate to 20251104192425-add-info-to-profile
|
#migrator --db-url "$DATABASE_URL" migrate to 20251104192425-add-info-to-profile
|
||||||
|
#
|
||||||
exit 1
|
#exit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user