From 8dad54251aeb9ede55bbc775c1cf7a9d84402762 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Tue, 29 Jul 2008 16:54:30 +0000 Subject: libs/lpk: Several fixes in CLI -> Machine bindings --- libs/lpk/luasrc/lpk.lua | 2 +- libs/lpk/luasrc/lpk/core.lua | 11 ++++++++--- libs/lpk/luasrc/lpk/core/download.lua | 1 + libs/lpk/luasrc/lpk/core/install.lua | 16 ++++++++++++++++ libs/lpk/luasrc/lpk/core/retreive.lua | 7 +++++++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/libs/lpk/luasrc/lpk.lua b/libs/lpk/luasrc/lpk.lua index 3b42a367e..7117c75f9 100644 --- a/libs/lpk/luasrc/lpk.lua +++ b/libs/lpk/luasrc/lpk.lua @@ -31,7 +31,7 @@ else os.exit(task.register.error or 1) end else - luci.util.perror(error .. "\n") + luci.util.perror((error or "Unknown Error") .. "\n") luci.lpk.util.splash() os.exit(1) end diff --git a/libs/lpk/luasrc/lpk/core.lua b/libs/lpk/luasrc/lpk/core.lua index bef5651c6..97de4fa92 100644 --- a/libs/lpk/luasrc/lpk/core.lua +++ b/libs/lpk/luasrc/lpk/core.lua @@ -22,6 +22,10 @@ function Task.rollback(self) end local state = table.remove(self.done) + if not state.rollback then + return true + end + local ret, err = pcall(state.rollback, state, self.register) if ret then @@ -33,7 +37,7 @@ end function Task.step(self) local state = table.remove(self.work) - local ret, next = pcall(state.process, state, self.register) + local ret, next = pcall(state.process, self.register) if ret then if next then @@ -42,7 +46,8 @@ function Task.step(self) table.insert(self.work, state) table.insert(self.work, nstate) else - self.register.error = "Unknown state: " .. next + self.register.error = 2 + self.register.errstr = "Unknown state: " .. next return false end else @@ -98,5 +103,5 @@ function Machine.task(self, name, ...) local register = {} - return start:entry(register) and Task(self, register, start) + return start.entry(register, ...) and Task(self, register, start) end diff --git a/libs/lpk/luasrc/lpk/core/download.lua b/libs/lpk/luasrc/lpk/core/download.lua index e69de29bb..7b306479f 100644 --- a/libs/lpk/luasrc/lpk/core/download.lua +++ b/libs/lpk/luasrc/lpk/core/download.lua @@ -0,0 +1 @@ +module("luci.lpk.core.download", package.seeall) diff --git a/libs/lpk/luasrc/lpk/core/install.lua b/libs/lpk/luasrc/lpk/core/install.lua index e69de29bb..abf612b29 100644 --- a/libs/lpk/luasrc/lpk/core/install.lua +++ b/libs/lpk/luasrc/lpk/core/install.lua @@ -0,0 +1,16 @@ +module("luci.lpk.core.install", package.seeall) + +function entry(register, ...) + print("Requested install of " .. table.concat(arg, ", ")) + return true +end + +function process(register) + register.sometext = "Test" + if not register.retreived then + print("Step down to retreive") + return "retreive" + else + print("Coming up again") + end +end \ No newline at end of file diff --git a/libs/lpk/luasrc/lpk/core/retreive.lua b/libs/lpk/luasrc/lpk/core/retreive.lua index e69de29bb..5ad63aa93 100644 --- a/libs/lpk/luasrc/lpk/core/retreive.lua +++ b/libs/lpk/luasrc/lpk/core/retreive.lua @@ -0,0 +1,7 @@ +module("luci.lpk.core.retreive", package.seeall) + +function process(register) + print "Now in retreive" + print (register.sometext) + register.retreived = true +end \ No newline at end of file -- cgit v1.2.3