fix expansions and add test suite
This commit is contained in:
parent
f717c85921
commit
7d3c84fed5
|
@ -1,7 +1,7 @@
|
|||
Package: sweeper
|
||||
Priority: optional
|
||||
Section: misc
|
||||
Version: 2.0.11
|
||||
Version: 2.0.12
|
||||
Architecture: mipsel
|
||||
Maintainer: af123@hummypkg.org.uk
|
||||
Depends: webif(>=1.2.4-3)
|
||||
|
|
|
@ -56,14 +56,69 @@ proc ::sweeper::expand_asfilename {ts &ret arg} {
|
|||
return [system filename $arg]
|
||||
}
|
||||
|
||||
set ::sweeper::brmap "( ) \[ ] \\{ \\}"
|
||||
|
||||
# Expand a string containing tokens
|
||||
proc ::sweeper::expand {ts str {orig ""}} {
|
||||
if {[string first "%" $str] == -1} {
|
||||
return $str
|
||||
}
|
||||
|
||||
# First process any extended functions
|
||||
|
||||
set ret $str
|
||||
set fnstack {}
|
||||
foreach {fn params} $::sweeper::expand_fns {
|
||||
|
||||
lassign $params numargs flags
|
||||
|
||||
set ls -1
|
||||
while {[set s [string first "%$fn" $ret]] >= 0} {
|
||||
if {$s <= $ls} break
|
||||
set ls $s
|
||||
|
||||
# Fetch the delimiter
|
||||
set chpos $($s + [string length $fn] + 1)
|
||||
set ch [string index $ret $chpos]
|
||||
|
||||
#log "Found FN $fn @ $s \[delim:$ch@$chpos]" 2
|
||||
|
||||
# Extract the arguments
|
||||
set pos $chpos
|
||||
set fnargs {}
|
||||
while {[llength $fnargs] < $numargs} {
|
||||
incr pos
|
||||
set e [string first $ch $ret $pos]
|
||||
if {$e == -1} {
|
||||
log "Error. %$fn - [llength $fnargs]/$numargs parameters found."
|
||||
break
|
||||
}
|
||||
lappend fnargs [::sweeper::expand $ts [
|
||||
string range $ret $pos $($e - 1)] $orig]
|
||||
set pos $e
|
||||
}
|
||||
|
||||
# s points to the start, e.g. %function
|
||||
# e points to the last delimiter or -1 if insufficient
|
||||
# arguments were found.
|
||||
|
||||
if {$e == -1} break
|
||||
|
||||
if {"inline" in $flags} {
|
||||
# For inline functions, replace the call with
|
||||
# the result.
|
||||
set fnret [
|
||||
::sweeper::expand_$fn $ts ret {*}$fnargs]
|
||||
set ret [string replace $ret $s $e $fnret]
|
||||
} else {
|
||||
# otherwise, queue the function up for later
|
||||
# execution.
|
||||
lappend fnstack $fn $fnargs
|
||||
# and remove the call
|
||||
set ret [string replace $ret $s $e]
|
||||
}
|
||||
}
|
||||
}
|
||||
#log "FNSTACK: $fnstack" 2
|
||||
|
||||
set glist [ts genrelist]
|
||||
set tsg [$ts get genre]
|
||||
if {![dict exists $glist $tsg]} {
|
||||
|
@ -131,64 +186,14 @@ proc ::sweeper::expand {ts str {orig ""}} {
|
|||
|
||||
# log $map 2
|
||||
|
||||
set ret [string map $map $str]
|
||||
set ret [string map $map $ret]
|
||||
log " Expanded \[$str] -> \[$ret]" 2
|
||||
|
||||
foreach {fn params} $::sweeper::expand_fns {
|
||||
# log " Looking for %$fn" 2
|
||||
|
||||
lassign $params numargs flags
|
||||
|
||||
set li -1
|
||||
while {[set i [string first "%$fn" $ret]] >= 0} {
|
||||
if {$i <= $li} break
|
||||
set li $i
|
||||
|
||||
# Fetch the delimiter
|
||||
set chpos $($i + [string length $fn] + 1)
|
||||
set ch [string index $ret $chpos]
|
||||
|
||||
# log " - found at $i (delim\[$ch])" 2
|
||||
|
||||
# Extract the arguments
|
||||
set pos $chpos
|
||||
set fnargs {}
|
||||
while {[llength $fnargs] < $numargs} {
|
||||
incr pos
|
||||
set e [string first $ch $ret $pos]
|
||||
if {$e == -1 && [ \
|
||||
dict exists $::sweeper::brmap $ch]} {
|
||||
set bch $::sweeper::brmap($ch)
|
||||
set e [string first $bch $ret $pos]
|
||||
}
|
||||
if {$e == -1} {
|
||||
log "Error. %$fn - [llength $fnargs]/$numargs parameters found."
|
||||
break
|
||||
}
|
||||
lappend fnargs [string range $ret \
|
||||
$pos $($e - 1)]
|
||||
set pos $e
|
||||
}
|
||||
|
||||
# log "FNARGS: ($fnargs)" 2
|
||||
|
||||
if {[llength $fnargs] == $numargs} {
|
||||
log " - Calling expand_$fn\($fnargs)" 2
|
||||
set fnret [
|
||||
::sweeper::expand_$fn $ts ret {*}$fnargs]
|
||||
log " - Result: ($ret) ($fnret)" 2
|
||||
}
|
||||
|
||||
if {"inline" in $flags} {
|
||||
set nret [string range $ret 0 $($i - 1)]
|
||||
append nret $fnret
|
||||
append nret [string range $ret $($pos + 1) end]
|
||||
set ret $nret
|
||||
} else {
|
||||
set ret [string replace $ret $($i - 1) $pos]
|
||||
}
|
||||
log " FN expanded \[$str] -> \[$ret]" 2
|
||||
}
|
||||
# Now call any queued extended functions
|
||||
foreach {fn fnargs} $fnstack {
|
||||
log " - Calling expand_$fn\($fnargs)" 2
|
||||
::sweeper::expand_$fn $ts ret {*}$fnargs
|
||||
log " Result: ($ret)" 2
|
||||
}
|
||||
|
||||
return $ret
|
||||
|
|
|
@ -41,5 +41,5 @@ proc scan_run {dir flag callback} {
|
|||
|
||||
set root [system mediaroot]
|
||||
|
||||
source auto.hook
|
||||
source /mod/webif/plugin/sweeper/auto.hook
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
#!/mod/bin/jimsh
|
||||
|
||||
source /mod/webif/plugin/sweeper/harness.jim
|
||||
|
||||
set ts [ts fetch /mod/webif/plugin/sweeper/th/rec/test.ts]
|
||||
|
||||
proc log {msg {level 1}} {
|
||||
#puts $msg
|
||||
}
|
||||
|
||||
#6/10. The Fame Game: Crime drama. While Sasha is occupied with an intensive training course, the boys' investigations take them to a lookalike agency. [HD] [AD,S]
|
||||
|
||||
foreach {test expected} {
|
||||
{%title} {New Tricks}
|
||||
{%synopsis%replace:Crime:XXX:} {6/10. The Fame Game: XXX drama. While Sasha is occupied with an intensive training course, the boys' investigations take them to a lookalike agency. [HD] [AD,S]}
|
||||
{PREAMBLE%synopsis%replace:Crime:XXX:POSTAMBLE} {PREAMBLE6/10. The Fame Game: XXX drama. While Sasha is occupied with an intensive training course, the boys' investigations take them to a lookalike agency. [HD] [AD,S]POSTAMBLE}
|
||||
{%replace:Crime:XXX:PREAMBLE %synopsis POSTAMBLE} {PREAMBLE 6/10. The Fame Game: XXX drama. While Sasha is occupied with an intensive training course, the boys' investigations take them to a lookalike agency. [HD] [AD,S] POSTAMBLE}
|
||||
{%asfilename:/mod/video/Test File/bob.ts:} {_mod_video_Test File_bob_ts}
|
||||
{/mod/video/%asfilename:bob/fred:.ts} {/mod/video/bob_fred.ts}
|
||||
{/mod/video/%asfilename:bob/fred:.ts%replace:video:radiator:} {/mod/radiator/bob_fred.ts}
|
||||
{%epname} {6/10. The Fame Game}
|
||||
{%epdescr} {s?e6/10}
|
||||
{%synopsis%regsub,Game:\s*,,} {6/10. The Fame Crime drama. While Sasha is occupied with an intensive training course, the boys' investigations take them to a lookalike agency. [HD] [AD,S]}
|
||||
{Z Nation_ 20150825_2200.ts%regsub,_ \s*, - ,} {Z Nation - 20150825_2200.ts}
|
||||
{%synopsis%regsub:^\s*([^ ]+)\s+([^ ]+).*:\1,\2:} {6/10.,The}
|
||||
} {
|
||||
set ret [::sweeper::expand $ts $test]
|
||||
|
||||
if {$ret eq $expected} {
|
||||
puts [format "%-70s => OK" $test]
|
||||
} else {
|
||||
puts [format "%-70s => FAIL" $test]
|
||||
puts " $ret"
|
||||
}
|
||||
|
||||
}
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue