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 {
+
There are no rules currently defined for this folder.
diff --git a/webif/plugin/sweeper/img/icon256.png b/webif/plugin/sweeper/img/icon256.png
new file mode 100644
index 0000000..b407c33
Binary files /dev/null and b/webif/plugin/sweeper/img/icon256.png differ
diff --git a/webif/plugin/sweeper/img/noicon22.png b/webif/plugin/sweeper/img/noicon22.png
new file mode 100644
index 0000000..8f906e7
Binary files /dev/null and b/webif/plugin/sweeper/img/noicon22.png differ
diff --git a/webif/plugin/sweeper/menu.hook b/webif/plugin/sweeper/menu.hook
new file mode 100755
index 0000000..57c0ec5
--- /dev/null
+++ b/webif/plugin/sweeper/menu.hook
@@ -0,0 +1,5 @@
+menuitem \
+ "Sweeper" \
+ "/plugin/sweeper/img/icon256.png" \
+ "/plugin/sweeper/edit.jim"
+
diff --git a/webif/plugin/sweeper/rules_json.jim b/webif/plugin/sweeper/rules_json.jim
index ff2d486..bddd378 100755
--- a/webif/plugin/sweeper/rules_json.jim
+++ b/webif/plugin/sweeper/rules_json.jim
@@ -76,12 +76,19 @@ proc rule {id rule} {
set lockfound -1
while {[llength $rule] > 1} {
set rule [lassign $rule cmd arg]
+ if {[string index $cmd 0] eq "!"} {
+ set negate 1
+ set cmd [string range $cmd 1 end]
+ } else {
+ set negate 0
+ }
if {$cmd eq "action"} break
if {$cmd eq "lock"} { set lockfound $arg }
if {$c} { add_json ",\n" }
incr c
add_json " {\n"
+ add_json " \"negate\": $negate,\n"
add_json " \"cmd\": \"[quot $cmd]\",\n"
add_json " \"arg\": \"[quot $arg]\"\n"
add_json " }"
diff --git a/webif/plugin/sweeper/schema.js b/webif/plugin/sweeper/schema.js
index c57a65b..2a99b1c 100644
--- a/webif/plugin/sweeper/schema.js
+++ b/webif/plugin/sweeper/schema.js
@@ -46,18 +46,21 @@ var schema = {
'class': 'all',
type: 'substr',
desc: 'Recording Title contains',
+ idesc: 'Recording Title does not contain',
def: 'Enter text here...'
},
synopsis: {
'class': 'all',
type: 'substr',
desc: 'Synopsis contains',
+ idesc: 'Synopsis does not contain',
def: 'Enter text here...'
},
guidance: {
'class': 'all',
type: 'substr',
desc: 'Guidance Text contains',
+ idesc: 'Guidance Text does not contain',
def: 'Enter text here...'
},
genre: {
@@ -91,6 +94,7 @@ var schema = {
'class': 'all',
type: 'select',
desc: 'Recording Flagged as',
+ idesc: 'Recording not Flagged as',
select: {
Locked: 'Locked',
New: 'New',
@@ -113,11 +117,18 @@ var schema = {
def: 1,
deprecated: true
},
+ filename: {
+ 'class': 'all',
+ type: 'substr',
+ desc: 'Filename contains',
+ def: 'Enter text here...'
+ },
fflag: {
'class': 'folder',
type: 'string',
desc: 'Folder flagged as',
- def: 'noflatten'
+ idesc: 'Folder not flagged as',
+ def: 'nosweep'
}
},
action: {
@@ -169,6 +180,12 @@ var schema = {
desc: 'Merge into or create folder of ' +
'same name found under...',
continues: false
+ },
+ renamefile: {
+ 'class': 'all',
+ argtype: 'string',
+ desc: 'Rename recording files to...',
+ continue: true
}
}
};
diff --git a/webif/plugin/sweeper/script.js b/webif/plugin/sweeper/script.js
index 47f585a..81b742c 100644
--- a/webif/plugin/sweeper/script.js
+++ b/webif/plugin/sweeper/script.js
@@ -101,11 +101,14 @@ function ruleconf(rule)
rule.find('tr.clause').each(function(i) {
cmd = $(this).find('th.cmd').attr('cmd');
+ negate = $(this).find('th.cmd').attr('negate');
c = schema.criterion[cmd];
val = $.trim($(this).find('td.val').html());
if (getters[c.type])
val = getters[c.type](cmd, val);
+ if (negate == '1')
+ s += '!';
s += cmd + ' ' + quot(val) + ' ';
});
@@ -156,14 +159,32 @@ function rulerefresh(rule)
}
}
+function critdesc(cmd, negate)
+{
+ var c = schema.criterion[cmd];
+ if (!c)
+ return 'Unknown (' + cmd + ')';
+ if (negate == '1' && c.idesc)
+ return c.idesc;
+ else if (negate == '1')
+ return c.desc + ' is not';
+ else
+ return c.desc;
+}
+
function criterion(data)
{
var c = schema.criterion[data.cmd];
var s;
+ if (!c)
+ {
+ alert('Unknown Criterion (' + data.cmd + ')');
+ return;
+ }
s = '
And: | ' +
- '' +
- c.desc + ' | ';
+ ' | ' +
+ critdesc(data.cmd, data.negate) + ' | ';
if (setters[c.type])
s += setters[c.type](data.cmd, data.arg);
@@ -185,6 +206,12 @@ function action(data)
var c = schema.action[data.cmd];
var s;
+ if (!c)
+ {
+ alert('Unknown action - ' + data.cmd);
+ return '';
+ }
+
if (c.argtype == 'folder' && !data.arg)
data.arg = mroot;
@@ -252,9 +279,6 @@ function addrule(id, data)
$('#ruleset').append(rule);
-// rule.find('button.addcriterion')
-// .button({icons: { primary: "ui-icon-plus"}});
-
rulerefresh(rule);
return rule;
@@ -519,6 +543,29 @@ $('#b_show').button({icons: {primary: "ui-icon-clipboard"}})
});
});
+$('#b_test').button({icons: {primary: "ui-icon-check"}})
+ .on('click', function(e) {
+ e.preventDefault();
+ $('#testresults_inner').empty()
+ .html(' Running rules... Please wait...');
+ $('#testresults').dialog({
+ height: '600', width: '800',
+ draggable: true, resizable: true,
+ autoOpen: true,
+ buttons: {
+ "Close": function() {
+ $(this).dialog('close');
+ }
+ }
+ });
+ $.post('test.jim', {
+ dir: $('span.dir').text(),
+ data: conffile()
+ }, function(data) {
+ $('#testresults_inner').text(data);
+ });
+});
+
$('#b_raw').button({icons: {primary: "ui-icon-gear"}})
.on('click', function(e) {
$('#ruleset div.raw').toggle('slow');
@@ -552,6 +599,56 @@ $('#macros').on('click', '#b_macro', function(e) {
changed(0);
+function addcriterion(rule)
+{
+ var type = rule.attr('type');
+
+ if (type == 'folder')
+ options = select_folder_criteria;
+ else
+ options = select_file_criteria;
+
+ // Populate select box and reset form.
+ $('#newcondition_cmd').empty();
+ $.each(options, function(k, v) {
+ $('#newcondition_cmd').append(
+ $('').attr('value', k).html(v)
+ );
+ });
+ $('#newcondition_negate').prop('checked', false);
+
+ $('#newcondition').dialog({
+ height: 'auto', width: 'auto',
+ draggable: false, resizable: false,
+ autoOpen: true,
+ position: {
+ my: 'bottom left',
+ at: 'top right',
+ of: rule
+ },
+ buttons: {
+ "Add Condition": function() {
+ $(this).dialog('close');
+ var id = rule.attr('id');
+ var val = $('#newcondition_cmd').val();
+ var negate = $('#newcondition_negate')
+ .prop('checked') ? '1' : '0';
+ rule.find('table.criteria tbody')
+ .append(criterion({
+ cmd: val,
+ negate: negate,
+ arg: schema.criterion[val].def
+ }));
+ changed(1);
+ rulerefresh(rule);
+ },
+ "Cancel": function() {
+ $(this).dialog('close');
+ }
+ }
+ });
+}
+
$('#ruleset')
.on('click', 'a.editclause', function(e) {
e.preventDefault();
@@ -559,24 +656,7 @@ $('#ruleset')
})
.on('click', 'a.addcriterion', function(e) {
e.preventDefault();
- var rule = $(this).closest('div.rule');
- var type = rule.attr('type');
-
- if (type == 'folder')
- options = select_folder_criteria;
- else
- options = select_file_criteria;
- edit_select(rule, 'Add new condition',
- options, '', function(rule, val) {
- var id = rule.attr('id');
- rule.find('table.criteria tbody')
- .append(criterion({
- cmd: val,
- arg: schema.criterion[val].def
- }));
- changed(1);
- rulerefresh(rule);
- });
+ addcriterion($(this).closest('div.rule'));
})
.on('click', 'a.editcomment', function(e) {
e.preventDefault();
diff --git a/webif/plugin/sweeper/style.css b/webif/plugin/sweeper/style.css
index ffbc131..82d777a 100644
--- a/webif/plugin/sweeper/style.css
+++ b/webif/plugin/sweeper/style.css
@@ -148,3 +148,9 @@ tr.blank td
line-height: 7px;
}
+#testresults_inner
+{
+ overflow: auto;
+ white-space: pre;
+}
+
diff --git a/webif/plugin/sweeper/test.jim b/webif/plugin/sweeper/test.jim
new file mode 100755
index 0000000..9e26b21
--- /dev/null
+++ b/webif/plugin/sweeper/test.jim
@@ -0,0 +1,62 @@
+#!/mod/bin/jimsh
+
+package require cgi
+source /mod/webif/lib/setup
+require lock system.class ts.class tdelete pretty_size browse.class \
+ safe_delete settings.class plugin
+
+httpheader
+
+set dir [cgi_get dir ""]
+set root [system mediaroot]
+
+set cf "/tmp/sweepertest.cf"
+
+set data [string map {
+ & &
+ < <
+ > >
+} [cgi_get data "-"]]
+
+if {$data eq "-" || $data eq ""} {
+ puts "No data sent!"
+ exit
+}
+
+if {[catch {set fp [open $cf w]} msg]} {
+ puts "Error, $msg"
+ exit
+}
+
+$fp puts -nonewline $data
+close $fp
+
+proc log {msg {level 1}} {
+ puts $msg
+}
+
+proc elapsed {start} {
+ return $(([clock milliseconds] - $start) / 1000.0)
+}
+
+proc startclock {} {
+ set ::startclock_s [clock milliseconds]
+}
+
+proc endclock {size} {
+ set el [elapsed $::startclock_s]
+ set rate $($size / $el)
+ return "[pretty_size $size] in $el seconds - [pretty_size $rate]/s"
+}
+
+proc register {args} {}
+
+set root [system mediaroot]
+
+source auto.hook
+
+set ::sweeper::dryrun 1
+::sweeper::apply $dir $cf
+
+file delete $cf
+
diff --git a/webif/plugin/sweeper/toolbar.hook b/webif/plugin/sweeper/toolbar.hook
new file mode 100755
index 0000000..a98fe64
--- /dev/null
+++ b/webif/plugin/sweeper/toolbar.hook
@@ -0,0 +1,3 @@
+
+tb "/plugin/sweeper/img/icon256.png" "Sweeper" "/plugin/sweeper/edit.jim"
+
|
---|