adding flag/unflag/fileexists/%asfilename...
This commit is contained in:
parent
6ae2d773d5
commit
f717c85921
|
@ -1,7 +1,7 @@
|
||||||
Package: sweeper
|
Package: sweeper
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Section: misc
|
Section: misc
|
||||||
Version: 2.0.10
|
Version: 2.0.11
|
||||||
Architecture: mipsel
|
Architecture: mipsel
|
||||||
Maintainer: af123@hummypkg.org.uk
|
Maintainer: af123@hummypkg.org.uk
|
||||||
Depends: webif(>=1.2.4-3)
|
Depends: webif(>=1.2.4-3)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
set ::sweeper::cf "/mod/etc/sweeper.conf"
|
set ::sweeper::cf "/mod/etc/sweeper.conf"
|
||||||
set ::sweeper::dryrun 0
|
set ::sweeper::dryrun 0
|
||||||
set ::sweeper::lastruleresult 0
|
set ::sweeper::lastruleresult 0
|
||||||
|
set ::sweeper::stack {}
|
||||||
|
|
||||||
proc ::sweeper::unknown {cmd args} {
|
proc ::sweeper::unknown {cmd args} {
|
||||||
log "Unknown sweeper rule clause '$cmd'" 0
|
log "Unknown sweeper rule clause '$cmd'" 0
|
||||||
|
@ -36,6 +37,7 @@ proc ::sweeper::strcontains {ref val} {
|
||||||
set ::sweeper::expand_fns {
|
set ::sweeper::expand_fns {
|
||||||
replace {2}
|
replace {2}
|
||||||
regsub {2}
|
regsub {2}
|
||||||
|
asfilename {1 {inline}}
|
||||||
}
|
}
|
||||||
|
|
||||||
proc ::sweeper::expand_replace {ts &ret search replace} {
|
proc ::sweeper::expand_replace {ts &ret search replace} {
|
||||||
|
@ -50,6 +52,12 @@ proc ::sweeper::expand_regsub {ts &ret search replace} {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc ::sweeper::expand_asfilename {ts &ret arg} {
|
||||||
|
return [system filename $arg]
|
||||||
|
}
|
||||||
|
|
||||||
|
set ::sweeper::brmap "( ) \[ ] \\{ \\}"
|
||||||
|
|
||||||
# Expand a string containing tokens
|
# Expand a string containing tokens
|
||||||
proc ::sweeper::expand {ts str {orig ""}} {
|
proc ::sweeper::expand {ts str {orig ""}} {
|
||||||
if {[string first "%" $str] == -1} {
|
if {[string first "%" $str] == -1} {
|
||||||
|
@ -88,6 +96,10 @@ proc ::sweeper::expand {ts str {orig ""}} {
|
||||||
"%channel" [$ts get channel_name] \
|
"%channel" [$ts get channel_name] \
|
||||||
"%duration" [$ts duration] \
|
"%duration" [$ts duration] \
|
||||||
\
|
\
|
||||||
|
"%filename" [$ts get file] \
|
||||||
|
"%basename" [$ts bfile] \
|
||||||
|
"%folder" [$ts dir] \
|
||||||
|
\
|
||||||
%epname [$ts episode_name] \
|
%epname [$ts episode_name] \
|
||||||
%series [$ts get seriesnum] \
|
%series [$ts get seriesnum] \
|
||||||
%episodes [$ts get episodetot] \
|
%episodes [$ts get episodetot] \
|
||||||
|
@ -125,7 +137,7 @@ proc ::sweeper::expand {ts str {orig ""}} {
|
||||||
foreach {fn params} $::sweeper::expand_fns {
|
foreach {fn params} $::sweeper::expand_fns {
|
||||||
# log " Looking for %$fn" 2
|
# log " Looking for %$fn" 2
|
||||||
|
|
||||||
lassign $params numargs
|
lassign $params numargs flags
|
||||||
|
|
||||||
set li -1
|
set li -1
|
||||||
while {[set i [string first "%$fn" $ret]] >= 0} {
|
while {[set i [string first "%$fn" $ret]] >= 0} {
|
||||||
|
@ -136,7 +148,7 @@ proc ::sweeper::expand {ts str {orig ""}} {
|
||||||
set chpos $($i + [string length $fn] + 1)
|
set chpos $($i + [string length $fn] + 1)
|
||||||
set ch [string index $ret $chpos]
|
set ch [string index $ret $chpos]
|
||||||
|
|
||||||
log " - found at $i (delim\[$ch])" 2
|
# log " - found at $i (delim\[$ch])" 2
|
||||||
|
|
||||||
# Extract the arguments
|
# Extract the arguments
|
||||||
set pos $chpos
|
set pos $chpos
|
||||||
|
@ -144,6 +156,11 @@ proc ::sweeper::expand {ts str {orig ""}} {
|
||||||
while {[llength $fnargs] < $numargs} {
|
while {[llength $fnargs] < $numargs} {
|
||||||
incr pos
|
incr pos
|
||||||
set e [string first $ch $ret $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} {
|
if {$e == -1} {
|
||||||
log "Error. %$fn - [llength $fnargs]/$numargs parameters found."
|
log "Error. %$fn - [llength $fnargs]/$numargs parameters found."
|
||||||
break
|
break
|
||||||
|
@ -153,11 +170,24 @@ proc ::sweeper::expand {ts str {orig ""}} {
|
||||||
set pos $e
|
set pos $e
|
||||||
}
|
}
|
||||||
|
|
||||||
set ret [string replace $ret $i $pos]
|
# log "FNARGS: ($fnargs)" 2
|
||||||
|
|
||||||
if {[llength $fnargs] == $numargs} {
|
if {[llength $fnargs] == $numargs} {
|
||||||
log " - Calling expand_$fn\($fnargs)" 2
|
log " - Calling expand_$fn\($fnargs)" 2
|
||||||
::sweeper::expand_$fn $ts ret {*}$fnargs
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,6 +458,26 @@ proc ::sweeper::foldername {ts str folder} {
|
||||||
return [::sweeper::strcontains [$ts dir] $str]
|
return [::sweeper::strcontains [$ts dir] $str]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc ::sweeper::fileexists {ts str folder} {
|
||||||
|
if {[string index $str 0] ne "/"} {
|
||||||
|
set str "[$ts dir]/[::sweeper::expand $ts $str]"
|
||||||
|
} else {
|
||||||
|
set str [::sweeper::expand $ts $str]
|
||||||
|
}
|
||||||
|
log " FILEEXISTS($str)" 2
|
||||||
|
return [file isfile $str]
|
||||||
|
}
|
||||||
|
|
||||||
|
proc ::sweeper::direxists {ts str folder} {
|
||||||
|
if {[string index $str 0] ne "/"} {
|
||||||
|
set str "[$ts dir]/[::sweeper::expand $ts $str]"
|
||||||
|
} else {
|
||||||
|
set str [::sweeper::expand $ts $str]
|
||||||
|
}
|
||||||
|
log " DIREXISTS($str)" 2
|
||||||
|
return [file isdirectory $str]
|
||||||
|
}
|
||||||
|
|
||||||
proc ::sweeper::series {ts flag folder} {
|
proc ::sweeper::series {ts flag folder} {
|
||||||
if {!$folder} { return 0 }
|
if {!$folder} { return 0 }
|
||||||
set dir [$ts dir]
|
set dir [$ts dir]
|
||||||
|
@ -705,6 +755,22 @@ proc ::sweeper::action_delete {ts cmd arg folder} {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc ::sweeper::action_flag {ts cmd arg folder} {
|
||||||
|
log "Flagged [$ts get file] as $arg" 0
|
||||||
|
if {!$::sweeper::dryrun} {
|
||||||
|
$ts setflag $arg
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
proc ::sweeper::action_unflag {ts cmd arg folder} {
|
||||||
|
log "Unflagged [$ts get file] as $arg" 0
|
||||||
|
if {!$::sweeper::dryrun} {
|
||||||
|
$ts unsetflag $arg
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
eval_plugins sweeper
|
eval_plugins sweeper
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
|
@ -186,6 +186,22 @@ var schema = {
|
||||||
negate: true,
|
negate: true,
|
||||||
def: ""
|
def: ""
|
||||||
},
|
},
|
||||||
|
fileexists: {
|
||||||
|
'class': 'all',
|
||||||
|
type: 'string',
|
||||||
|
desc: 'File exists',
|
||||||
|
idesc: "File does not exist",
|
||||||
|
negate: true,
|
||||||
|
def: ""
|
||||||
|
},
|
||||||
|
direxists: {
|
||||||
|
'class': 'all',
|
||||||
|
type: 'string',
|
||||||
|
desc: 'Directory exists',
|
||||||
|
idesc: "Directory does not exist",
|
||||||
|
negate: true,
|
||||||
|
def: ""
|
||||||
|
},
|
||||||
textmatch: {
|
textmatch: {
|
||||||
'class': 'all',
|
'class': 'all',
|
||||||
type: 'textmatch',
|
type: 'textmatch',
|
||||||
|
@ -297,6 +313,18 @@ var schema = {
|
||||||
desc: 'Unlock recordings',
|
desc: 'Unlock recordings',
|
||||||
continues: true
|
continues: true
|
||||||
},
|
},
|
||||||
|
flag: {
|
||||||
|
'class': 'all',
|
||||||
|
argtype: 'string',
|
||||||
|
desc: 'Set recording flag...',
|
||||||
|
continues: true
|
||||||
|
},
|
||||||
|
unflag: {
|
||||||
|
'class': 'all',
|
||||||
|
argtype: 'string',
|
||||||
|
desc: 'Unset recording flag...',
|
||||||
|
continues: true
|
||||||
|
},
|
||||||
'delete': {
|
'delete': {
|
||||||
'class': 'all',
|
'class': 'all',
|
||||||
argtype: 'none',
|
argtype: 'none',
|
||||||
|
|
Loading…
Reference in New Issue