Skip to content

Commit

Permalink
contrib: add 'playdemo' script
Browse files Browse the repository at this point in the history
  • Loading branch information
xdelaruelle committed Nov 21, 2019
1 parent 4466e4a commit a0de177
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/site.exp
/contrib/mtreview
/contrib/mb
/contrib/playdemo
/contrib/rpm/environment-modules.spec
/contrib/scripts/add.modules
/contrib/scripts/modulecmd
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ contrib/mb: contrib/mb.in version.inc
$(translate-in-script)
chmod +x $@

contrib/playdemo: contrib/playdemo.in version.inc
$(translate-in-script)
chmod +x $@

contrib/scripts/add.modules: contrib/scripts/add.modules.in
$(translate-in-script)

Expand Down Expand Up @@ -509,6 +513,7 @@ endif
rm -f modulecmd.tcl
rm -f contrib/mtreview
rm -f contrib/mb
rm -f contrib/playdemo
rm -f $(MODULECMDTEST)
rm -f contrib/scripts/add.modules
rm -f contrib/scripts/modulecmd
Expand Down
71 changes: 71 additions & 0 deletions contrib/playdemo.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!@TCLSHDIR@/tclsh
#
# PLAYDEMO, play demos recorded with asciinema
# Copyright (C) 2019 Xavier Delaruelle
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

##########################################################################

set demoparentpath [file normalize [file dirname $argv0]/../doc/demo]
set usage "Usage: $argv0 demo \[rep\] \[speed\]
Play designated demo rep times at given speed"

# parse command-line arguments
lassign $argv demoname demorep demospeed
if {$demoname eq "-h" || $demoname eq "--help"} {
puts stderr $usage
exit 0
} elseif {[llength $argv] > 3} {
puts stderr $usage
exit 1
}

# verify args
if {$demorep eq {}} {
set demorep 1
} elseif {![string is integer -strict $demorep]} {
puts stderr $usage
exit 1
}
if {$demospeed eq {}} {
set demospeed 1
} elseif {![string is integer -strict $demospeed]} {
puts stderr $usage
exit 1
}

# check demo exists
set demopath $demoparentpath/$demoname
if {![file isdirectory $demopath] || ![file readable $demopath]} {
puts stderr "ERROR: $demoname does not exist or is not readable"
exit 1
}

# verify asciinema availability
set asciinemapath [lindex [auto_execok asciinema] 0]
if {$asciinemapath eq {}} {
puts stderr "ERROR: command 'asciinema' cannot be found"
exit 1
}

# repeat demo play
for {set i 0} {$i < $demorep} {incr i} {
# play each file of the demo
foreach demofile [lsort [glob $demopath/*.cast]] {
exec $asciinemapath play -s $demospeed $demofile >@stdout 2>@stderr
}
}

# vim:set tabstop=3 shiftwidth=3 expandtab autoindent syntax=tcl:

0 comments on commit a0de177

Please sign in to comment.