diff --git a/Makefile.am b/Makefile.am index e33050ee..96c9ede3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -67,8 +67,6 @@ bin_PROGRAMS = bin_SCRIPTS = dist_doc_DATA = -docs_targets = docs/Utilities - check-target: @test $(prefix) = $(shell $(top_srcdir)/build-aux/version.sh --install) || ( echo "ERROR [Makefile]: prefix '$(prefix)' and target '($(shell $(top_srcdir)/build-aux/version.sh --install))' mismatch; ./configure is outdated. Build using '--clean' option to fix this." > /dev/stderr ; false ) @@ -331,7 +329,5 @@ documents/gridlabd.pdf: documents/gridlabd.glm (cd documents ; $(DESTDIR)$(bindir)/gridlabd gridlabd.glm | echo "WARNING: unable to update documents/gridlabd.pdf") test -f documents/gridlabd.md && pandoc -V geometry:landscape documents/gridlabd.md -o documents/gridlabd.pdf -docs: $(docs_targets) # documents/gridlabd.pdf - docs_toc: utilities/regen_toc >'docs/User manual/0 - Cover/1 - Contents.md' diff --git a/docs/Makefile.mk b/docs/Makefile.mk index 19526eeb..e2c793f7 100644 --- a/docs/Makefile.mk +++ b/docs/Makefile.mk @@ -1,15 +1,17 @@ -DOCS = -DOCS += docs/Utilities/Framework.md -DOCS += docs/Utilities/Network.md -DOCS += docs/Utilities/Edit.md -DOCS += docs/Utilities/Mapping.md -DOCS += docs/Utilities/Unitcalc.md +docs: docs/Utilities + +DOCS_UTILITIES = +DOCS_UTILITIES += docs/Utilities/Framework.md +DOCS_UTILITIES += docs/Utilities/Network.md +DOCS_UTILITIES += docs/Utilities/Edit.md +DOCS_UTILITIES += docs/Utilities/Mapping.md +DOCS_UTILITIES += docs/Utilities/Unitcalc.md + +docs/Utilities: $(DOCS_UTILITIES) + echo "Updating $@..." %.md: FORCE - echo "Updating $@" $(DESTDIR)$(bindir)/gridlabd python docs/makemd.py $(basename $(notdir $(shell echo "$@" | tr 'A-Z' 'a-z'))) $(dir $@) -docs/Utilities: $(DOCS) - FORCE: diff --git a/subcommands/gridlabd-marimo b/subcommands/gridlabd-marimo index 9b6da27c..112b4e48 100644 --- a/subcommands/gridlabd-marimo +++ b/subcommands/gridlabd-marimo @@ -1,4 +1,5 @@ #!/bin/bash +## ## Syntax: gridlabd marimo [OPTIONS ...] [COMMAND] [NOTEBOOK] ## ## Options: @@ -9,6 +10,8 @@ ## ## * `--pid`: get the process id for the notebook (if any) ## +## * `-R|--repo`: change marimo repository (default `arras-energy/marimo`) +## ## * `--upgrade`: upgrade marimo to latest version ## ## * `--url`: get the URL for the notebook (if any) @@ -17,6 +20,8 @@ ## ## * `--wait`: wait for marimo server to exit ## +## * `-W|--workdir`: change work directory (default `gridlabd-marimo`) +## ## Commands: ## ## * `edit NOTEBOOK`: open the notebook in the marimo editor @@ -25,6 +30,8 @@ ## ## * `list`: list open marimo notebooks ## +## * `status`: list details of active notebooks +## ## * `stop NOTEBOOK`: stops the marimo notebook ## ## Run a gridlabd marimo notebook. @@ -53,8 +60,8 @@ LIB=$GLD_ETC/marimo LOG=$LIB/marimo.log -URL=https://raw.githubusercontent.com/arras-energy/marimo/refs/heads/main/source WAIT=no +WORKDIR=gridlabd-marimo E_OK=0 E_SYNTAX=1 @@ -62,6 +69,17 @@ E_FAIL=2 E_NOTFOUND=3 E_MISSING=4 +function repo() +{ + if [ $# -eq 0 ]; then + error "missing repo name" E_MISSING + fi + URL=https://raw.githubusercontent.com/$1/refs/heads/main/source + API=https://api.github.com/repos/$1/contents/source + GIT=https://github.com/$1 +} +repo arras-energy/marimo + function error() { # error MESSAGE [EXITCODE] @@ -90,13 +108,13 @@ function index() if [ "$(gridlabd.bin --version=branch)" == "master" ]; then curl -sL -H 'Cache-Control: no-cache' $URL/.index 2>>$LOG else - curl -sL -H 'Cache-Control: no-cache' https://api.github.com/repos/arras-energy/marimo/contents/source 2>>$LOG | grep '"name": ".*\.py",' | cut -f2 -d: | cut -f1 -d. | tr -cd "A-Za-z0-9_\\n" + curl -sL -H 'Cache-Control: no-cache' $API 2>>$LOG | grep '"name": ".*\.py",' | cut -f2 -d: | cut -f1 -d. | tr -cd "A-Za-z0-9_\\n" fi } function getlist() { - basename -s .py $(ps -ax | grep bin/marimo | grep -v grep | sed -r 's/ +/ /g' | cut -f7 -d' ') 2>>$LOG + basename -s .py $(ps -ax | grep bin/marimo | grep -v grep | sed -r 's/ +/ /g' | rev | cut -f1 -d'/' | rev ) 2>>$LOG } function getpid() @@ -105,13 +123,6 @@ function getpid() ps ax | grep bin/marimo | grep $EXE | cut -f1 -d' ' 2>>$LOG } -function getinfo() -{ - for PID in $*; do - lsof -i -P -a -p $PID | tail -n +1 2>>$LOG - done -} - function geturl() { PID=$(getpid $1) @@ -175,20 +186,30 @@ function edit() elif [ "$(gridlabd.bin --version=branch)" == "master" ]; then error "you must use a development version of gridlabd" E_FAIL fi - if [ -d gridlabd-marimo ]; then - ( cd gridlabd-marimo ; git pull ) + if [ -d "$WORKDIR" ]; then + ORIGIN=$(cd "$WORKDIR"; git remote get-url origin) + if [ "$URL" != "$ORIGIN" ]; then + warning "repository '$GIT' does not match '$WORKDIR' origin '$ORIGIN', unable to pull" + elif [ ! -d "$WORKDIR/.git" ]; then + warning "'$WORKDIR' is not a git repository (you cannot commit changes), unable to pull" + else + ( cd "$WORKDIR" ; git pull ) + fi else - git clone https://github.com/arras-energy/marimo gridlabd-marimo + git clone $GIT "$WORKDIR" || error "clone failed" E_FAIL fi - if [ ! -d gridlabd-marimo/source ]; then + if [ ! -d "$WORKDIR/source" ]; then error "clone failed" E_FAIL else - if [ ! -f gridlabd-marimo/source/$1.py ]; then - echo "Creating gridlabd-marimo/source/$1.py" + if [ ! -f "$WORKDIR/source/$1.py" ]; then + echo "Creating '$WORKDIR/source/$1.py'" fi - ( cd gridlabd-marimo/source ; marimo edit $1.py ) + echo "Opening marimo notebook..." >/dev/stderr + ( cd "$WORKDIR/source" ; marimo edit "$1.py" ) + fi + if [ -d "$WORKDIR/.git" ]; then + warning "don't forget to add/commit/push changes to '$WORKDIR' when done editing" fi - warning "don't forget to add/commit/push when done editing" } function open() @@ -203,6 +224,21 @@ function open() } +function status() +{ + LIST=$(getlist) + if [ ! -z "$LIST" ]; then + FORMAT="%-16.16s %-6.6s %-32.32s\n" + printf "$FORMAT" Name PID URL + printf "$FORMAT" ---------------- ------ -------------------------------- + for APP in $LIST; do + APPPID=$(getpid $APP) + APPURL=$(geturl $APP) + printf "$FORMAT" $APP $APPPID $APPURL + done + fi +} + mkdir -p $LIB/.etag echo "*** COMMAND = '$0 $*' ***" >>$LOG @@ -228,6 +264,10 @@ while [ $# -gt 0 ]; do getpid $2 shift 1 ;; + -R|--repo) + repo $2 + shift 1 + ;; --upgrade) python3 -m pip install --upgrade marimo shift 1 @@ -242,10 +282,21 @@ while [ $# -gt 0 ]; do --wait) WAIT=yes ;; + -W|--workdir) + if [ $# -eq 1 ]; then + error "missing folder name" E_MISSING + fi + WORKDIR=$2 + shift + ;; index) # list of available apps index exit $E_OK ;; + status) + status + exit $E_OK + ;; list) # list of active apps getlist exit $E_OK