File: playdemo

package info (click to toggle)
modules 5.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,996 kB
  • sloc: exp: 79,667; sh: 6,142; tcl: 5,895; makefile: 1,478; ansic: 474; python: 272; csh: 202; perl: 47; ruby: 44; lisp: 13
file content (71 lines) | stat: -rwxr-xr-x 2,171 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env tclsh
#
# PLAYDEMO, play demos recorded with asciinema
# Copyright (C) 2019-2021 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 2 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: