]> git.e2factory.org Git - e2factory.git/commitdiff
Use console module everywhere
authorTobias Ulmer <tu@emlix.com>
Wed, 27 Nov 2013 19:00:34 +0000 (20:00 +0100)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:41:17 +0000 (15:41 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2lib.lua
generic/e2option.lua
generic/plugin.lua
global/e2.lua
local/e2-build.lua
local/e2-dlist.lua
local/e2-dsort.lua
local/e2-help.lua
local/e2-ls-project.lua
local/e2-playground.lua

index 97243b440329e05fe18342b7f275aa03ded01fc8..dae915ae91cfb766e6c501a921d1699ece0cb132 100644 (file)
@@ -574,32 +574,35 @@ function e2lib.log(level, msg)
     if level < 1 or level > 4 then
         e2lib.log(1, "Internal error: invalid log level")
     end
+
     if not msg then
         e2lib.log(1, "Internal error: calling log() without log message")
     end
+
     local log_prefix = "[" .. level .. "] "
-    -- remove end of line if it exists
-    if msg:match("\n$") then
-        msg = msg:sub(1, msg:len() - 1)
+
+    if string.sub(msg, -1) ~= "\n"  then
+        msg = msg.."\n"
     end
 
     if e2lib.globals.debuglogfile then
-
         -- write out buffered messages first
         for _,m in ipairs(e2lib.globals.debuglogfilebuffer) do
             eio.fwrite(e2lib.globals.debuglogfile, m)
         end
         e2lib.globals.debuglogfilebuffer = {}
 
-        eio.fwrite(e2lib.globals.debuglogfile, log_prefix .. msg .. "\n")
+        eio.fwrite(e2lib.globals.debuglogfile, log_prefix .. msg)
     else
-        table.insert(e2lib.globals.debuglogfilebuffer, log_prefix .. msg .. "\n")
+        table.insert(e2lib.globals.debuglogfilebuffer, log_prefix .. msg)
     end
+
     if e2lib.getlog(level) then
         if e2lib.globals.log_debug then
-            io.stderr:write(log_prefix)
+            console.eout(log_prefix .. msg)
+        else
+            console.eout(msg)
         end
-        io.stderr:write(msg .. "\n")
     end
 end
 
index 6052fd6468d1eb600e745b2a24350de91d39cd61..c9788c0281ed63a59e409a5df1be0e5171f0e539 100644 (file)
 -- Parsing of command-line options
 
 local e2option = {}
+local buildconfig = require("buildconfig")
+local console = require("console")
 local e2lib = require("e2lib")
 local plugin = require("plugin")
 local err = require("err")
 local strict = require("strict")
 local tools = require("tools")
-local buildconfig = require("buildconfig")
 
 local options = {}
 local aliases = {}
@@ -200,7 +201,7 @@ local function defaultoptions()
 
     e2option.flag("version", "show version number",
     function()
-        print(buildconfig.VERSIONSTRING)
+        console.infonl(buildconfig.VERSIONSTRING)
         plugin.print_descriptions()
         e2lib.finish(0)
     end,
@@ -208,9 +209,9 @@ local function defaultoptions()
 
     e2option.flag("licence", "show licence information",
     function()
-        print(e2lib.globals._version)
-        print()
-        print(e2lib.globals._licence)
+        console.infonl(e2lib.globals._version)
+        console.infonl()
+        console.infonl(e2lib.globals._licence)
         e2lib.finish(0)
     end,
     category)
@@ -404,15 +405,15 @@ end
 -- @return This function does not return.
 function e2option.usage(rc)
     local out
+    local m = string.format("usage: %s --help for more information\n",
+        toolname())
+
     if rc == 0 then
-        out = io.stdout
+        console.info(m)
     else
-        out = io.stderr
+        console.eout(m)
     end
 
-    local m = string.format("usage: %s --help for more information\n",
-        toolname())
-    out:write(m)
     e2lib.finish(rc)
 end
 
index 40acc26185b4798171a8541150e4b3d89a567484..30e5f01c84107b0efe1429efb3803b336c846ce8 100644 (file)
@@ -30,6 +30,7 @@
 ]]
 
 local plugin = {}
+local console = require("console")
 local err = require("err")
 local e2lib = require("e2lib")
 local strict = require("strict")
@@ -260,11 +261,10 @@ function plugin.exit_plugins()
 end
 
 --- print a description for each plugin. This is for use with the --version
--- option. This version always succeeds.
--- @return nil
+-- option. This function always succeeds.
 function plugin.print_descriptions()
     for i,pd in ipairs(plugins) do
-        print(pd.description)
+        console.infonl(pd.description)
     end
 end
 
index 4c0fd5c99a61764ec44f5ad14417b4f4024bd4cc..b5b30694c866035bdf4518e565ec7603ab54db82 100644 (file)
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ]]
 
+local buildconfig = require("buildconfig")
+local console = require("console")
 local e2lib = require("e2lib")
 local e2option = require("e2option")
 local err = require("err")
-local buildconfig = require("buildconfig")
 
 local function e2(arg)
     local rc, re = e2lib.init()
@@ -41,8 +42,8 @@ local function e2(arg)
 
     e2option.flag("prefix", "print installation prefix",
     function()
-        print(buildconfig.PREFIX)
-        os.exit(0)
+        console.infonl(buildconfig.PREFIX)
+        e2lib.finish(0)
     end)
 
     local root = e2lib.locate_project_root()
index 2a45e11e3ef5248485b58e57289025fdda5e8745..168793d840383a6c1c59417c16d3d6cae7539c98 100644 (file)
@@ -28,6 +28,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ]]
 
+local console = require("console")
 local e2lib = require("e2lib")
 local e2tool = require("e2tool")
 local e2build = require("e2build")
@@ -223,7 +224,7 @@ local function e2_build(arg)
             if not bid then
                 return false, re
             end
-            print(string.format("%-20s [%s]", r, bid))
+            console.infof("%-20s [%s]\n", r, bid)
         end
 
         return true
index e604861939951100924a33adc0420000faec232a..5c5e7603968ed9cb9342ddd70a0aa79ff4975f15 100644 (file)
@@ -28,6 +28,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ]]
 
+local console = require("console")
 local e2lib = require("e2lib")
 local e2tool = require("e2tool")
 local e2option = require("e2option")
@@ -75,8 +76,8 @@ local function e2_dlist(arg)
         return false, re
     end
 
-    for i = 1, #dep do
-        print(dep[i])
+    for _,d in ipairs(dep) do
+        console.infonl(d)
     end
 
     return true
index c2b9f833f9d283059b008a49f621cfba8adb098b..8b6dd71bfb169a652374742e4c836c998c87572d 100644 (file)
@@ -28,6 +28,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ]]
 
+local console = require("console")
 local e2lib = require("e2lib")
 local e2tool = require("e2tool")
 local e2option = require("e2option")
@@ -55,7 +56,9 @@ local function e2_dsort(arg)
 
     local d = e2tool.dsort(info)
     if d then
-        for i = 1, #d do print(d[i]) end
+        for _,dep in ipairs(d) do
+            console.infonl(dep)
+        end
     end
 
     return true
index dc7dfbfdfd15c512d0966dbaa0fef57e76bb9be9..0759ab54d57e819d744098787facb43ef9906642 100644 (file)
@@ -28,6 +28,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ]]
 
+local console = require("console")
 local e2lib = require("e2lib")
 local e2tool = require("e2tool")
 local err = require("err")
@@ -71,11 +72,11 @@ local function list_manpage_section(documentation, header, section)
     end
     table.sort(sorted)
 
-    print(header)
+    console.infonl(header)
     for _,displayname in ipairs(sorted) do
-            print(string.format("  %s", displayname))
+            console.infof("  %s\n", displayname)
     end
-    print()
+    console.infonl()
     return true
 end
 
index 9363f816caec99f917e98f5f7c9cec69d0cfffbe..75874964ea3c25a79d90e5debe58aa11d87d9508 100644 (file)
@@ -30,6 +30,7 @@
 
 -- ls-project - show project information -*- Lua -*-
 
+local console = require("console")
 local e2lib = require("e2lib")
 local e2tool = require("e2tool")
 local err = require("err")
@@ -114,16 +115,16 @@ local function e2_ls_project(arg)
     table.sort(sources)
 
     local function pempty(s1, s2, s3)
-        print(string.format("   %s  %s  %s", s1, s2, s3))
+        console.infof("   %s  %s  %s\n", s1, s2, s3)
     end
     local function p0(s1, s2, v)
-        print(string.format("%s", v))
+        console.infonl(v)
     end
     local function p1(s1, s2, v)
-        print(string.format("   o--%s", v))
+        console.infof("   o--%s\n", v)
     end
     local function p2(s1, s2, v)
-        print(string.format("   %s  o--%s", s1, v))
+        console.infof("   %s  o--%s\n", s1, v)
     end
     local function p3(s1, s2, k, v)
         if v then
@@ -133,9 +134,9 @@ local function e2_ls_project(arg)
 
                 v = v:sub(2)
             end
-            print(string.format("   %s  %s  o--%-10s = %s", s1, s2, k, v))
+            console.infof("   %s  %s  o--%-10s = %s\n", s1, s2, k, v)
         else
-            print(string.format("   %s  %s  o--%s", s1, s2, k))
+            console.infof("   %s  %s  o--%s\n", s1, s2, k)
         end
     end
 
@@ -150,7 +151,7 @@ local function e2_ls_project(arg)
             i = i + 1
             if l then
                 if (l:len() + v:len() + 1) > col then
-                    print(l)
+                    console.infonl(l)
                     l = nil
                 end
             end
@@ -162,44 +163,44 @@ local function e2_ls_project(arg)
             header = header2
         end
         if l then
-            print(l)
+            console.infonl(l)
         end
     end
 
     if opts.dot or opts["dot-sources"] then
         local arrow = "->"
-        print("digraph \"" .. info.project.name .. "\" {")
+        console.infof("digraph \"%s\" {\n", info.project.name)
         for _, r in pairs(results) do
             local res = info.results[r]
             local deps = e2tool.dlist(info, r)
             if #deps > 0 then
                 for _, dep in pairs(deps) do
                     if opts.swap then
-                        print(string.format("  \"%s\" %s \"%s\"", dep, arrow, r))
+                        console.infof("  \"%s\" %s \"%s\"\n", dep, arrow, r)
                     else
-                        print(string.format("  \"%s\" %s \"%s\"", r, arrow, dep))
+                        console.infof("  \"%s\" %s \"%s\"\n", r, arrow, dep)
                     end
                 end
             else
-                print(string.format("  \"%s\"", r))
+                console.infof("  \"%s\"\n", r)
             end
             if opts["dot-sources"] then
                 for _, src in ipairs(res.sources) do
                     if opts.swap then
-                        print(string.format("  \"%s-src\" %s \"%s\"", src, arrow, r))
+                        console.infof("  \"%s-src\" %s \"%s\"\n", src, arrow, r)
                     else
-                        print(string.format("  \"%s\" %s \"%s-src\"", r, arrow, src))
+                        console.infof("  \"%s\" %s \"%s-src\"\n", r, arrow, src)
                     end
                 end
             end
         end
         if opts["dot-sources"] then
             for _, s in pairs(sources) do
-                print(string.format("  \"%s-src\" [label=\"%s\", shape=box]", s, s))
+                console.infof("  \"%s-src\" [label=\"%s\", shape=box]\n", s, s)
             end
         end
-        print("}")
-        e2lib.finish()
+        console.infonl("}")
+        e2lib.finish(0)
     end
 
     --------------- project name
@@ -230,7 +231,7 @@ local function e2_ls_project(arg)
             p3(s1, s2, k, tostring(ce.flags[k]))
         end
     end
-    print("   |")
+    console.infonl("   |")
 
     --------------------- sources
     local s1 = "|"
index 7d7043982d2f84676183cca78f776a86530ccee2..8d5b660fc46b3e98173d46992aabbe4d8660bd06 100644 (file)
@@ -30,6 +30,7 @@
 
 -- playground - enter existing chroot(1) environment -*- Lua -*-
 
+local console = require("console")
 local e2lib = require("e2lib")
 local e2tool = require("e2tool")
 local e2build = require("e2build")
@@ -93,7 +94,7 @@ local function e2_playground(arg)
         return false, err.new("playground does not exist")
     end
     if opts.showpath then
-        print(info.results[r].build_config.c)
+        console.infonl(info.results[r].build_config.c)
         e2lib.finish(0)
     end
     -- interactive mode, use bash profile