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,21 +49,21 @@ 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"
;; ;;
*) *)
# Platform unknown, force rebuilding the whole # Platform unknown, force rebuilding the whole
# project every time. # project every time.
echo "0" echo "0"
;; ;;
esac esac
else else
echo "0" echo "0"
fi fi
} }
# Substitute shell variables in a stream with their actual value # Substitute shell variables in a stream with their actual value
@ -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"
@ -104,7 +104,7 @@ recipe_build() {
if [ $(basename "$obj" .o) != "$MAIN" ]; then if [ $(basename "$obj" .o) != "$MAIN" ]; then
objs="$objs $obj" objs="$objs $obj"
fi fi
if [ $(mod_time "$src") -ge $(mod_time "../$obj") ]; then if [ $(mod_time "$src") -ge $(mod_time "../$obj") ]; then
echo "CC $(basename $obj)" echo "CC $(basename $obj)"
obj_dir=$(dirname "../$obj") obj_dir=$(dirname "../$obj")
@ -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

@ -7,8 +7,8 @@
. "$(pwd)/tools/lib/common.sh" . "$(pwd)/tools/lib/common.sh"
if [ -z "$TELODENDRIA_PUB" ]; then if [ -z "$TELODENDRIA_PUB" ]; then
echo "TELODENDRIA_PUB not set." echo "TELODENDRIA_PUB not set."
exit 1 exit 1
fi fi
TP_DIR="$TELODENDRIA_PUB/patches" TP_DIR="$TELODENDRIA_PUB/patches"
@ -16,110 +16,133 @@ TP_DIR="$TELODENDRIA_PUB/patches"
CURL="curl -s" CURL="curl -s"
if [ ! -d "$TP_DIR" ]; then if [ ! -d "$TP_DIR" ]; then
echo "$TP_DIR does not exist." echo "$TP_DIR does not exist."
exit 1 exit 1
fi 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",'
fi 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"
matrix_get_files() { fi
$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")
continue
fi
if ! $CURL -o "$TP_DIR/ingress/$id.patch" "$HOMESERVER/media/v3/download/$server/$id"; then 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
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
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."
echo "Will try again next time." echo "Will try again next time."
continue continue
fi fi
count=$(cat "$TP_DIR/count.txt") count=$(cat "$TP_DIR/count.txt")
count=$((count + 1)) count=$((count + 1))
cp "$TP_DIR/ingress/$id.patch" "$TP_DIR/p/$count.patch" cp "$TP_DIR/ingress/$id.patch" "$TP_DIR/p/$count.patch"
( (
cd "$TP_DIR/queued" cd "$TP_DIR/queued"
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")
find "$TP_DIR/queued" -name '*.patch' | while IFS= read -r patch; do find "$TP_DIR/queued" -name '*.patch' | while IFS= read -r patch; do
n=$(basename "$patch" .patch) n=$(basename "$patch" .patch)
echo "Patch #$n:" echo "Patch #$n:"
head -n3 "$patch" head -n3 "$patch"
echo echo
done done
;; ;;
"view") "view")
if [ -f "$TP_DIR/queued/$2.patch" ]; then if [ -f "$TP_DIR/queued/$2.patch" ]; then
less "$TP_DIR/queued/$2.patch" less "$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
;; ;;
"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
fi fi
;; ;;
"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."
msgFile="/tmp/patchmsg-$(date +%s).txt" msgFile="/tmp/patchmsg-$(date +%s).txt"
$EDITOR "$msgFile" $EDITOR "$msgFile"
if [ -f "$msgFile" ]; then if [ -f "$msgFile" ]; then
msg="$msg<br><blockquote>$(cat $msgFile)<br>&mdash;$DISPLAY_NAME ($MXID)</blockquote>" msg="$msg<br><blockquote>$(cat $msgFile)<br>&mdash;$DISPLAY_NAME ($MXID)</blockquote>"
fi fi
matrix_send "$msg" matrix_send "$msg"
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
;; ;;
*) *)
echo "No action specified." echo "No action specified."
exit 1 exit 1
;; ;;
esac esac

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)
{ {