webif/var/mongoose/cgi-bin/browse/rename.jim

46 lines
899 B
Plaintext
Raw Normal View History

#!/mod/bin/jimsh
package require cgi
source /mod/webif/lib/setup
require ts.class
puts "Content-Type: text/html"
puts ""
cgi_input
#cgi_dump
set file [cgi_get renamefile "-"]
if {$file eq "-"} exit
set newfile [string trim [cgi_get rename]]
set dir [file dirname $file]
if {[file isdirectory $file]} {
#puts "Directory."
if {$newfile ne ""} {
set newfile "${dir}/${newfile}"
file rename $file $newfile
}
} elseif {[set ts [ts fetch $file]] != 0} {
#puts "TS file."
foreach attr {title synopsis guidance genre} {
if {[catch {
set new [string trim [cgi_get "rename_$attr"]]
set old [$ts get $attr]
if {[string length $new] > 0 && $new ne $old} {
$ts set$attr $new
}
} msg]} {
puts "$attr: $msg"
}
}
if {"$dir/$newfile.ts" ne "$file"} { ts renamegroup $file $newfile }
} else {
#puts "Normal file."
if {$newfile ne ""} { ts renamegroup $file $newfile }
}