Author: titmuss
Date: Wed Apr 23 06:21:18 2008
New Revision: 2322
URL: http://svn.slimdevices.com?rev=2322&root=Jive&view=rev
Log:
Bug: N/A
Description:
Move Play Macros into Extra's.
Allow macros to start automatically when SqueezePlay starts, and update the
Macros file. This will allow automated testing.
Added DataDumper from Lua wiki, this does a better job at serialization.
Added:
7.1/trunk/squeezeplay/src/squeezeplay/share/jive/utils/dumper.lua
Modified:
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/MacroPlay/MacroPlayApplet.lua
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/MacroPlay/MacroPlayMeta.lua
Modified:
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/MacroPlay/MacroPlayApplet.lua
URL:
http://svn.slimdevices.com/7.1/trunk/squeezeplay/src/squeezeplay/share/applets/MacroPlay/MacroPlayApplet.lua?rev=2322&root=Jive&r1=2321&r2=2322&view=diff
==============================================================================
---
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/MacroPlay/MacroPlayApplet.lua
(original)
+++
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/MacroPlay/MacroPlayApplet.lua
Wed Apr 23 06:21:18 2008
@@ -13,14 +13,16 @@
-- stuff we use
-local getfenv, loadfile, ipairs, package, pairs, require, setfenv,
setmetatable, tostring = getfenv, loadfile, ipairs, package, pairs, require,
setfenv, setmetatable, tostring
+local assert, getfenv, loadfile, ipairs, package, pairs, require, setfenv,
setmetatable, tostring = assert, getfenv, loadfile, ipairs, package, pairs,
require, setfenv, setmetatable, tostring
local oo = require("loop.simple")
+local io = require("io")
+local os = require("os")
local lfs = require("lfs")
local math = require("math")
local string = require("string")
local table = require("jive.utils.table")
-
+local dumper = require("jive.utils.dumper")
local Applet = require("jive.Applet")
local Event = require("jive.ui.Event")
@@ -49,9 +51,11 @@
local task = false
local timer = false
local macro = false
+local macrodir = false
function init(self)
+ self.config = {}
self:loadconfig()
end
@@ -79,17 +83,20 @@
function loadconfig(self)
-- Load macro configuration
- local f, err = loadmacro("Macros.lua")
+ local f, dirorerr = loadmacro("Macros.lua")
if f then
- -- Defines self.macros
- f()
+ self.configFile = dirorerr .. "Macros.lua"
+ self.config = f()
else
- log:warn("Error loading Macros: ", err)
- end
-
--- if self.autostart then
--- self:autoplay()
--- end
+ log:warn("Error loading Macros: ", dirorerr)
+ end
+end
+
+
+function saveconfig(self)
+ local file = assert(io.open(self.configFile, "w"))
+ file:write(dumper.dump(self.config, nil, false))
+ file:close()
end
@@ -105,12 +112,12 @@
window:addWidget(menu)
-- Macro menus
- if self.autostart then
+ if self.config.autostart then
local item = {
text = self:string("MACRO_PLAY_AUTOSTART"),
sound = "WINDOWSHOW",
callback = function(event, menuItem)
- self.auto = nil
+ self.config.auto = true
self:autoplay()
end,
focusGained = function()
@@ -121,7 +128,7 @@
menu:addItem(item)
end
- for k, v in pairs(self.macros) do
+ for k, v in pairs(self.config.macros) do
local item = {
text = self:string(v.name),
sound = "WINDOWSHOW",
@@ -148,43 +155,48 @@
end
+-- play the next autostart macro
function autoplay(self)
- if self.auto == false then
+ local config = self.config
+
+ if config.auto == false then
return
end
- if self.auto == nil then
- self.auto = 1
- end
-
- if self.auto > #self.autostart then
+ if config.auto == true then
+ config.auto = 1
+ end
+
+ if config.auto > #config.autostart then
log:info("Macro Autoplay FINISHED")
- self.auto = false
-
- return
- end
-
- local macro = self.macros[self.autostart[self.auto]]
- self.auto = self.auto + 1
-
- self:play(macro)
-end
+ config.auto = false
+
+ else
+ local macro = config.macros[config.autostart[config.auto]]
+ config.auto = config.auto + 1
+
+ self:play(macro)
+ end
+
+ self:saveconfig()
+end
+
-- play the macro
-function play(self, entry)
+function play(self, _macro)
task = Task("MacroPlay", self,
function()
- local f, dir = loadmacro(entry.file)
+ local f, dirorerr = loadmacro(_macro.file)
if f then
- macro = entry
- macro.dir = dir
+ macro = _macro
+ macrodir = dirorerr
log:info("Macro starting: ", macro.file)
f()
self:autoplay()
else
- log:warn("Macro error: ", err)
+ log:warn("Macro error: ", dirorerr)
end
end)
task:addTask()
@@ -267,8 +279,7 @@
local screen = Surface:newRGB(w, h)
window:draw(screen, LAYER_ALL)
-
- local reffile = macro.dir .. file .. ".bmp"
+ local reffile = macrodir .. file .. ".bmp"
if lfs.attributes(reffile, "mode") == "file" then
-- verify screenshot
log:debug("Loading reference screenshot " .. reffile)
@@ -278,11 +289,11 @@
if match < limit then
-- failure
- log:warn("Macro Screenshot FAILED " .. file .. "
match=" .. match .. " limt=" .. limit)
- failfile = macro.dir .. file .. "_fail.bmp"
+ log:warn("Macro Screenshot " .. file .. " FAILED
match=" .. match .. " limt=" .. limit)
+ failfile = macrodir .. file .. "_fail.bmp"
screen:saveBMP(failfile)
else
- log:info("Macro Screenshot PASSED " .. file)
+ log:info("Macro Screenshot " .. file .. " PASSED")
pass = true
end
else
@@ -298,12 +309,16 @@
function macroPass(msg)
log:warn("Macro PASS ", macro.name, ": ", msg)
- macro.passed = Framework:getTicks()
+ macro.passed = os.date()
+ macro.failed = nil
end
function macroFail(msg)
log:warn("Macro FAIL ", macro.name, ": ", msg)
+
+ macro.passed = nil
+ macro.failed = os.date()
end
Modified:
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/MacroPlay/MacroPlayMeta.lua
URL:
http://svn.slimdevices.com/7.1/trunk/squeezeplay/src/squeezeplay/share/applets/MacroPlay/MacroPlayMeta.lua?rev=2322&root=Jive&r1=2321&r2=2322&view=diff
==============================================================================
---
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/MacroPlay/MacroPlayMeta.lua
(original)
+++
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/MacroPlay/MacroPlayMeta.lua
Wed Apr 23 06:21:18 2008
@@ -20,6 +20,8 @@
local AppletMeta = require("jive.AppletMeta")
+local Timer = require("jive.ui.Timer")
+
local appletManager = appletManager
local jiveMain = jiveMain
@@ -38,7 +40,22 @@
function registerApplet(meta)
+ local applet = appletManager:loadApplet('MacroPlay')
+
+ if not applet.config.macros then
+ appletManager:freeApplet('MacroPlay')
+ return
+ end
+
+ if applet.config.auto then
+ Timer(30000,
+ function()
+ applet:autoplay()
+ end,
+ true):start()
+ end
+
-- menu item to start
- jiveMain:addItem(meta:menuItem('macroPlay', 'advancedSettings',
'MACRO_PLAY', function(applet, ...) applet:settingsShow(...) end))
+ jiveMain:addItem(meta:menuItem('macroPlay', 'extras', 'MACRO_PLAY',
function(applet, ...) applet:settingsShow(...) end))
end
Added: 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/utils/dumper.lua
URL:
http://svn.slimdevices.com/7.1/trunk/squeezeplay/src/squeezeplay/share/jive/utils/dumper.lua?rev=2322&root=Jive&view=auto
==============================================================================
--- 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/utils/dumper.lua (added)
+++ 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/utils/dumper.lua Wed Apr
23 06:21:18 2008
@@ -1,0 +1,239 @@
+--[[ DataDumper.lua
+Copyright (c) 2007 Olivetti-Engineering SA
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+]]
+
+-- Local variables for speed optimization
+local type, tostring, pairs, ipairs, pcall =
+ type, tostring, pairs, ipairs, pcall
+local setmetatable, getmetatable, setfenv, getfenv =
+ setmetatable, getmetatable, setfenv, getfenv
+local string_format, string_dump, string_rep =
+ string.format, string.dump, string.rep
+local table_concat, table_sort, table_concat, table_insert =
+ table.concat, table.sort, table.concat, table.insert
+local debug_getupvalue, debug_setupvalue =
+ debug.getupvalue, debug.setupvalue
+local _G = _G
+
+
+module(...)
+
+
+local dumplua_closure = [[
+local closures = {}
+local function closure(t)
+ closures[#closures+1] = t
+ t[1] = assert(loadstring(t[1]))
+ return t[1]
+end
+
+for _,t in pairs(closures) do
+ for i = 2,#t do
+ debug_setupvalue(t[1], i-1, t[i])
+ end
+end
+]]
+
+local lua_reserved_keywords = {
+ 'and', 'break', 'do', 'else', 'elseif', 'end', 'false', 'for',
+ 'function', 'if', 'in', 'local', 'nil', 'not', 'or', 'repeat',
+ 'return', 'then', 'true', 'until', 'while' }
+
+local function keys(t)
+ local res = {}
+ local oktypes = { stringstring = true, numbernumber = true }
+ local function cmpfct(a,b)
+ if oktypes[type(a)..type(b)] then
+ return a < b
+ else
+ return type(a) < type(b)
+ end
+ end
+ for k in pairs(t) do
+ res[#res+1] = k
+ end
+ table_sort(res, cmpfct)
+ return res
+end
+
+local c_functions = {}
+for _,lib in pairs{'_G', 'string', 'table', 'math',
+ 'io', 'os', 'coroutine', 'package', 'debug'} do
+ local t = _G[lib] or {}
+ lib = lib .. "."
+ if lib == "_G." then lib = "" end
+ for k,v in pairs(t) do
+ if type(v) == 'function' and not pcall(string_dump, v) then
+ c_functions[v] = lib..k
+ end
+ end
+end
+
+function dump(value, varname, fastmode, ident)
+ local defined, dumplua = {}
+ local keycache, strvalcache, out, closure_cnt = {}, {}, {}, 0
+ setmetatable(strvalcache, {__index = function(t,value)
+ local res = string_format('%q', value)
+ t[value] = res
+ return res
+ end})
+ local fcts = {
+ string = function(value) return strvalcache[value] end,
+ number = function(value) return value end,
+ boolean = function(value) return tostring(value) end,
+ ['nil'] = function(value) return 'nil' end,
+ ['function'] = function(value)
+ return string_format("loadstring(%q)", string_dump(value))
+ end,
+ userdata = function() error("Cannot dump userdata") end,
+ thread = function() error("Cannot dump threads") end,
+ }
+ local function test_defined(value, path)
+ if defined[value] then
+ if path:match("^getmetatable.*%)$") then
+ out[#out+1] = string_format("s%s, %s)\n", path:sub(2,-2),
defined[value])
+ else
+ out[#out+1] = path .. " = " .. defined[value] .. "\n"
+ end
+ return true
+ end
+ defined[value] = path
+ end
+ local function make_key(t, key)
+ local s
+ if type(key) == 'string' and key:match('^[_%a][_%w]*$') then
+ s = key .. "="
+ else
+ s = "[" .. dumplua(key, 0) .. "]="
+ end
+ t[key] = s
+ return s
+ end
+ for _,k in ipairs(lua_reserved_keywords) do
+ keycache[k] = '["'..k..'"] = '
+ end
+ if fastmode then
+ fcts.table = function (value)
+ -- Table value
+ local numidx = 1
+ out[#out+1] = "{"
+ for key,val in pairs(value) do
+ if key == numidx then
+ numidx = numidx + 1
+ else
+ out[#out+1] = keycache[key]
+ end
+ local str = dumplua(val)
+ out[#out+1] = str..","
+ end
+ out[#out+1] = "}"
+ return ""
+ end
+ else
+ fcts.table = function (value, ident, path)
+ if test_defined(value, path) then return "nil" end
+ -- Table value
+ local sep, str, numidx, totallen = " ", {}, 1, 0
+ local meta, metastr = getmetatable(value)
+ if meta then
+ ident = ident + 1
+ metastr = dumplua(meta, ident, "getmetatable("..path..")")
+ totallen = totallen + #metastr + 16
+ end
+ for _,key in pairs(keys(value)) do
+ local val = value[key]
+ local s = ""
+ local subpath = path
+ if key == numidx then
+ subpath = subpath .. "[" .. numidx .. "]"
+ numidx = numidx + 1
+ else
+ s = keycache[key]
+ if not s:match "^%[" then subpath = subpath .. "." end
+ subpath = subpath .. s:gsub("%s*=%s*$","")
+ end
+ s = s .. dumplua(val, ident+1, subpath)
+ str[#str+1] = s
+ totallen = totallen + #s + 2
+ end
+ if totallen > 80 then
+ sep = "\n" .. string_rep(" ", ident+1)
+ end
+ str = "{"..sep..table_concat(str, ","..sep).." "..sep:sub(1,-3).."}"
+ if meta then
+ sep = sep:sub(1,-3)
+ return "setmetatable("..sep..str..","..sep..metastr..sep:sub(1,-3)..")"
+ end
+ return str
+ end
+ fcts['function'] = function (value, ident, path)
+ if test_defined(value, path) then return "nil" end
+ if c_functions[value] then
+ return c_functions[value]
+ elseif debug == nil or debug_getupvalue(value, 1) == nil then
+ return string_format("loadstring(%q)", string_dump(value))
+ end
+ closure_cnt = closure_cnt + 1
+ local res = {string_dump(value)}
+ for i = 1,math.huge do
+ local name, v = debug_getupvalue(value,i)
+ if name == nil then break end
+ res[i+1] = v
+ end
+ return "closure " .. dumplua(res, ident, "closures["..closure_cnt.."]")
+ end
+ end
+ function dumplua(value, ident, path)
+ return fcts[type(value)](value, ident, path)
+ end
+ if varname == nil then
+ varname = "return "
+ elseif varname:match("^[%a_][%w_]*$") then
+ varname = varname .. " = "
+ end
+ if fastmode then
+ setmetatable(keycache, {__index = make_key })
+ out[1] = varname
+ table_insert(out,dumplua(value, 0))
+ return table_concat(out)
+ else
+ setmetatable(keycache, {__index = make_key })
+ local items = {}
+ for i=1,10 do items[i] = '' end
+ items[3] = dumplua(value, ident or 0, "t")
+ if closure_cnt > 0 then
+ items[1], items[6] = dumplua_closure:match("(.*\n)\n(.*)")
+ out[#out+1] = ""
+ end
+ if #out > 0 then
+ items[2], items[4] = "local t = ", "\n"
+ items[5] = table_concat(out)
+ items[7] = varname .. "t"
+ else
+ items[2] = varname
+ end
+ return table_concat(items)
+ end
+end
+
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins