From 1eaff8d5d21ba6359160bda1cc33d43aea311117 Mon Sep 17 00:00:00 2001 From: hummypkg Date: Mon, 9 Jun 2014 22:24:50 +0000 Subject: [PATCH] updates --- CONTROL/control | 4 +- webif/plugin/sweeper/auto.hook | 121 ++++++++++++++++++++----- webif/plugin/sweeper/browse.css | 5 + webif/plugin/sweeper/browse.hook | 2 + webif/plugin/sweeper/browse.js | 4 + webif/plugin/sweeper/diriconset.hook | 4 + webif/plugin/sweeper/edit.jim | 20 ++++ webif/plugin/sweeper/img/icon256.png | Bin 0 -> 19445 bytes webif/plugin/sweeper/img/noicon22.png | Bin 0 -> 1065 bytes webif/plugin/sweeper/menu.hook | 5 + webif/plugin/sweeper/rules_json.jim | 7 ++ webif/plugin/sweeper/schema.js | 19 +++- webif/plugin/sweeper/script.js | 126 +++++++++++++++++++++----- webif/plugin/sweeper/style.css | 6 ++ webif/plugin/sweeper/test.jim | 62 +++++++++++++ webif/plugin/sweeper/toolbar.hook | 3 + 16 files changed, 341 insertions(+), 47 deletions(-) create mode 100644 webif/plugin/sweeper/img/icon256.png create mode 100644 webif/plugin/sweeper/img/noicon22.png create mode 100755 webif/plugin/sweeper/menu.hook create mode 100755 webif/plugin/sweeper/test.jim create mode 100755 webif/plugin/sweeper/toolbar.hook diff --git a/CONTROL/control b/CONTROL/control index 766fc3f..38878f4 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -1,9 +1,9 @@ Package: sweeper Priority: optional Section: misc -Version: 1.0.15 +Version: 1.0.17 Architecture: mipsel Maintainer: af123@hummypkg.org.uk -Depends: webif(>=1.0.14-4) +Depends: webif(>=1.0.14-6) Description: Automatically manage single recording files. [Web Interface. Multi-folder support.] Tags: http://hummy.tv/forum/threads/3843/ diff --git a/webif/plugin/sweeper/auto.hook b/webif/plugin/sweeper/auto.hook index 63d38f9..2859c36 100644 --- a/webif/plugin/sweeper/auto.hook +++ b/webif/plugin/sweeper/auto.hook @@ -1,5 +1,6 @@ set ::sweeper::cf "/mod/etc/sweeper.conf" +set ::sweeper::dryrun 0 proc ::sweeper::unknown {cmd args} { log "Unknown sweeper rule clause '$cmd'" 0 @@ -23,6 +24,8 @@ proc ::sweeper::expand {ts str} { } set timestamp [clock format [$ts get start] -format "%Y%m%d%H%M%S"] + set yyyymmdd [string range $timestamp 0 7] + set hhmm [string range $timestamp 8 11] set map [list \ "%title" [$ts get title] \ @@ -32,10 +35,12 @@ proc ::sweeper::expand {ts str} { "%channel" [$ts get channel_name] \ "%duration" [$ts duration] \ "%timestamp" $timestamp \ + "%yyyymmdd" $yyyymmdd \ + "%hhmm" $hhmm \ ] set ret [string map $map $str] - log " Expanded to \[$ret]" 2 + log " Expanded \[$str] -> \[$ret]" 2 return $ret } @@ -100,6 +105,10 @@ proc ::sweeper::definition {ts def} { return [::sweeper::strcontains [$ts get definition] $def] } +proc ::sweeper::filename {ts str} { + return [::sweeper::strcontains [$ts bfile] $str] +} + proc ::sweeper::title {ts str} { return [::sweeper::strcontains [$ts get title] $str] } @@ -162,35 +171,56 @@ proc ::sweeper::action {ts cmds} { log " ... No such directory $root/$rest" 2 return 1 } - system mkdir_p "$root/$rest" - if {![file isdirectory "$root/$rest"]} { - log "Error creating directory $root/$rest" 1 - return 1 - } else { - log " ... created directory $root/$rest" 2 + if {!$::sweeper::dryrun} { + system mkdir_p "$root/$rest" + if {![file isdirectory "$root/$rest"]} { + log "Error creating $root/$rest" 1 + return 1 + } else { + log " ... created $root/$rest" 2 + } } } log "Moving [$ts get file] to $rest" 0 foreach f [$ts fileset] { log " ....... $f" - file rename $f "$root/$rest/[file tail $f]" - if {"$root/$rest" ni $::sweeper::recalc} { - lappend ::sweeper::recalc "$root/$rest" + if {!$::sweeper::dryrun} { + file rename $f "$root/$rest/[file tail $f]" + if {"$root/$rest" ni $::sweeper::recalc} { + lappend ::sweeper::recalc "$root/$rest" + } } } return 1 } + renamefile { + set rest [system filename [::sweeper::expand $ts $rest]] + set file [$ts get file] + log "Renaming [$ts get file] to $rest" 0 + if {[file exists "[file dirname $file]/$rest.ts"]} { + log "... ERROR Target already exists" 0 + return 0 + } + if {!$::sweeper::dryrun} { + ts renamegroup $file $rest + } + return 0 + } lock { if {![$ts flag Locked]} { log "Locked [$ts get file]" 0 - $ts lock + if {!$::sweeper::dryrun} { + $ts lock + } } return 0 } unlock { if {[$ts flag Locked]} { log "Unlocked [$ts get file]" 0 - $ts unlock + if {!$::sweeper::dryrun} { + $ts unlock + } } return 0 } @@ -305,15 +335,19 @@ proc ::sweeper::folder_action {ts cmds} { log " ... No such directory $root/$rest" 2 return 1 } - system mkdir_p "$root/$rest" - if {![file isdirectory "$root/$rest"]} { - log "Error creating directory $root/$rest" 1 - return 1 - } else { - log " ... created directory $root/$rest" 2 + if {!$::sweeper::dryrun} { + system mkdir_p "$root/$rest" + if {![file isdirectory "$root/$rest"]} { + log "Error creating $root/$rest" 1 + return 1 + } else { + log " ... created $root/$rest" 2 + } } } - ::sweeper:folder_merge $folder "$root/$rest" + if {!$::sweeper::dryrun} { + ::sweeper:folder_merge $folder "$root/$rest" + } return 1 } fileundercreate - @@ -330,12 +364,33 @@ proc ::sweeper::folder_action {ts cmds} { if {$cmd ne "fileundercreate"} { return 1 } set target "$root/$rest/$lfolder" log "Creating $target" 0 - system mkdir_p $target + if {!$::sweeper::dryrun} { + system mkdir_p $target + } + } + if {!$::sweeper::dryrun} { + ::sweeper:folder_merge $folder $target } - ::sweeper:folder_merge $folder $target return 1 } + renamefile { + ::sweeper::folder_apply $folder [lambda {ts} { + set rest [system filename \ + [::sweeper::expand $ts $rest]] + set file [$ts get file] + log "Renaming [$ts get file] to $rest" 0 + if {[file exists "[file dirname $file]/$rest.ts"]} { + log "... ERROR Target already exists" 0 + return 0 + } + if {!$::sweeper::dryrun} { + ts renamegroup $file $rest + } + } + return 0 + } lock { + if {$::sweeper::dryrun} { return 0 } ::sweeper::folder_apply $folder [lambda {ts} { if {![$ts flag Locked]} { log "Locked [$ts get file]" 0 @@ -345,6 +400,7 @@ proc ::sweeper::folder_action {ts cmds} { return 0 } unlock { + if {$::sweeper::dryrun} { return 0 } ::sweeper::folder_apply $folder [lambda {ts} { if {[$ts flag Locked]} { log "Unlocked [$ts get file]" 0 @@ -373,12 +429,19 @@ proc ::sweeper::runrule {ts rule} { while {[llength $rule] > 1} { set rule [lassign $rule cmd arg] log " $cmd\($arg)" 2 + if {[string index $cmd 0] eq "!"} { + set negate 1 + set cmd [string range $cmd 1 end] + } else { + set negate 0 + } if {$folder && [exists -proc ::sweeper::folder_$cmd]} { set ret [::sweeper::folder_$cmd $ts $arg] } else { set ret [::sweeper::$cmd $ts $arg] } if {$cmd eq "action"} { return $ret } + if {$negate} { set ret $(!$ret) } if {!$ret} { log " Nomatch" 2 break @@ -454,11 +517,27 @@ proc ::sweeper::apply {dir cf} { log "==== folder $entry ====" 2 log "" 2 + if {[file exists "$entry/.nosweep"]} { + log "No-sweep folder." 2 + continue + } + if {![file exists "$entry/.series"]} { log "Not series folder." 2 continue } + # Check if the .series entry is a real one versus one created + # by ts resetnew + set fd [open "$entry/.series"] + set bytes [read $fd] + close $fd + set sbytes [unpack $bytes -uintle 160 32] + if {$sbytes == 0} { + log ".series file was auto-created, skipping folder." + continue + } + set ts 0 foreach de [readdir -nocomplain $entry] { set dentry "$entry/$de" diff --git a/webif/plugin/sweeper/browse.css b/webif/plugin/sweeper/browse.css index f74874c..d351cc6 100644 --- a/webif/plugin/sweeper/browse.css +++ b/webif/plugin/sweeper/browse.css @@ -4,3 +4,8 @@ background-image: url(/plugin/sweeper/img/icon16.png); } +.contextMenu li.nosweep a +{ + background-image: url(/plugin/sweeper/img/noicon22.png); +} + diff --git a/webif/plugin/sweeper/browse.hook b/webif/plugin/sweeper/browse.hook index 055e92b..cf63c35 100644 --- a/webif/plugin/sweeper/browse.hook +++ b/webif/plugin/sweeper/browse.hook @@ -3,3 +3,5 @@ jscss /plugin/sweeper/browse.js /plugin/sweeper/browse.css lappend plugins(dmenu) {sweeper {desc "Sweeper Rules"}} +lappend plugins(dmenu) {nosweep {desc "Toggle no-sweep flag"}} + diff --git a/webif/plugin/sweeper/browse.js b/webif/plugin/sweeper/browse.js index 80f1288..ec73802 100644 --- a/webif/plugin/sweeper/browse.js +++ b/webif/plugin/sweeper/browse.js @@ -3,3 +3,7 @@ plugins.dmenu.sweeper = function(dir) { window.location = '/plugin/sweeper/edit.jim?dir=' + dir; }; +plugins.dmenu.nosweep = function(dir, iconset, results, el) { + flagdir(dir, 'nosweep', iconset, results, el); +}; + diff --git a/webif/plugin/sweeper/diriconset.hook b/webif/plugin/sweeper/diriconset.hook index a839f93..426cae9 100644 --- a/webif/plugin/sweeper/diriconset.hook +++ b/webif/plugin/sweeper/diriconset.hook @@ -3,3 +3,7 @@ if {$dir eq [system mediaroot] || [file exists "$dir/.sweeper"]} { lappend icons [_addicon "/plugin/sweeper/img/icon22.png" "Sweeper Rules"] } +if {[file exists "$dir/.nosweep"]} { + lappend icons [_addicon "/plugin/sweeper/img/noicon22.png" "No-sweep"] +} + diff --git a/webif/plugin/sweeper/edit.jim b/webif/plugin/sweeper/edit.jim index 061fed0..3b87349 100755 --- a/webif/plugin/sweeper/edit.jim +++ b/webif/plugin/sweeper/edit.jim @@ -35,6 +35,7 @@ puts { +
@@ -141,12 +142,31 @@ Add pre-defined ruleset: + + + +