Skip to content

Commit

Permalink
Correct states of operation in Table of Implemented Operations
Browse files Browse the repository at this point in the history
* Add new script bin/update_stats.sh to update README automatically
* New script bin/gen_stats.sh which was part of bin/compile.sh
* Operation may in y, x or ~ state
* Correct states of operations by providing them in the original source
  • Loading branch information
icy committed Oct 22, 2017
1 parent 64e68b7 commit 8e13cce
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 132 deletions.
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ $ docker run --rm -ti \
1. Please **do not** use `make pacapt` to update `pacapt`,
and/or modify it manually;
1. For your development, use `make pacapt.dev`;
To generate the table of implemented options, use `PACAPT_STATS=1`.
This table is manually replaced the one in `README` file.

## Branches

Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ default:
@echo ' Please use DISTRO= to specify Docker image'
@echo " tests : Run all tests. Please read tests/README.md first."
@echo " Use TESTS= to specify a package. Docker is required."
@echo " stats : Generate table of implemented operations in development branch."
@echo ""
@echo "Environments:"
@echo ""
@echo " VERSION : Version information. Default: git commit hash."
@echo " BINDIR : Destination directory. Default: /usr/local/bin."
@echo " DISTRO : Container image. Default: debian:stable."
@echo " PACAPT_STATS: Generate table of supported options. Default: yes"

# Build and install development script

Expand Down Expand Up @@ -76,6 +76,10 @@ docker.i:
-v $(PWD)/pacapt.dev:$(BINDIR)/pacman \
$(DISTRO) /bin/bash

.PHONY: stats
stats:
@./bin/gen_stats.sh

.PHONY: clean
clean:
@if git clean -nX | grep -q .; then \
Expand Down
44 changes: 23 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,30 +110,32 @@ A short description can be found at

## Implemented operations

Notes:
1. Though being marked as `supported`, some operation may only generate
`Unsupported` error and/or do nothing.
1. The table below is generated from source. Please don't update it manually.

```
Q Qc Qi Qk Ql Qm Qo Qp Qs Qu R Rn Rns Rs S Sc Scc Sccc Si Sii Sl Ss Su Suy Sw Sy U
apk y . y . y . y . y y y y y y y y y y y y y y y y y y y
cave y . y . y . y y y y y y y y y y y y y . . y y y . y y
dnf y y y . y y y y y y y . . . y y y y y . y y y y y y y
dpkg y . y . y . y y y y y y y y y y y y y y . y y y . y y
homebrew y y y . y . y . y y y . . y y y y y y . . y y y . y .
macports . y . . y . y . . y y . . y y y y . y . . y y y . y .
pkgng y . y . y . y y . y y . . y y y y . y . . y y y . y .
pkg_tools y . y . y . y y . y y y y y y y y . y . y y y y . y .
portage y y y . y . y . . y y . . y y y y y y . . y y y . y .
sun_tools y . y . y . y . y . y . . . . . . . . . . . . . . . y
swupd . . . y . . y . y . y . . . y . . . . . . y y y . y .
tazpkg y . y . y . y . . . y . . . y y y . . . . y y y . y y
xbps y . y . y . y y y y y y y y y y y y y y . y y y y y y
yum y y y . y y y y y y y . . y y y y y y y . y y y . y y
zypper y y y . y y y y y y y y y y y y y y y y y y y y y y y
Q Qc Qi Qk Ql Qm Qo Qp Qs Qu R Rn Rns Rs S Sc Scc Sccc Si Sii Sl Ss Su Suy Sw Sy U
apk ~ . y . y . y . y y y y y y y y y y y y y y y y y y y
cave y . y . y . y y y y y y y y y y y x y . . y y y . y x
dnf ~ y y . y y y y y y y . . . y y y y y . y y y y y y y
dpkg ~ . y . y . y y y y y y y ~ y y y y y y . y y y . y y
homebrew ~ y y . y . y . y y y . . y y y y y y . . y y y . y .
macports . y . . y . y . . y y . . ~ y y y . y . . y y y . y .
pkgng y . y . y . y y . y y . . y y y y . y . . y y y . y .
pkg_tools ~ . y . y . y y . y y y y ~ y y x . y . y ~ y y . x .
portage y y y . y . y . . y y . . y y y y y y . . y y y . y .
sun_tools y . y . y . y . y . y . . . . . . . . . . . . . . . y
swupd . . . y . . y . y . y . . . y . . . . . . y y y . y .
tazpkg y . y . y . y . . . y . . . y y y . . . . y y y . y y
xbps y . y . y . y y y y y y y y y y y y y y . y y y y y y
yum y y y . y y y y y y y . . y y y y y y y . y y y . y y
zypper y y y . y y y y y y y y y y y y y y y y y y y y y y y
```

**Notes:**

* *y*: Implemented;
* *~*: Implemented. Some options may not supported/implemented;
* *x*: Operation is not supported by Operating system;
* The table below is generated from source. Please don't update it manually.

## Related projects

* [An Arch's pacman-like package manager for Windows](https://github.com/Grenadingue/batch-pacapt)
Expand Down
109 changes: 1 addition & 108 deletions bin/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ done
# Detect all supported operations.
########################################################################

_operations=()

echo "_validate_operation() {"
echo " case \"\$1\" in"

Expand All @@ -139,7 +137,6 @@ for L in ./lib/*.sh; do

while read F; do
echo " \"$F\") ;;"
_operations+=( "$F" )
done < \
<(
$GREP -hE "^${_PKGNAME}_[^ \t]+\(\)" "$L" \
Expand All @@ -159,108 +156,4 @@ echo "}"

$GREP -v '^#' lib/zz_main.sh

########################################################################
# Stop here, or continue...
########################################################################

if [[ -z "${PACAPT_STATS:-}" ]]; then
echo >&2 "pacapt version '$VERSION' has been generated"
exit
fi

########################################################################
# For developers only
#
# PxO Q Qi Qs ...
# dpkg x o o ...
# yum o o o ...
#
########################################################################

_soperations="$(
echo "${_operations[@]}" \
| sed -e 's# #\n#g' \
| sed -e 's#^.*_\([A-Z][a-z]*\)#\1#g' \
| sort -u
)"

# Print the headers
_ret="$(printf " %9s " "")"
for _sopt in $_soperations; do
_size="$(( ${#_sopt} + 1))"
_ret="$(printf "%s%${_size}s" "$_ret" "$_sopt")"
done
printf >&2 "%s\n" "$_ret"

i=0 # index
rs=0 # restart

_operations+=( "xxx_yyy" )

while :; do
_ret=""

[[ "$i" -lt "${#_operations[@]}" ]] \
|| break

_cur_pkg="${_operations[$i]}"
_cur_pkg="${_cur_pkg%_*}"

for _sopt in $_soperations; do
# Detect flag for this secondary option
_flag="."

# Start from the #rs index,
# go to boundary of the next package name.
# xx_Qi, xx_Qs,... yy_Qi, yy_Qs,...
#
i=$rs
while [[ "$i" -lt "${#_operations[@]}" ]]; do
_opt="${_operations[$i]}"

_cur2_opt="${_opt##*_}"
_cur2_pkg="${_opt%_*}"

# echo >&2 "(cur_pkg = $_cur_pkg, look up $_sopt [from $rs], found $_cur2_opt)"

# Reach the boundary of the next package name
if [[ "$_cur2_pkg" != "$_cur_pkg" ]]; then
break
else
if [[ "$_cur2_opt" == "$_sopt" ]]; then
_flag="y"
break
else
(( i ++ )) ||:
fi
fi
done

_size="$(( ${#_sopt} + 1))"
_ret="$(printf "%s%${_size}s" "$_ret" "$_flag")"
done

# Detect the next #restart index
i=$rs
while [[ "$i" -lt "${#_operations[@]}" ]]; do
_opt="${_operations[$i]}"
_cur2_pkg="${_opt%_*}"

if [[ "$_cur2_pkg" != "$_cur_pkg" ]]; then
rs=$i
break
fi

(( i ++ )) ||:
done

if [[ "$_cur_pkg" != "xxx" ]]; then
printf >&2 " %9s %s\n" "$_cur_pkg" "$_ret"
fi
done

########################################################################
# Print statistics and the fancy table
########################################################################

echo >&2 "pacapt version '$VERSION' has been generated"
echo >&2 "pacapt version '$VERSION' has been generated."
147 changes: 147 additions & 0 deletions bin/gen_stats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#!/usr/bin/env bash

# Purpose : Generate the table of implemented operations
# Author : Ky-Anh Huynh
# License : MIT
# Origin : ./bin/compile.sh

# <DRY_ME_PLEASE>
: "${PACAPT_STATS:=yes}" # List implemented operations to STDERR
: "${GREP:=grep}" # Need to update on SunOS
: "${AWK:=awk}" # Need to update on SunOS

# At compile time, `_sun_tools_init` is not yet defined.
if [[ -f "lib/sun_tools.sh" ]]; then
source "lib/sun_tools.sh" :
_sun_tools_init
fi

export GREP AWK VERSION PACAPT_STATS
# </DRY_ME_PLEASE>

# $1:
_implState() {
if grep -qs "# ${1} _not_implemented" ./lib/*.sh; then
echo "x"
elif grep -qs "# ${1} may _not_implemented" ./lib/*.sh; then
echo "~"
else
echo "y"
fi
}

printf >&2 ":: $0: Generating statistics (table of implemented operations)..."

# Operations (FQDN)
_OPERATIONS=()
for L in ./lib/*.sh; do
_PKGNAME="${L##*/}"
_PKGNAME="${_PKGNAME%.*}"

case "$_PKGNAME" in
"zz_main"|"00_core") continue ;;
esac

while read F; do
_OPERATIONS+=( "$F" )
done < \
<(
$GREP -hE "^${_PKGNAME}_[^ \t]+\(\)" "$L" \
| $AWK -F '(' '{print $1}'
)
done

# Secondary options
_SOPERATIONS="$(
echo "${_OPERATIONS[@]}" \
| sed -e 's# #\n#g' \
| sed -e 's#^.*_\([A-Z][a-z]*\)#\1#g' \
| sort -u
)"

printf "\n"
printf "\`\`\`\n"

# Print the headers
_ret="$(printf "%9s " "")"
for _sopt in $_SOPERATIONS; do
_size="$(( ${#_sopt} + 1))"
_ret="$(printf "%s%${_size}s" "$_ret" "$_sopt")"
done
printf "%s\n" "$_ret"

i=0 # index
rs=0 # restart

_OPERATIONS+=( "xxx_yyy" )

while :; do
_ret=""

[[ "$i" -lt "${#_OPERATIONS[@]}" ]] \
|| break

_cur_pkg="${_OPERATIONS[$i]}"
_cur_pkg="${_cur_pkg%_*}"

for _sopt in $_SOPERATIONS; do
# Detect flag for this secondary option
_flag="."

# Start from the #rs index,
# go to boundary of the next package name.
# xx_Qi, xx_Qs,... yy_Qi, yy_Qs,...
#
i=$rs
while [[ "$i" -lt "${#_OPERATIONS[@]}" ]]; do
_opt="${_OPERATIONS[$i]}"

_cur2_opt="${_opt##*_}"
_cur2_pkg="${_opt%_*}"

# echo >&2 "(cur_pkg = $_cur_pkg, look up $_sopt [from $rs], found $_cur2_opt)"

# Reach the boundary of the next package name
if [[ "$_cur2_pkg" != "$_cur_pkg" ]]; then
break
else
if [[ "$_cur2_opt" == "$_sopt" ]]; then
# detect real state of this operation...
_flag="$(_implState "$_opt")"
break
else
(( i ++ )) ||:
fi
fi
done

_size="$(( ${#_sopt} + 1))"
_ret="$(printf "%s%${_size}s" "$_ret" "$_flag")"
done

# Detect the next #restart index
i=$rs
while [[ "$i" -lt "${#_OPERATIONS[@]}" ]]; do
_opt="${_OPERATIONS[$i]}"
_cur2_pkg="${_opt%_*}"

if [[ "$_cur2_pkg" != "$_cur_pkg" ]]; then
rs=$i
break
fi

(( i ++ )) ||:
done

if [[ "$_cur_pkg" != "xxx" ]]; then
printf "%9s %s\n" "$_cur_pkg" "$_ret"
fi
done

printf "\`\`\`\n"
printf "\n**Notes:**\n\n"
printf "* *y*: Implemented;\n"
printf "* *~*: Implemented. Some options may not supported/implemented;\n"
printf "* *x*: Operation is not supported by Operating system;\n"
printf "* The table below is generated from source. Please don't update it manually.\n"
printf "\n"
33 changes: 33 additions & 0 deletions bin/update_stats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

# Purpose : Update table of implemented operations in README.md
# Author : Ky-Anh Huynh
# License : MIT

./bin/gen_stats.sh > stats.tmp

< README.md awk '
BEGIN {
ins = 0
}
{
if ($0 ~ /## Implemented operations/) {
print $0;
ins = 1;
}
else {
if ($0 ~ /##/) {
print $0;
ins = 0;
}
else if (ins == 0) {
print $0;
}
}
}
' \
| sed -e '/## Implemented operations/r stats.tmp' \
> README.md.tmp

mv README.md.tmp README.md
git diff README.md
Loading

0 comments on commit 8e13cce

Please sign in to comment.