Switch tp from using jq to json; format td

This commit is contained in:
Jordan Bancino 2023-03-08 22:47:40 +00:00
parent 76413f834e
commit 20ebeb9c32
3 changed files with 132 additions and 110 deletions

View file

@ -49,10 +49,10 @@ fi
mod_time() { mod_time() {
if [ -n "$1" ] && [ -f "$1" ]; then if [ -n "$1" ] && [ -f "$1" ]; then
case "$(uname)" in case "$(uname)" in
Linux|CYGWIN_NT*|Haiku) Linux | CYGWIN_NT* | Haiku)
stat -c %Y "$1" stat -c %Y "$1"
;; ;;
*BSD|DragonFly|Minix) *BSD | DragonFly | Minix)
stat -f %m "$1" stat -f %m "$1"
;; ;;
*) *)
@ -79,7 +79,7 @@ setsubst() {
echo "s|\\\${[a-zA-Z_]*}||g" echo "s|\\\${[a-zA-Z_]*}||g"
echo "s|'''|'|g" echo "s|'''|'|g"
) > "$SED" ) >"$SED"
sed -f "$SED" $@ sed -f "$SED" $@
rm "$SED" rm "$SED"
@ -195,9 +195,9 @@ recipe_site() {
echo "$dest" echo "$dest"
mkdir -p "$dir" mkdir -p "$dir"
setsubst "$file" > "$dest" setsubst "$file" >"$dest"
done done
cd - > /dev/null cd - >/dev/null
find man/ -name '*.[1-9]' | while IFS= read -r man; do find man/ -name '*.[1-9]' | while IFS= read -r man; do
dir=$(dirname "$man") dir=$(dirname "$man")
@ -206,7 +206,7 @@ recipe_site() {
mkdir -p "$TELODENDRIA_PUB/$dir/" mkdir -p "$TELODENDRIA_PUB/$dir/"
mandoc -Thtml \ mandoc -Thtml \
-O style=/style.css,man=/man/man%S/%N.%S.html "$man" \ -O style=/style.css,man=/man/man%S/%N.%S.html "$man" \
> "$TELODENDRIA_PUB/$dir/$html.html" >"$TELODENDRIA_PUB/$dir/$html.html"
echo "$TELODENDRIA_PUB/$dir/$html.html" echo "$TELODENDRIA_PUB/$dir/$html.html"
done done
} }
@ -235,7 +235,7 @@ recipe_release() {
# Checksum the release tarball. # Checksum the release tarball.
sha256 "Telodendria-v$TELODENDRIA_VERSION.tar.gz" \ sha256 "Telodendria-v$TELODENDRIA_VERSION.tar.gz" \
> "Telodendria-v$TELODENDRIA_VERSION.tar.gz.sha256" >"Telodendria-v$TELODENDRIA_VERSION.tar.gz.sha256"
# Sign the release tarball. # Sign the release tarball.
if [ ! -z "$TELODENDRIA_SIGNIFY_SECRET" ]; then if [ ! -z "$TELODENDRIA_SIGNIFY_SECRET" ]; then
@ -280,7 +280,7 @@ recipe_patch() {
echo " this patch under the conditions specified in it." echo " this patch under the conditions specified in it."
echo echo
cvs -q diff -uNp $PATCHSET | grep -v '^\? ' cvs -q diff -uNp $PATCHSET | grep -v '^\? '
) > "$PATCH_FILE" ) >"$PATCH_FILE"
"$EDITOR" "$PATCH_FILE" "$EDITOR" "$PATCH_FILE"
echo "$PATCH_FILE" echo "$PATCH_FILE"
@ -288,7 +288,7 @@ recipe_patch() {
recipe_diff() { recipe_diff() {
tmp_patch="/tmp/telodendria-$(date +%s).patch" tmp_patch="/tmp/telodendria-$(date +%s).patch"
cvs -q diff -uNp $PATCHSET > "$tmp_patch" cvs -q diff -uNp $PATCHSET >"$tmp_patch"
if [ -z "$PAGER" ]; then if [ -z "$PAGER" ]; then
PAGER="less -F" PAGER="less -F"
fi fi
@ -306,4 +306,3 @@ done
if [ -z "$1" ]; then if [ -z "$1" ]; then
recipe_build recipe_build
fi fi

View file

@ -23,34 +23,57 @@ fi
matrix_send() { matrix_send() {
msg="$1" msg="$1"
if [ ! -z "$msg" ]; then if [ ! -z "$msg" ]; then
jq --null-input \ (
--arg body "$msg" \ printf '{'
--arg formatted_body "$msg" \ printf '"body":'
--arg format "org.matrix.custom.html" \ json -e "$msg"
--arg msgtype "m.text" \ printf ',"formatted_body":'
'{"body":$body,"formatted_body":$formatted_body,"format":$format,"msgtype":$msgtype}' | json -e "$msg"
$CURL -X PUT -d @- "$HOMESERVER/client/v3/rooms/$PATCHES_ROOM/send/m.room.message/$(date +%s)?access_token=$ACCESS_TOKEN" printf ',"format":"org.matrix.custom.html",'
printf '"msgtype":"m.text"'
printf '}'
) | $CURL -X PUT -d @- "$HOMESERVER/client/v3/rooms/$PATCHES_ROOM/send/m.room.message/$(date +%s)?access_token=$ACCESS_TOKEN"
fi fi
} }
matrix_get_files() {
$CURL "$HOMESERVER/client/v3/sync?access_token=$ACCESS_TOKEN" |
jq ".rooms.join.\"$PATCHES_ROOM\".timeline.events[] | select(.type==\"m.room.message\") | .content | select(.msgtype==\"m.file\") | [.body,.info.size,.url] | @tsv" |
cut -d '"' -f 2 |
sed 's/\\t/,/g'
}
case "$1" in case "$1" in
"ingress") "ingress")
matrix_get_files | while IFS="," read -r file size url; do timeline="/tmp/timeline.json"
server=$(echo "$url" | cut -d '/' -f 3) $CURL "$HOMESERVER/client/v3/sync?access_token=$ACCESS_TOKEN" |
id=$(echo "$url" | cut -d '/' -f 4) json -s "rooms->join->${PATCHES_ROOM}->timeline" >"$timeline"
ext=$(echo "$file" | rev | cut -d '.' -f 1 | rev)
if [ "$ext" != "patch" ] || [ "$size" -gt "$MAX_SIZE" ] || [ -f "$TP_DIR/ingress/$id.patch" ]; then length=$(cat "$timeline" | json -s "events->@length")
i=0
while [ $i -lt $length ]; do
content=$(cat "$timeline" | json -s "events[$i]->content->^body->^formatted_body")
i=$((i + 1))
type=$(echo "$content" | json -s "msgtype->@decode")
if [ "$type" != "m.file" ]; then
continue continue
fi fi
size=$(echo "$content" | json -s "info->size")
if [ "$size" -gt "$MAX_SIZE" ]; then
continue
fi
file=$(echo "$content" | json -s "filename->@decode")
ext=$(echo "$file" | rev | cut -d '.' -f 1 | rev)
if [ "$ext" != "patch" ]; then
continue
fi
url=$(echo "$content" | json -s "url->@decode")
id=$(echo "$url" | cut -d '/' -f 4)
if [ -f "$TP_DIR/ingress/$id.patch" ]; then
continue
fi
server=$(echo "$url" | cut -d '/' -f 3)
if ! $CURL -o "$TP_DIR/ingress/$id.patch" "$HOMESERVER/media/v3/download/$server/$id"; then if ! $CURL -o "$TP_DIR/ingress/$id.patch" "$HOMESERVER/media/v3/download/$server/$id"; then
rm "$TP_DIR/ingress/$id.patch" rm "$TP_DIR/ingress/$id.patch"
echo "Failed to fetch mxc://$server/$id." echo "Failed to fetch mxc://$server/$id."
@ -66,9 +89,9 @@ case "$1" in
ln -s "../p/$count.patch" "$count.patch" ln -s "../p/$count.patch" "$count.patch"
) )
echo "$count" > "$TP_DIR/count.txt" echo "$count" >"$TP_DIR/count.txt"
matrix_send "Queued <code>$file</code> as <a href=\"https://telodendria.io/patches/p/$count.patch\">#$count</a>" > /dev/null matrix_send "Queued <code>$file</code> as <a href=\"https://telodendria.io/patches/p/$count.patch\">#$count</a>" >/dev/null
done done
;; ;;
"queue") "queue")
@ -89,7 +112,7 @@ case "$1" in
;; ;;
"apply") "apply")
if [ -f "$TP_DIR/queued/$2.patch" ]; then if [ -f "$TP_DIR/queued/$2.patch" ]; then
patch < "$TP_DIR/queued/$2.patch" patch <"$TP_DIR/queued/$2.patch"
else else
echo "Patch #$2 doesn't exist in the queue." echo "Patch #$2 doesn't exist in the queue."
exit 1 exit 1
@ -97,13 +120,13 @@ case "$1" in
;; ;;
"reverse") "reverse")
if [ -f "$TP_DIR/queued/$2.patch" ]; then if [ -f "$TP_DIR/queued/$2.patch" ]; then
patch -R < "$TP_DIR/queued/$2.patch" patch -R <"$TP_DIR/queued/$2.patch"
else else
echo "Patch #$2 doesn't exist in the queue." echo "Patch #$2 doesn't exist in the queue."
exit 1 exit 1
fi fi
;; ;;
"accept"|"reject") "accept" | "reject")
if [ -f "$TP_DIR/queued/$2.patch" ]; then if [ -f "$TP_DIR/queued/$2.patch" ]; then
mv "$TP_DIR/queued/$2.patch" "$TP_DIR/${1}ed/$2.patch" mv "$TP_DIR/queued/$2.patch" "$TP_DIR/${1}ed/$2.patch"
msg="Patch <a href=\"https://telodendria.io/patches/p/$2.patch\">#$2</a> was marked as ${1}ed." msg="Patch <a href=\"https://telodendria.io/patches/p/$2.patch\">#$2</a> was marked as ${1}ed."

View file

@ -101,7 +101,7 @@ query(char *select, HashMap * json)
func = 1; func = 1;
} }
else if (keyName[0] == '!') else if (keyName[0] == '^')
{ {
if (JsonValueType(val) == JSON_OBJECT) if (JsonValueType(val) == JSON_OBJECT)
{ {