libs/lpk: Several fixes in CLI -> Machine bindings
authorSteven Barth <steven@midlink.org>
Tue, 29 Jul 2008 16:54:30 +0000 (16:54 +0000)
committerSteven Barth <steven@midlink.org>
Tue, 29 Jul 2008 16:54:30 +0000 (16:54 +0000)
libs/lpk/luasrc/lpk.lua
libs/lpk/luasrc/lpk/core.lua
libs/lpk/luasrc/lpk/core/download.lua
libs/lpk/luasrc/lpk/core/install.lua
libs/lpk/luasrc/lpk/core/retreive.lua

index 3b42a367ede5b96184bf04bbf67a2f1397e3d1fa..7117c75f9c0a52617e7ab3b35f6faa4b6fd87e28 100644 (file)
@@ -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             
index bef5651c6ae6df708bcc52344441965d404afaf9..97de4fa92eb32bd53baeaf410eab3f8e047d9fb3 100644 (file)
@@ -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 
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..7b306479fd49c16e9275c13217388ad38baa2728 100644 (file)
@@ -0,0 +1 @@
+module("luci.lpk.core.download", package.seeall)
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..abf612b2956cb638207018a04c4f3742f550a397 100644 (file)
@@ -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
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..5ad63aa937f93332a598e94d1f2117fa9fe2e610 100644 (file)
@@ -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