~alias/polybase-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] First draft of "Packs" patch

Details
Message ID
<20240913200110.10048-1-lucsaccoccio@disroot.org>
DKIM signature
pass
Download raw message
Patch: +74 -14
This is only a first draft, the code is still messy/redundant, sorry :/

Signed-off-by: Luc-Saccoccio <lucsaccoccio@disroot.org>
---
 packs.txt |  2 ++
 polybase  | 86 ++++++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 74 insertions(+), 14 deletions(-)
 create mode 100644 packs.txt

diff --git a/packs.txt b/packs.txt
new file mode 100644
index 0000000..311aa6d
--- /dev/null
+++ b/packs.txt
@@ -0,0 +1,2 @@
L2:(('LU2IN002','TD',1),('LU2IN005','TD',1),('LU2IN018','Memento',1),('LU2IN018','TME',1),('LU2IN019','TD',1))
L3_BDD:(('LU3IN009','Cours',1),('LU3IN009','TD',1))
diff --git a/polybase b/polybase
index 81720aa..e5de687 100755
--- a/polybase
+++ b/polybase
@@ -67,25 +67,51 @@ course_page() {
decrement() {
	authcheck
	[ "$1" ] || front_page '=> /decrement'
	course="$(coursecheck $1)"
	[ "$course" ] || die code 51
	code=$(echo "$course" | cut -f 1)
	kind=$(echo "$course" | cut -f 2)
	part=$(echo "$course" | cut -f 3)

	sqlite3 "$DB" "UPDATE courses SET quantity = quantity - 1 WHERE (code, kind, part) IN (('$code', '$kind', $part));"
	if [ -eq "$(echo "$1" | cut -d_ -f 1)" "pack"]
	then
		while read -r pack
		do
			pack_name=$(echo "$pack" | cut -d: -f 1)
			pack_content=$(echo "$pack" | cut -d: -f 2)
			if [ -eq "$pack_name" "$(echo "$1" | cut -d_ -f 2-)" ]
			then
				sqlite3 "$DB" "UPDATE courses SET quantity = quantity - 1 WHERE (code, kind, part) IN $pack_content;"
			fi
		done < packs.txt
	else
		course="$(coursecheck $1)"
		[ "$course" ] || die code 51
		code=$(echo "$course" | cut -f 1)
		kind=$(echo "$course" | cut -f 2)
		part=$(echo "$course" | cut -f 3)

		sqlite3 "$DB" "UPDATE courses SET quantity = quantity - 1 WHERE (code, kind, part) IN (('$code', '$kind', $part));"
	fi
}

increment() {
	authcheck
	[ "$1" ] || front_page '=> /increment'
	course="$(coursecheck $1)"
	[ "$course" ] || die code 51
	code=$(echo "$course" | cut -f 1)
	kind=$(echo "$course" | cut -f 2)
	part=$(echo "$course" | cut -f 3)

	sqlite3 "$DB" "UPDATE courses SET quantity = quantity + 1 WHERE (code, kind, part) IN (('$code', '$kind', $part));"
	if [ -eq "$(echo "$1" | cut -d_ -f 1)" "pack"]
	then
		while read -r pack
		do
			pack_name=$(echo "$pack" | cut -d: -f 1)
			pack_content=$(echo "$pack" | cut -d: -f 2)
			if [ -eq "$pack_name" "$(echo "$1" | cut -d_ -f 2-)" ]
			then
				sqlite3 "$DB" "UPDATE courses SET quantity = quantity - 1 WHERE (code, kind, part) IN $pack_content;"
			fi
		done < packs.txt
	else
		course="$(coursecheck $1)"
		[ "$course" ] || die code 51
		code=$(echo "$course" | cut -f 1)
		kind=$(echo "$course" | cut -f 2)
		part=$(echo "$course" | cut -f 3)

		sqlite3 "$DB" "UPDATE courses SET quantity = quantity + 1 WHERE (code, kind, part) IN (('$code', '$kind', $part));"
	fi
}

set_quantity() {
@@ -126,6 +152,38 @@ front_page() {
			echo '=> / Change Individually'
			echo ;;
	esac

	if $($links)
	then
		echo
		echo "## Packs"
		while read -r pack
		do
			pack_name=$(echo "$pack" | cut -d: -f 1)
			real_pack_name=$(echo "$pack_name" | tr '_' ' ')
			pack_content=$(echo "$pack" | cut -d: -f 2)
			echo
			case "$1" in
				'=> /increment'|'=> /decrement')
					echo "$1/$pack_name $real_pack_name" ;;
				*)
					echo "=> $real_pack_name" ;;
			esac
			sqlite3 "$DB" '.headers OFF' '.mode tabs' "SELECT code, kind, part, parts, name, quantity, total, shown FROM courses WHERE (code, kind, part) IN $pack_content $($links || echo 'AND shown = true ')ORDER BY code, part;" | while read -r row
				do
					code=$(echo "$row" | cut -f 1)
					kind=$(echo "$row" | cut -f 2)
					part=$(echo "$row" | cut -f 3)
					parts=$(echo "$row" | cut -f 4)
					name=$(echo "$row" | cut -f 5)
					quantity=$(echo "$row" | cut -f 6)
					total=$(echo "$row" | cut -f 7)
					shown=$(echo "$row" | cut -f 8)
					echo "> $code ($kind), $name$([ $parts -gt 1 ] && echo ' (partie '$part/$parts')')$([ $shown = 1 ] || echo ' (hidden)'): $quantity/$total"
				done
		done < packs.txt
	fi

	sqlite3 "$DB" '.headers OFF' '.mode tabs' 'SELECT DISTINCT semester FROM courses ORDER BY semester DESC;' | while read -r semester
	do
		echo
--
2.46.0
Details
Message ID
<D4AMS9VJXQCC.2MXI3RAD1WR35@disroot.org>
In-Reply-To
<20240913200110.10048-1-lucsaccoccio@disroot.org> (view parent)
DKIM signature
pass
Download raw message
Thanks :) applied with fixes

Indeed this needs to be rehauled but good enough for now

To git@git.sr.ht:~alias/polybase
   3f532ba..51ad80d  master -> master
Reply to thread Export thread (mbox)